# rorkai/21st architecture

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

- Interactive diagram: https://gitdiagram.com/rorkai/21st
- Repository: https://github.com/rorkai/21st

## Overview

##### High-Level Architecture Overview

a) Frontend Layer (Next.js Application)
- Key areas:
- Public facing pages (/app directory)
- Component preview system
- Publishing interface
- Authentication flows

b) Backend Services Layer
- In the middle, showing connections to:
- Clerk (Authentication)
- Supabase (Database)
- Cloudflare R2 (Component Storage)
- CodeSandbox/Sandpack (Component Preview)

c) Storage Layer
- At the bottom, showing:
- Supabase Database
- R2 Storage Bucket

##### Component Relationships

a) Client-Side Flow:
**User Interface → Authentication → Component Registry → Preview System**

b) Publishing Flow:
**Upload → Validation → Storage → Registry Update**

##### Detailed Component Breakdown

Frontend (Next.js):
- Public Pages
- Component Browser
- User Profiles
- Publishing Interface
- API Routes
- Component Registry
- Webhooks
- Cache Management
- Shared Components
- UI Components
- Preview System

Backend Services:
- Authentication (Clerk)
- Database (Supabase)
- Storage (Cloudflare R2)
- Preview (Sandpack)

##### Key Workflows to Highlight

a) Component Installation:
**npx shadcn → Registry API → Component Retrieval → Local Installation**

b) Component Publishing:
**Upload → Validation → Storage → Registry Update → Preview Generation**

##### Integration Points

Clear connections for:
- Clerk webhook integration with Supabase
- R2 storage integration with component registry
- Sandpack preview system integration
- shadcn CLI integration points

##### Scale and Performance

Highlight:
- CDN integration points
- Cache layers
- Database optimization points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI["User Interface"]
        Pages["Public Pages"]
        Preview["Component Preview System"]
        Publish["Publishing Interface"]
        SharedUI["Shared UI Components"]
        CompReg["Component Registry"]
    end

    subgraph BackendServices
        Auth["Authentication (Clerk)"]
        DB["Database (Supabase)"]
        Storage["Storage (R2)"]
        SandP["Preview (Sandpack)"]
    end

    subgraph APIRoutes
        RegAPI["Component Registry API"]
        WebHooks["Webhooks"]
        Cache["Cache Management"]
    end

    %% Frontend Connections
    UI --> Auth
    UI --> CompReg
    CompReg --> Preview
    Preview --> SandP
    Publish --> Storage

    %% Backend Connections
    Auth --> DB
    RegAPI --> DB
    RegAPI --> Storage
    WebHooks --> DB
    Cache --> Storage

    %% Component Registry Flow
    CompReg --> RegAPI
    RegAPI --> Storage
    Storage --> Preview

    %% Publishing Flow
    Publish --> RegAPI
    Publish --> Preview

    %% Styling
    classDef frontend fill:#3b82f6,color:#fff
    classDef backend fill:#22c55e,color:#fff
    classDef storage fill:#f97316,color:#fff
    classDef api fill:#a855f7,color:#fff

    class UI,Pages,Preview,Publish,SharedUI,CompReg frontend
    class Auth,DB,Storage,SandP backend
    class RegAPI,WebHooks,Cache api

    %% Click Events
    click UI "https://github.com/rorkai/21st/blob/main/apps/web/components/Header.tsx"
    click Pages "https://github.com/rorkai/21st/tree/main/apps/web/app"
    click Preview "https://github.com/rorkai/21st/blob/main/apps/web/components/ComponentPreview.module.css"
    click Publish "https://github.com/rorkai/21st/tree/main/apps/web/app/publish"
    click SharedUI "https://github.com/rorkai/21st/tree/main/apps/web/components/ui"
    click CompReg "https://github.com/rorkai/21st/blob/main/apps/web/components/ComponentCard.tsx"
    click Auth "https://github.com/rorkai/21st/blob/main/apps/web/lib/clerk.ts"
    click DB "https://github.com/rorkai/21st/blob/main/apps/web/lib/supabase.ts"
    click Storage "https://github.com/rorkai/21st/blob/main/apps/web/lib/r2.ts"
    click SandP "https://github.com/rorkai/21st/blob/main/apps/web/lib/sandpack.tsx"
    click RegAPI "https://github.com/rorkai/21st/tree/main/apps/web/app/api/r"
    click WebHooks "https://github.com/rorkai/21st/tree/main/apps/web/app/api/webhooks"
    click Cache "https://github.com/rorkai/21st/tree/main/apps/web/app/api/purge-cache"
```
