# udecode/plate architecture

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

- Interactive diagram: https://gitdiagram.com/udecode/plate
- Repository: https://github.com/udecode/plate

## Overview

##### Project Type & Purpose
- This is an open-source monorepo (“Plate”) hosting a rich-text editor framework for React (`slate-react`).
- It’s organized as a Yarn / Turborepo workspace containing:
- Core library (`packages/core`)
- Dozens of plugin packages under `packages/…` (e.g., alignment, autoformat, media, yjs, etc.)
- Primitives and headless UI components
- A Next.js documentation site at `apps/www`
- Several starter templates under `templates/…`
- Tooling and CI config under `tooling` and `.github`

##### Key Top-Level Components
- **Monorepo Orchestrator**
- Yarn Workspaces & `turbo.json` — manages the build/test pipeline, hoists dependencies.
- **Core Package**
- `packages/core` — the heart of the Plate plugin system, exposes the plugin API & slate-react integrations.
- **Plugin Packages**
- `packages/<feature>` (e.g., autoformat, media, table, yjs) each implements a `Base…Plugin` + React wrapper.
- **Primitives & Components**
- UI primitives built on Radix UI under `packages/*` and `apps/www/src/components/ui`.
- **Documentation Site**
- Next.js app at `apps/www` — renders markdown (`docs/…`), Contentlayer, static and API routes (`src/app/api/registry`).
- **Templates**
- `templates/plate-playground-template` & `templates/plate-template` — project starters that wire core + plugins + Next.js.
- **Tooling & CI**
- `tooling` folder: ESLint configs, Playwright tests, Vitest, Turborepo watch scripts.
- `.github/workflows`: CI, release, lint, test, cache cleanup, registry sync.

##### Relationships & Data Flows
- The **docs site** depends on the **registry** of plugins and primitives generated by scripts (`apps/www/scripts/*`) and the `@udecode/plate-*` packages.
- **Templates** consume the same registry and `packages/*` to spin up new projects.
- **CI pipelines** (GitHub Actions) trigger Turborepo tasks: build, lint, test across all packages and the docs app.
- **Tooling scripts** in `tooling/scripts` scaffold new plugin packages, update the registry, or bump versions.
- At runtime, a consumer app:
- Installs core + selected plugin packages
- Configures a `PlateProvider` (from `@udecode/plate-core`) and registers plugins
- Renders the editor via `Plate` and optional UI components.

