# tinloof/sanity-kit architecture

> Architecture diagram of the GitHub repository tinloof/sanity-kit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tinloof/sanity-kit
- Repository: https://github.com/tinloof/sanity-kit

## Overview

##### Project type and purpose
- This is a monorepo (managed by pnpm & Turbo) containing a set of npm packages and two demo applications.
- Its purpose is to provide reusable components, plugins and tooling (“Sanity Kit”) for building content‐driven websites with Sanity.io:
- `packages/sanity-studio` – custom Sanity Studio plugins and components
- `packages/sanity-web` – React components/utilities for rendering Sanity content in a Next.js front end
- plus shared ESLint & TypeScript config packages
- The `apps/next` and `apps/studio` folders are live preview/demo apps to validate changes in `sanity-web` and `sanity-studio` respectively.

##### File structure
- Top level
- monorepo config: `pnpm-workspace.yaml`, `turbo.json`, GitHub workflows, root `package.json`
- `packages/`: reusable libraries
- `apps/`: two Next.js-based preview applications
- `apps/next`
- Next.js front end
- Uses `sanity-web` package to fetch and render data from a Sanity headless CMS via Sanity API
- Routes for draft–publish toggling via API routes
- `apps/studio`
- Sanity Studio authored in TypeScript
- Uses `sanity-studio` package to extend Studio with custom fields, plugins, navigators
- Shared tooling packages under `packages/`: ESLint config, TypeScript config
- CI/CD: GitHub Actions workflows for changeset-driven releases and dependency updates

##### README for additional insights
- Describes developer workflow: `npm run dev` at root spins up all packages and both apps in dev mode via Turbo
- Each app requires its own `.env` to connect to a real Sanity project
- Changes in packages hot-reload in the corresponding app

a. Main components
- Monorepo root (Turbo/NX orchestrator)
- Package libraries (sanity-studio, sanity-web, eslint-config, typescript-config)
- Preview applications (Next.js front end + API routes; Sanity Studio front end)
- External service: Sanity.io (hosted headless CMS + database)
- Developer workstation (IDE, local environment)
b. Relationships & data flows
1. Developer edits code → Turbo watches & rebuilds affected packages
2. Changes are published to local dev servers in `apps/next` and `apps/studio`
3. `apps/next` → fetches content from Sanity API using `sanity-web` client
4. `apps/studio` → connects to Sanity project, extends the editing UI with `sanity-studio` plugins
5. Both apps read common config (eslint, tsconfig) from root/`packages`
c. Architectural patterns/design principles
- Monorepo with shared build/config tooling (DRY principle)
- Package-based modularization for reuse across multiple apps
- Preview apps as integration tests
- API façade in Next.js (`/api/draft`, `/api/disable-draft`)
d. Key technologies/frameworks/libraries
- pnpm & Turbo – monorepo management and task orchestration
- Next.js – React server/client components + API routes
- Sanity.io – headless CMS (client & CLI SDK)
- TypeScript – type safety across packages and apps
- ESLint/Prettier – code style enforcement
- Tailwind CSS – styling in Next.js apps

