# andreaswt/figma-clone architecture

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

- Interactive diagram: https://gitdiagram.com/andreaswt/figma-clone
- Repository: https://github.com/andreaswt/figma-clone

## Overview

##### Project type and purpose
- This is a full-stack, real-time collaborative “Figma clone” built with Next.js 13 (app router), React 18, TypeScript, Prisma (Postgres), NextAuth.js for authentication, and Liveblocks for live collaboration.

##### File structure
- Top-level:
- src/app – Next.js pages and layout
- src/app/api – NextAuth routes and Liveblocks auth endpoint
- src/server – database and auth server logic
- prisma/schema.prisma – database schema
- public – static assets (e.g., thumbnail)
- components & hooks – React UI and custom hooks
- Patterns:
- App Router → React Server/Client Components
- API Routes for auth and liveblocks token generation
- Prisma ORM for DB access
- Liveblocks handles WebSocket-style real-time sync
- NextAuth.js for session management
- Tailwind CSS/postCSS for styling

##### README for additional insights
- Confirms stack: Next.js, React, TypeScript, Liveblocks, Prisma/Postgres, Vercel.
- Outlines features and flow: user signs up/in → lands on dashboard → creates/joins drawing rooms → real-time collaboration.

- Use clear labels: e.g., “Browser (React Client)”, “Next.js Serverless Functions”, “PostgreSQL (Prisma)”, “Liveblocks Service”.
- Blue = frontend components
- Green = backend/API
- Orange = database
- Purple = external real-time service

##### Detailed capture of essential elements
- Break the system into at least these layers:
- Presentation (React components: canvas, toolbars, sidebars, dashboard)
- API & business logic (Next.js app router, `src/server`, NextAuth config)
- Data (Prisma, Postgres)
- Real-time collaboration (Liveblocks auth + live service)
- Deployment (Vercel hosting static + serverless)
- Don’t omit utility modules (`src/utils.ts`, `src/schemas.ts`), middleware, or hooks—they support the data flow and UI logic.

[Browser: React UI]
| (HTTP GET/POST) ──> [Next.js App Router + API Routes]
|                     ├─ /api/auth ←── NextAuth.js
|                     ├─ /api/liveblocks-auth ──> Liveblocks Server
|                     └─ Prisma Client ──> Postgres DB
└─(WebSocket) ──> Liveblocks Real-time Service

## Diagram (Mermaid)

```mermaid
graph TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Browser (React Client)"]:::frontend
        CanvasComp["Canvas Components"]:::frontend
        ToolsBarComp["Toolbar Components"]:::frontend
        SidebarsComp["Sidebar Components"]:::frontend
        DashboardComp["Dashboard Components"]:::frontend
        LiveblocksClient["Liveblocks Client"]:::frontend
    end

    %% API & Business Logic
    subgraph "API & Business Logic"
        direction TB
        NextJSApp["Next.js App Router"]:::backend
        NextJSAPI["Next.js API Routes"]:::backend
        NextAuthAPI["NextAuth API Route"]:::backend
        AuthLogic["Server-side Auth Logic"]:::backend
        LiveblocksAuthAPI["Liveblocks Auth API Route"]:::backend
        Actions["Application Actions"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        PrismaInit["Prisma Client"]:::db
        PostgresDB["PostgreSQL Database"]:::db
        SchemaPrisma["prisma/schema.prisma"]:::db
    end

    %% Real-time Collaboration
    subgraph "Real-time Collaboration"
        direction TB
        LiveblocksSvc["Liveblocks Real-time Service"]:::external
    end

    %% Deployment
    subgraph "Deployment"
        direction TB
        Vercel["Vercel Hosting (Static & Serverless)"]:::infra
        CDN["Static Assets CDN"]:::infra
    end

    %% Connections
    Browser --> CanvasComp
    Browser --> ToolsBarComp
    Browser --> SidebarsComp
    Browser --> DashboardComp
    Browser --> LiveblocksClient
    Browser --> NextJSApp
    NextJSApp --> NextJSAPI
    NextJSAPI --> NextAuthAPI
    NextAuthAPI --> AuthLogic
    AuthLogic --> PrismaInit
    NextJSAPI --> LiveblocksAuthAPI
    LiveblocksAuthAPI --> LiveblocksSvc
    NextJSApp --> Actions
    Actions --> AuthLogic
    NextJSApp --> PrismaInit
    PrismaInit --> PostgresDB
    PrismaInit --> SchemaPrisma
    LiveblocksClient -.->|WebSocket| LiveblocksSvc
    Vercel -->|Hosts| Browser
    Vercel -->|Hosts| NextJSAPI
    Vercel -->|Serves| CDN

    %% Click Events
    click Browser "https://github.com/andreaswt/figma-clone/tree/main/src/app"
    click NextJSApp "https://github.com/andreaswt/figma-clone/tree/main/src/app"
    click NextJSAPI "https://github.com/andreaswt/figma-clone/tree/main/src/app/api"
    click NextAuthAPI "https://github.com/andreaswt/figma-clone/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click AuthLogic "https://github.com/andreaswt/figma-clone/blob/main/src/server/auth/config.ts"
    click AuthLogic "https://github.com/andreaswt/figma-clone/blob/main/src/server/auth/index.ts"
    click LiveblocksAuthAPI "https://github.com/andreaswt/figma-clone/blob/main/src/app/api/liveblocks-auth/route.ts"
    click PrismaInit "https://github.com/andreaswt/figma-clone/blob/main/src/server/db.ts"
    click SchemaPrisma "https://github.com/andreaswt/figma-clone/blob/main/prisma/schema.prisma"
    click CanvasComp "https://github.com/andreaswt/figma-clone/blob/main/src/components/canvas/Canvas.tsx"
    click LiveblocksClient "https://github.com/andreaswt/figma-clone/blob/main/src/components/liveblocks/Room.tsx"
    click ToolsBarComp "https://github.com/andreaswt/figma-clone/blob/main/src/components/toolsbar/ToolsBar.tsx"
    click SidebarsComp "https://github.com/andreaswt/figma-clone/blob/main/src/components/sidebars/Sidebars.tsx"
    click DashboardComp "https://github.com/andreaswt/figma-clone/blob/main/src/components/dashboard/RoomsView.tsx"
    click Actions "https://github.com/andreaswt/figma-clone/blob/main/src/app/actions/auth.ts"
    click Actions "https://github.com/andreaswt/figma-clone/blob/main/src/app/actions/rooms.ts"
    click CDN "https://github.com/andreaswt/figma-clone/tree/main/public"
    click Vercel "https://github.com/andreaswt/figma-clone/blob/main/tailwind.config.ts"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef db fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef infra fill:#f5c6cb,stroke:#721c24,color:#721c24
```
