Folder Structure

Folder structure for Sanity CMS

Monorepo layout

The starter is a pnpm workspace: the Next.js site lives under frontend/ and Sanity Studio (schemas, CLI, deploy) lives under studio/. GROQ queries and the Sanity client live next to the app in frontend/sanity/; content schemas live only in studio/schemas/. TypeGen reads queries under frontend/sanity/queries/ and writes frontend/sanity.types.ts (see studio/sanity.cli.ts).

PathRole
frontend/Next.js app, UI, API routes, sanity/ client & GROQ, sanity.types.ts
studio/Studio config, schema definitions, schema.json, Presentation resolve

Next.js app (frontend/)

layout.tsx
index.tsx
page.ts
post.ts
section-header.ts
sanity.types.ts
package.json

frontend/ — what goes where

  • app/ — App Router routes, layouts, and API routes (draft mode, newsletter, etc.).
  • components/ — React UI, including blocks/ for page-builder sections that map to Sanity block types, and blocks/index.tsx for resolving CMS blocks to components.
  • sanity/ — Everything the Next.js app needs to talk to Sanity:
    • lib/ — Client, fetch helpers, live content, image URLs, metadata, tokens, env.
    • queries/GROQ queries (often one file per block or document type), organized similarly to studio/schemas/ so queries stay easy to find.
  • sanity.types.ts — Generated TypeScript types for queries and documents (run TypeGen from studio/ or pnpm typegen from the repo root).
  • package.json — Frontend dependencies and scripts.

There is no schemas/ folder under frontend/ — schemas are defined only in the Studio package below.

Sanity Studio (studio/)

structure.ts
defaultDocumentNode.ts
schema-types.ts
sanity.config.ts
sanity.cli.ts
schema.json
sample-data.tar.gz
package.json

studio/ — what goes where

  • schemas/Content model: document types under documents/, page-builder blocks under blocks/ (including shared/ objects such as links and variants), and optional previews/ for custom preview components in the Studio.
  • presentation/resolve.ts wires the Presentation tool (visual editing): URL mapping between routes and documents.
  • static/ — Assets such as preview thumbnails for schema list previews.
  • structure.ts — Studio sidebar structure (Structure Builder).
  • defaultDocumentNode.ts — Custom document views in the Studio (e.g. preview panes).
  • schema-types.ts — Imports and exports all schema types registered in sanity.config.ts.
  • sanity.config.ts — Studio plugins, project/dataset, schema registration.
  • sanity.cli.ts — CLI project settings and TypeGen paths (queries in frontend/sanity/queries, output frontend/sanity.types.ts).
  • schema.json — Produced by sanity schema extract in studio/ (used by TypeGen).
  • sample-data.tar.gz — Optional dataset import for local demos.
  • package.json — Studio dependencies and scripts.

Generated artifacts

  • studio/schema.json — Run npx sanity schema extract from studio/ (or use the pnpm typegen workflow at the repo root, which runs extract + typegen).
  • frontend/sanity.types.ts — Run npx sanity typegen generate from studio/ after schema.json is up to date. Paths are configured in studio/sanity.cli.ts.