##### Essential architectural elements
- Don’t just list every file—group by package/app and role
- How changes propagate from code → local packages → preview apps → external CMS

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer
    Dev["Developer Workstation"]:::dev

    %% Monorepo Orchestrator
    subgraph "Monorepo Orchestrator"
        PWS["pnpm-workspace.yaml"]:::orches
        TURBO["turbo.json"]:::orches
        ROOTPKG["package.json"]:::orches
    end

    %% Packages
    subgraph "Packages"
        subgraph "sanity-studio"
            SS_PKG["package.json"]:::lib
            SS_INDEX["src/index.ts"]:::lib
            SS_COMPS["src/components"]:::lib
            SS_PLUGINS["src/plugins"]:::lib
            SS_SCHEMAS["src/schemas"]:::lib
            SS_HOOKS["src/hooks"]:::lib
            SS_UTILS["src/utils"]:::lib
        end
        subgraph "sanity-web"
            SW_PKG["package.json"]:::lib
            SW_INDEX["src/index.ts"]:::lib
            SW_COMPS["src/components"]:::lib
            SW_UTILS["src/utils"]:::lib
        end
        subgraph "eslint-config"
            ESLINT_PKG["package.json"]:::config
            ESLIB["library.js"]:::config
            ESL_NEXT["next.js"]:::config
            ESL_REACT["react-internal.js"]:::config
        end
        subgraph "typescript-config"
            TS_PKG["package.json"]:::config
            TS_BASE["base.json"]:::config
        end
    end

    %% Applications
    subgraph "Apps"
        subgraph "Next.js Front End"
            NEXT_PKG["package.json"]:::app
            NEXT_CONF["next.config.mjs"]:::app
            TAILWIND["tailwind.config.js"]:::app
            PAGE["app/(website)/[...path]/page.tsx"]:::app
            API_DRAFT["app/api/draft/route.ts"]:::app
            API_DISABLE["app/api/disable-draft/route.ts"]:::app
            CLIENT["data/sanity/client.ts"]:::app
            QUERIES["data/sanity/queries.ts"]:::app
            PAGECOMP["components/Page.tsx"]:::app
        end
        subgraph "Sanity Studio Preview"
            STUDIO_PKG["package.json"]:::app
            STUDIO_CFG["sanity.config.ts"]:::app
            STUDIO_CLI["sanity.cli.ts"]:::app
            SCHEMAS["schemas/*.ts"]:::app
        end
    end

    %% External Service
    Sanity["Sanity.io CMS"]:::external

    %% Relationships
    Dev -->|"edits code"| PWS
    Dev --> TURBO
    Dev --> ROOTPKG

    PWS --> SS_PKG
    PWS --> SW_PKG
    PWS --> ESLINT_PKG
    PWS --> TS_PKG
    PWS --> NEXT_PKG
    PWS --> STUDIO_PKG

    TURBO --> SS_PKG
    TURBO --> SW_PKG
    TURBO --> NEXT_PKG
    TURBO --> STUDIO_PKG

    ROOTPKG --> ESLINT_PKG
    ROOTPKG --> TS_PKG

    %% Apps use packages
    NEXT_PKG --> SW_PKG
    STUDIO_PKG --> SS_PKG

    %% Data flows
    SW_INDEX -->|fetch content| Sanity
    SS_INDEX -->|edit content| Sanity

    %% Config usage
    ESLINT_PKG --> NEXT_PKG
    ESLINT_PKG --> STUDIO_PKG
    TS_PKG --> NEXT_PKG
    TS_PKG --> STUDIO_PKG

    %% Click Events
    click PWS "https://github.com/tinloof/sanity-kit/blob/main//pnpm-workspace.yaml"
    click TURBO "https://github.com/tinloof/sanity-kit/blob/main//turbo.json"
    click ROOTPKG "https://github.com/tinloof/sanity-kit/blob/main//package.json"
    click SS_PKG "https://github.com/tinloof/sanity-kit/blob/main//packages/sanity-studio/package.json"
    click SS_INDEX "https://github.com/tinloof/sanity-kit/blob/main//packages/sanity-studio/src/index.ts"
    click SS_COMPS "https://github.com/tinloof/sanity-kit/tree/main//packages/sanity-studio/src/components"
    click SS_PLUGINS "https://github.com/tinloof/sanity-kit/tree/main//packages/sanity-studio/src/plugins"
    click SS_SCHEMAS "https://github.com/tinloof/sanity-kit/tree/main//packages/sanity-studio/src/schemas"
    click SS_HOOKS "https://github.com/tinloof/sanity-kit/tree/main//packages/sanity-studio/src/hooks"
    click SS_UTILS "https://github.com/tinloof/sanity-kit/tree/main//packages/sanity-studio/src/utils"
    click SW_PKG "https://github.com/tinloof/sanity-kit/blob/main//packages/sanity-web/package.json"
    click SW_INDEX "https://github.com/tinloof/sanity-kit/blob/main//packages/sanity-web/src/index.ts"
    click SW_COMPS "https://github.com/tinloof/sanity-kit/tree/main//packages/sanity-web/src/components"
    click SW_UTILS "https://github.com/tinloof/sanity-kit/tree/main//packages/sanity-web/src/utils"
    click ESLINT_PKG "https://github.com/tinloof/sanity-kit/blob/main//packages/eslint-config/package.json"
    click ESLIB "https://github.com/tinloof/sanity-kit/blob/main//packages/eslint-config/library.js"
    click ESL_NEXT "https://github.com/tinloof/sanity-kit/blob/main//packages/eslint-config/next.js"
    click ESL_REACT "https://github.com/tinloof/sanity-kit/blob/main//packages/eslint-config/react-internal.js"
    click TS_PKG "https://github.com/tinloof/sanity-kit/blob/main//packages/typescript-config/package.json"
    click TS_BASE "https://github.com/tinloof/sanity-kit/blob/main//packages/typescript-config/base.json"
    click NEXT_PKG "https://github.com/tinloof/sanity-kit/blob/main//apps/next/package.json"
    click NEXT_CONF "https://github.com/tinloof/sanity-kit/blob/main//apps/next/next.config.mjs"
    click TAILWIND "https://github.com/tinloof/sanity-kit/blob/main//apps/next/tailwind.config.js"
    click PAGE "https://github.com/tinloof/sanity-kit/blob/main//apps/next/app/(website)/[...path]/page.tsx"
    click API_DRAFT "https://github.com/tinloof/sanity-kit/blob/main//apps/next/app/api/draft/route.ts"
    click API_DISABLE "https://github.com/tinloof/sanity-kit/blob/main//apps/next/app/api/disable-draft/route.ts"
    click CLIENT "https://github.com/tinloof/sanity-kit/blob/main//apps/next/data/sanity/client.ts"
    click QUERIES "https://github.com/tinloof/sanity-kit/blob/main//apps/next/data/sanity/queries.ts"
    click PAGECOMP "https://github.com/tinloof/sanity-kit/blob/main//apps/next/components/Page.tsx"
    click STUDIO_PKG "https://github.com/tinloof/sanity-kit/blob/main//apps/studio/package.json"
    click STUDIO_CFG "https://github.com/tinloof/sanity-kit/blob/main//apps/studio/sanity.config.ts"
    click STUDIO_CLI "https://github.com/tinloof/sanity-kit/blob/main//apps/studio/sanity.cli.ts"
    click SCHEMAS "https://github.com/tinloof/sanity-kit/blob/main//apps/studio/schemas/*.ts"

    %% Styles
    classDef orches fill:#FFD700,stroke:#333,stroke-width:1px
    classDef lib fill:#ADFF2F,stroke:#333,stroke-width:1px
    classDef config fill:#87CEFA,stroke:#333,stroke-width:1px
    classDef app fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef external fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef dev fill:#D3D3D3,stroke:#333,stroke-width:1px
```
