Let's give you a quick guide on how and why we use Cursor .mdc rules. If you don't know what .mdc stands for, well...neither do we. But if I had to hazard a guess, I'd say it's probably Misguided Decisions & Chaos.
Moving quickly on from the Dad joke, I'm going to talk about why the rules are important, the specific things that this rule does, and why we would advise heavily tweaking it to your own preferences.
Schema layout
We have a very rigid way of building schema because, in most situations, you don't want to be debugging a large website project with one giant index file with 300+ schema types imported. That's why we have pre-determined patterns for adding indexes and spread operators on a folder-by-folder level.
This way, it becomes far easier to debug at scale and quickly include new schemas from within the same folder. The only trip hazard with this is that if you do not update the import in the index, you will not see your page builder block, so please be aware of this.
Typesafety
You'll notice a recurring theme in the way we build our Sanity websites... We hate having to manually type interfaces. We want to make as much typescript automated as physically possible, and for that reason, you'll notice it's heavily embedded within our .mdc file as well. Ultimately, you're making it easier for yourself in the long run, and the more you can automate, the easier you can scale.
Predefined schema
You may also notice there are a couple of predefined schema titles, names and types. There's a good reason for this. Usually, we're not the biggest fan of the DRY (Don't Repeat Yourself) way of coding. Purely because we find it's very easy to create spaghetti code when one requirement's goalposts inevitably shift and mutate content.
However, you will notice we regularly recycle the same naming conventions on different blocks. This helps to reuse Tailwind CSS and ultimately increases your development momentum.
Image recognition
Finally, there's a real advantage to screenshot wireframes within Figma and get a rough draft for your schema. That's why we included some standardisation that correlates the point above of matching certain UI layouts with certain schema types to ensure you create consistent, user-friendly fields with descriptions and icons.
The rules themselves
Always use defineField on every field and defineType throughout the whole type. Only import defineArrayMember if needed:
Adding icons
When adding icons to a schema, make sure you use the default sanity/icons first, and then if no icon is relevant, refer to any other iconset the user has installed - e.g lucide-react.
Structuring files and folders
This is a rough idea of how to structure folders and files, ensuring you always have an index within the folder to create an array of documents/blocks. Do not use these as exact names, it's used purely for layout purposes.
│ ├── studio/ │ │ ├── README.md │ │ ├── eslint.config.mjs │ │ ├── location.ts │ │ ├── package.json │ │ ├── prettier.config.mjs │ │ ├── sanity-typegen.json │ │ ├── sanity.cli.ts │ │ ├── sanity.config.ts │ │ ├── schema.json │ │ ├── structure.ts │ │ ├── tsconfig.json │ │ ├── .env.example │ │ ├── .gitignore │ │ ├── components/ │ │ │ ├── logo.tsx │ │ │ └── slug-field-component.tsx │ │ ├── plugins/ │ │ │ └── presentation-url.ts │ │ ├── schemaTypes/ │ │ │ ├── common.ts │ │ │ ├── index.ts │ │ │ ├── blocks/ │ │ │ │ ├── cta.ts │ │ │ │ ├── faq-accordion.ts │ │ │ │ ├── feature-cards-icon.ts │ │ │ │ ├── hero.ts │ │ │ │ ├── image-link-cards.ts │ │ │ │ ├── index.ts │ │ │ │ └── subscribe-newsletter.ts │ │ │ ├── definitions/ │ │ │ │ ├── button.ts │ │ │ │ ├── custom-url.ts │ │ │ │ ├── index.ts │ │ │ │ ├── pagebuilder.ts │ │ │ │ └── rich-text.ts │ │ │ └── documents/ │ │ │ ├── author.ts │ │ │ ├── blog.ts │ │ │ ├── faq.ts │ │ │ └── page.ts │ │ └── utils/ │ │ ├── const-mock-data.ts │ │ ├── constant.ts │ │ ├── helper.ts │ │ ├── mock-data.ts │ │ ├── og-fields.ts │ │ ├── parse-body.ts │ │ ├── seo-fields.ts │ │ ├── slug.ts │ │ └── types.ts
Layout of page builder index example
This is an example of how the blocks index file would be structured, you would create multiple of these on multiple nested routes to make it easier to create an array of files at each level, rather than bundling a large number of imports in a singular index.ts on the root
Common Field Templates
When writing any Sanity schema, always include a description, name, title, and type. The description should explain functionality in simple terms for non-technical users. Place description above type.
Use these templates when implementing common fields:
Eyebrow
Title
Heading Level Toggle
Rich Text
Buttons
Image
Type Generation
After adding new Sanity schema, run the type command to generate TypeScript definitions:
GROQ Rules
Whenever there is an image within a GROQ query, do not expand it unless explicitly instructed to do so.
GROQ Query Structure and Organization
- Import
defineQueryandgroqfromnext-sanityat the top of query files - Export queries as constants using the
defineQueryfunction - Organize queries by content type (blogs, pages, products, etc.)
- Group related queries together
Naming Conventions
- Use camelCase for all query names
- Prefix query names with action verb (get, getAll, etc.) followed by content type
- Suffix all queries with "Query" (e.g.,
getAllBlogIndexTranslationsQuery) - Prefix reusable fragments with underscore (e.g.,
_richText,_buttons)
Fragment Reuse
- Define common projection fragments at the top of the file
- Create reusable fragments for repeated patterns (e.g.,
_richText,_buttons,_icon) - Use string interpolation to include fragments in queries
- Ensure fragments are composable and focused on specific use cases
Query Parameters
- Use
$for parameters (e.g.,$slug,$locale,$id) - Handle localization with consistent patterns (e.g.,
${localeMatch}) - Use
select()for conditional logic within queries - Define default parameters using
coalesce()
Response Types
- Export TypeScript interfaces for query responses when needed
- Use descriptive types that match the query structure
- Follow the pattern:
export type GetAllMainPageTranslationsQueryResponse = string[];
Best Practices
- Use explicit filtering (
_type == "x") rather than implicit type checking - Prefer projection over returning entire documents
- Use
order()for explicit sorting rather than relying on document order - Check for defined fields (
defined(field)) before accessing them - Use conditional projections for optional fields
- Add pagination parameters (
[$start...$end]) for list queries
Code Style
- Use template literals for query strings
- Indent nested query structures for readability
- Keep related query parts together
- Maintain consistent whitespace and indentation
- Use comments to explain complex query logic
File Naming Conventions
- Use kebab-case for ALL file names
- ✅ CORRECT:
user-profile.tsx,auth-layout.tsx,api-utils.ts - ❌ INCORRECT:
userProfile.tsx,AuthLayout.tsx,apiUtils.ts
- ✅ CORRECT:
- MUST use
.tsxextension for React components - MUST use
.tsextension for utility files - MUST use lowercase for all file names
- MUST separate words with hyphens
- MUST NOT use spaces or underscores
Screenshot Rules
When asked to produce schema from screenshots, follow these guidelines:
- Help describe types and interfaces using the provided image
- Use the Sanity schema format shown above
- Always include descriptions based on the visual elements in the image
Visual Cues
- Tiny text above a title is likely an eyebrow
- Large text without formatting that looks like a header should be a title or subtitle
- Text with formatting (bold, italic, lists) likely needs richText
- Images should include alt text fields
- Background images should be handled appropriately
- Use reusable button arrays for button patterns
- If
richTextFieldorbuttonsFieldexists in the project, use them




