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).
| Path | Role |
|---|---|
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, includingblocks/for page-builder sections that map to Sanity block types, andblocks/index.tsxfor 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 tostudio/schemas/so queries stay easy to find.
sanity.types.ts— Generated TypeScript types for queries and documents (run TypeGen fromstudio/orpnpm typegenfrom 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 underdocuments/, page-builder blocks underblocks/(includingshared/objects such as links and variants), and optionalpreviews/for custom preview components in the Studio.presentation/—resolve.tswires 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 insanity.config.ts.sanity.config.ts— Studio plugins, project/dataset, schema registration.sanity.cli.ts— CLI project settings and TypeGen paths (queries infrontend/sanity/queries, outputfrontend/sanity.types.ts).schema.json— Produced bysanity schema extractinstudio/(used by TypeGen).sample-data.tar.gz— Optional dataset import for local demos.package.json— Studio dependencies and scripts.
Generated artifacts
studio/schema.json— Runnpx sanity schema extractfromstudio/(or use thepnpm typegenworkflow at the repo root, which runs extract + typegen).frontend/sanity.types.ts— Runnpx sanity typegen generatefromstudio/afterschema.jsonis up to date. Paths are configured instudio/sanity.cli.ts.