The Best Directory Structure to Use for Next.js and Sanity Projects

9 replies
Last updated: Jun 14, 2021
For Next & Sanity projects, do folks usually go with the following structure (as Sanity's examples seem to use):
/studio/ folder within a Next.js project
or is there any disadvantage to having something like:
frontend -> nextjs files
studio -> sanity magic ?
AI Update

Both approaches are totally valid, and the choice really comes down to your team's preferences and deployment strategy. There's no major technical disadvantage to either structure.

The /studio folder approach (embedded in Next.js) is what you'll see in most of Sanity's official examples and templates. Here's why it's popular:

  • Simpler deployment: Everything deploys together as one Next.js app. Your Studio lives at yoursite.com/studio as a Next.js route
  • Shared dependencies: You can share TypeScript types, validation logic, and other code between your frontend and Studio
  • Monorepo benefits without the complexity: You get code sharing without needing to set up a full monorepo with workspaces
  • Easier local development: One npm install, one dev server to run

The separate repos/folders approach works great too, especially when:

  • Different teams manage each part: Your content team might have their own Studio deployment workflow
  • You want Studio on Sanity's hosting: You can deploy Studio to yourproject.sanity.studio using the CLI's deploy command, completely separate from your frontend
  • Multiple frontends: If you have iOS, Android, and web apps all consuming the same Sanity content, a separate Studio makes more sense
  • You prefer strict separation of concerns: Some teams just like keeping things completely decoupled

My take: If you're a solo dev or small team building a single website, the embedded /studio approach is usually simpler. If you have multiple frontends or want your Studio completely independent, go with separate projects.

Both structures work identically from a functionality perspective - Sanity Studio is just a React app either way, and your Next.js frontend talks to Sanity's Content Lake via the same APIs regardless of where Studio lives. The Presentation Tool for visual editing works with either setup too.

we do the second, works fine (each is a yarn workspace though)
Not overly familiar with yarn workspaces / seeing mentions of lerna - but I do think option 2 is the cleaner one. Tryna figure out whether its better to host Studio on vercel alongside frontend, or follow stick with sanitys default deploy location
I prefer everything to be together in one repo, but I typically deploy my studios to a
.sanity.studio
URL (via
sanity deploy
) to keep things easy, and avoid changing base URLs for the studio.
I do the second.
oh one thing about two distinct directories, some services like Netlify can treat each like it’s own site for deploy purposes and it makes this very easy to juggle
Appreciate the input guys! 😎
I currently have 2 separate projects in the same repo, one for studio and one for web. That was the old recommended approach back when I started using Sanity. But I’m curious about this new approach to host the studio as a separate app with Next rewrites.
I tried copying what was set up in the template repo but couldn’t get it working.
I’ll give it another try when my current projects calm down a bit. I kept getting errors when trying to access the studio. The classic
Invalid token <
I think that’s pretty much the setup I had as well. Though I use npm (other than in the studio since sanity pretty much forces yarn on you). That shouldn’t be it though, right?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?