How do you structure folder components in your Sanity projects?
This is a great question and honestly, there's no "perfect" solution â it's one of those things that evolves with your project! Your current approach is actually pretty solid and commonly used.
Here are a few patterns I've seen work well in Sanity + React/Next.js projects:
Your current approach (domain-based grouping):
components/
Blog/
index.js
BlogDetail.jsx
BlogOverview.jsx
BlogCard.jsxThis is totally valid! The index.js barrel export keeps imports clean. Some folks take this further by adding a Blog.module.css or co-locating tests here too.
Feature-based structure:
components/
blog/
BlogCard.jsx
BlogDetail.jsx
shared/
Button.jsx
Card.jsx
layout/
Header.jsx
Footer.jsxThis groups by feature/domain but flattens it a bit. Works well when components don't have many sub-components.
Atomic design approach:
components/ atoms/ # Button, Input, etc. molecules/ # BlogCard, SearchBar organisms/ # BlogOverview, Header templates/ # PageLayout
This can feel over-engineered for smaller projects, but scales nicely for design systems.
Sanity-specific consideration:
If you're using Portable Text for rich text, many folks create a dedicated structure:
components/
portableText/
serializers/
ImageSerializer.jsx
CodeSerializer.jsx
PortableTextRenderer.jsxMy personal take: Your current structure is fine! The main thing is consistency. I'd maybe add:
- A
shared/orcommon/folder for truly reusable components (buttons, inputs, etc.) - Co-locate component-specific styles/tests with the component
- Use barrel exports (
index.js) sparingly â they can hurt tree-shaking
The "never happy about the outcome" feeling is universal đ â just pick a convention, document it in a README, and stick with it. You can always refactor later when pain points become obvious!
Show original thread7 replies
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.