##### Architectural Patterns & Principles
- **Monorepo / Turborepo**: central orchestrator for builds & tests; workspace dependency graph.
- **Plugin Architecture**: Core defines plugin injection & pipelines; each feature is a self-contained plugin package.
- **Headless vs. UI Layer**: Plugins expose headless behavior; separate React wrapper packages for UI integration.
- **Content Registry**: Scripts generate a JSON registry consumed by the docs site and Playground.
- **Template-Driven Development**: Prewired project templates let users scaffold with minimal setup.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Monorepo Root
    subgraph "Monorepo Root"
        MonorepoOrchestrator["Monorepo Orchestrator"]:::library
    end

    %% Package Layer
    subgraph "Packages"
        Core["Core Library"]:::library
        subgraph "Plugin Packages"
            Autoformat["Autoformat Plugin"]:::library
            Media["Media Plugin"]:::library
            Yjs["Collaboration (Yjs) Plugin"]:::library
            Table["Table Plugin"]:::library
        end
        subgraph "UI Primitives"
            ReactUtils["React Utils (primitives/hooks)"]:::library
        end
    end

    %% Apps and Templates
    subgraph "Applications & Templates"
        DocsSite["Documentation Site (Next.js + Contentlayer)"]:::app
        WWWUI["Docs Site UI Primitives"]:::library
        subgraph "Templates"
            Playground["Playground Template"]:::app
            Starter["Default Starter Template"]:::app
        end
    end

    %% Tooling and CI
    subgraph "Tooling & CI"
        ToolingScripts["Tooling Scripts"]:::tooling
        CIWorkflows["CI Workflows & Release Automation"]:::tooling
    end

    %% External Services
    NPMRegistry["npm Registry"]:::external
    GitHub["GitHub"]:::external
    Discord["Discord"]:::external

    %% Dependency and Data Flows
    MonorepoOrchestrator -->|manages| Core
    MonorepoOrchestrator -->|manages| Autoformat
    MonorepoOrchestrator -->|manages| Media
    MonorepoOrchestrator -->|manages| Yjs
    MonorepoOrchestrator -->|manages| Table
    MonorepoOrchestrator -->|manages| ReactUtils
    MonorepoOrchestrator -->|manages| DocsSite
    MonorepoOrchestrator -->|manages| Playground
    MonorepoOrchestrator -->|manages| Starter
    MonorepoOrchestrator -->|manages| ToolingScripts
    MonorepoOrchestrator -->|manages| CIWorkflows

    ToolingScripts -->|generates registry| Registry["Plugin Registry JSON"]:::tooling
    Registry -->|consumed by| DocsSite
    Registry -->|consumed by| Playground
    Registry -->|consumed by| Starter

    CIWorkflows -->|triggers build/test| MonorepoOrchestrator
    CIWorkflows -->|publishes to| NPMRegistry
    CIWorkflows -->|syncs with| GitHub

    DocsSite -->|uses UI| WWWUI
    DocsSite -->|sources docs from| DocsMarkdown["docs/… (Markdown)"]:::library
    DocsSite -->|exposes api| RegistryAPI["/src/app/api/registry"]:::app

    %% Consumer App flow
    subgraph "Downstream Consumer App"
        ConsumerApp["Consumer App"]:::external
    end
    ConsumerApp -->|installs| Core
    ConsumerApp -->|installs| Autoformat
    ConsumerApp -->|configures| Core
    ConsumerApp -->|renders| ReactUtils

    %% External Connections
    MonorepoOrchestrator -->|hosts code on| GitHub
    GitHub -->|integrates with| CIWorkflows
    Community["Developer Community"]:::external
    Community -->|discuss on| Discord

    %% Click Events
    click MonorepoOrchestrator "https://github.com/udecode/plate/blob/main/turbo.json"
    click MonorepoOrchestrator "https://github.com/udecode/plate/blob/main/package.json"
    click MonorepoOrchestrator "https://github.com/udecode/plate/blob/main/.yarnrc.yml"
    click Core "https://github.com/udecode/plate/tree/main/packages/core"
    click Autoformat "https://github.com/udecode/plate/tree/main/packages/autoformat"
    click Media "https://github.com/udecode/plate/tree/main/packages/media"
    click Yjs "https://github.com/udecode/plate/tree/main/packages/yjs"
    click Table "https://github.com/udecode/plate/tree/main/packages/table"
    click ReactUtils "https://github.com/udecode/plate/tree/main/packages/react-utils"
    click WWWUI "https://github.com/udecode/plate/tree/main/apps/www/src/components/ui"
    click DocsSite "https://github.com/udecode/plate/tree/main/apps/www"
    click Playground "https://github.com/udecode/plate/tree/main/templates/plate-playground-template"
    click Starter "https://github.com/udecode/plate/tree/main/templates/plate-template"
    click ToolingScripts "https://github.com/udecode/plate/tree/main/tooling/scripts"
    click CIWorkflows "https://github.com/udecode/plate/tree/main/.github/workflows"

    %% Styles
    classDef library fill:#bfdffd,stroke:#2266aa,stroke-width:1px
    classDef app fill:#b2f7b2,stroke:#228822,stroke-width:1px
    classDef tooling fill:#ffd8b2,stroke:#cc6600,stroke-width:1px
    classDef external fill:#e0e0e0,stroke:#888888,stroke-width:1px style ConsumerApp stroke-dasharray: 5 5,color:#444
```
