Development Guide
Package Structure
Section titled “Package Structure”The Sanity package (@repo/sanity) is at packages/sanity/:
packages/sanity/├── src/│ ├── index.ts # Main Sanity config (defineConfig)│ ├── schema/│ │ ├── index.ts # schemaTypes export│ │ ├── documents/ # Document types (settings, artist, event, …)│ │ └── objects/ # Object types (currently none)│ └── utils/│ └── groups.ts # Field groups (GROUP, GROUPS, SETTINGS_GROUPS)├── package.json├── tsconfig.json└── eslint.config.mjsConfiguration
Section titled “Configuration”Main config: packages/sanity/src/index.ts:
import { SITE_NAME } from '@repo/constants'import { defineConfig } from 'sanity'import { structureTool } from 'sanity/structure'import { visionTool } from '@sanity/vision'import { media } from 'sanity-plugin-media'import { references, referencesView } from 'sanity-plugin-references'import { singletonTools } from 'sanity-plugin-singleton-management'import { tags } from 'sanity-plugin-tags-v4'import { userSelect } from 'sanity-plugin-user-select-input'
import { schemaTypes } from './schema'
export default defineConfig({ name: 'rotunde', title: SITE_NAME, projectId: 'dm359cdv', dataset: 'production', plugins: [ structureTool({ defaultDocumentNode: (S) => S.document().views([S.view.form(), referencesView(S)]), }), visionTool(), media(), singletonTools(), tags(), userSelect(), references(), ], schema: { types: schemaTypes },})Using the Package
Section titled “Using the Package”The Sanity package is consumed by the Studio app at apps/studio/:
export {default} from '@repo/sanity'This allows the Studio app to use the shared configuration without duplicating code.
Development Workflow
Section titled “Development Workflow”Running the Studio
Section titled “Running the Studio”To start the Sanity Studio in development mode:
cd apps/studiopnpm devThis will start the Studio at http://localhost:3333 (or the next available port).
Building the Studio
Section titled “Building the Studio”To build the Studio for production:
cd apps/studiopnpm buildDeploying the Studio
Section titled “Deploying the Studio”To deploy the Studio to Sanity’s hosting:
cd apps/studiopnpm deployAdding Schema Types
Section titled “Adding Schema Types”Adding a Document Type
Section titled “Adding a Document Type”- Create
packages/sanity/src/schema/documents/myDocument.tsand define the type withdefineType/defineField. - Export from
packages/sanity/src/schema/documents/index.ts: add the import and include it in theschemaDocumentsarray. - The document will appear in the Studio.
Adding an Object Type
Section titled “Adding an Object Type”- Create a new file in
packages/sanity/src/schema/objects/and export fromschema/objects/index.tsinschemaObjects. - Use the type in document fields with
type: 'myObject'.
TypeScript Support
Section titled “TypeScript Support”The package uses TypeScript with strict type checking. Schema types are automatically typed, and you can generate TypeScript types from your Sanity schema using @sanity/typegen or similar tools.
Linting
Section titled “Linting”The package uses ESLint with Sanity’s recommended configuration:
pnpm lintDependencies
Section titled “Dependencies”Key dependencies:
sanity(^5.4.0) — Core Sanity@sanity/vision— GROQ Vision toolsanity-plugin-media— Media browsersanity-plugin-singleton-management— Singleton toolssanity-plugin-tags-v4— Tags fieldsanity-plugin-user-select-input— User pickersanity-plugin-references— References view + pluginreact,styled-components— Studio UI@repo/constants— SITE_NAME and shared constants
Best Practices
Section titled “Best Practices”- Keep schemas organized: Group related document types together
- Use TypeScript: Leverage type safety for schema definitions
- Document your schemas: Add descriptions and help text to fields
- Validate fields: Use validation rules to ensure data quality
- Use singletons appropriately: Only use singleton documents for truly unique content
- Test queries: Use the Vision tool to test GROQ queries before using them in code