Where to organize document schemas in Sanity Studio folder structure?

18 replies
Last updated: Feb 5, 2022
Need some advice here. I have this folder structure of the studio where basically almost everything is inside the “documents” folder. I want to cleanup the folder and make it more readable and logical.
Any tips ? Where would you move the docs in which folder because it can be pretty tough somethimes
😄
AI Update

Great question! Organizing your Sanity Studio folder structure can definitely get messy as projects grow. While Sanity doesn't enforce a strict folder structure (since everything is schema-as-code), here are some practical patterns that work well:

Common Folder Structure Patterns

Group by content type categories:

schemas/
├── documents/         # Top-level content types
│   ├── page.ts
│   ├── post.ts
│   └── author.ts
├── objects/          # Reusable nested objects
│   ├── seo.ts
│   ├── hero.ts
│   └── cta.ts
├── blocks/           # Portable Text blocks
│   ├── customImage.ts
│   └── callout.ts
└── singletons/       # One-off documents
    ├── settings.ts
    └── navigation.ts

Or group by feature/domain:

schemas/
├── blog/
│   ├── post.ts
│   ├── category.ts
│   └── author.ts
├── commerce/
│   ├── product.ts
│   └── collection.ts
├── pages/
│   ├── page.ts
│   └── landingPage.ts
└── shared/
    ├── seo.ts
    └── media.ts

Key Organization Tips

Separate by schema type hierarchy:

  • Documents (type: 'document'): Top-level content that appears in your desk structure
  • Objects (type: 'object'): Reusable components that nest inside documents
  • Singletons: Documents that should only have one instance (site settings, global config)

Consider what editors see: Your folder structure doesn't affect the Studio UI that editors see - that's controlled by your Structure tool configuration. So organize files for developer clarity, not editor experience.

Keep related schemas together: If a schema is only used by one document type, consider keeping them in the same folder or file.

Use an index file: Create an index.ts in your schemas folder that imports and exports all schema types. This gives you one place to manage what's registered in your Studio.

The beauty of Sanity's schema-as-code approach is there's no "wrong" answer - it's just JavaScript/TypeScript files. Pick a structure that makes sense for your team's mental model and refactor as needed. The schemas will work the same regardless of folder organization!

Most teams find the first pattern (documents/objects/blocks/singletons) works well as a starting point, then add domain-specific folders as the project grows. Good luck with the cleanup! 😄

Show original thread
18 replies
Hey Nino. One approach you could take is to group your files by "concern". That is, to have multiple directories for each "concern" (e.g. "settings" or "articles") and to have
documents
and
objects
etc. directories inside each of those.
You could even use plugins to help do this grouping (
https://www.sanity.io/docs/plugins ), however it's not strictly necessary because you can load your schemas from any location.
user E
Which plugin do I need don’t see it on this page. Love Sanity, only issue is something structure on how to make it readable and clean.
Is it the “sanity install third-party-reviews” plugin
Sorry, I didn't explain that very well. What I meant is that you can create a plugin for each of your "concerns" (different parts of your app) and keep them in the
plugins
directory only for you. Your plugins don't have to add anything to the Studio UI, you can simply use them as a clean way to organise your code 🙂.
This page might be helpful:
https://www.sanity.io/guides/creating-my-first-sanity-io-plugin .
Thank you. I see a lot of people having modules, objects and documents. From multiple demo starters from Sanity. maybe I should do the same. But keeping code organized is never easy.
My current play project is nowhere near as complex as yours, but one of the first things I do to stay “sane” is organize my schema files into a simple file system that makes sense to me for the project I am doing. In this case, a simple blog concept. The naming conventions for directories within
./schemas
don’t matter as much as the imports and datatypes. In my case, I wanted to set up two different portable text block content inputs, so I created two objects named
ptext
and
ptextLite
, and this works how I want.
user U
Thanks for sharing! I will first follow the design and based on the elements build documents and modules.
I often browse public repos from the Sanity team and community submissions for inspiration. Sounds like you’re on a good path!
user U
Yes, I’v setup some of the Sanity team and community demos to take inspiration from. Usually I see modules, documents, objects.
My current little blog workflow experiment that I’m using to test community questions as well is intended to be a platform for a handful of my own different sites. As I add different documents for different projects, I may switch my file layout to match the different sub projects. I don’t have a prescriptive suggestion for you, but part of the fun in all of this is coming up with my own methods!
My current little blog workflow experiment that I’m using to test community questions as well is intended to be a platform for a handful of my own different sites. As I add different documents for different projects, I may switch my file layout to match the different sub projects. I don’t have a prescriptive suggestion for you, but part of the fun in all of this is coming up with my own methods!
user U
Agree here if you think about it, there is no good or bad as long as it makes sense on the long term if you have to update it. Naming is the most important page, category, tag, list etc etc.
There are some amazingly deep discussions about best methods and a lot of strong opinions in nearly every dev community. I think I try to organize in a way that seems easiest for someone else to read and easiest for my own workflow. I sometimes start with multiple components combined in a single file, just to break them out - and sometimes with a bunch of different small component documents only to merge them later.
user U
good point, for instance image field/type not to copy paste the same code over and over again, but create one component named image.js and share it with other document files. That’s what you are talking about right?
user U
good point, for instance image field/type not to copy paste the same code over and over again, but create one component named image.js and share it with other document files. That’s what you are talking about right?
user U
May I ask which font are you using I really like it. Could you share the settings from vscode?
Cascadia code and one of the oceanic themes with italics. https://github.com/microsoft/cascadia-code
user U
Thank you very much!

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?