# ishaan1013/sandbox architecture

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

- Interactive diagram: https://gitdiagram.com/ishaan1013/sandbox
- Repository: https://github.com/ishaan1013/sandbox

## Overview

##### Main System Components

a) Frontend Layer:
- Next.js application (React)
- Key components:
- Editor interface (Monaco)
- Real-time collaboration features (Liveblocks)
- Authentication (Clerk)
- Dashboard & UI components

b) Backend Services:
- Express/Socket.io Server
- Cloudflare Workers Microservices:
- Database Worker (D1)
- Storage Worker (R2)
- AI Worker (Workers AI)
- E2B Sandbox Environment

##### Component Relationships

a) Client-Server Communication:
- WebSocket connections between frontend and Express server
- HTTP/REST endpoints between frontend and Cloudflare Workers
- Authentication flow through Clerk

b) Microservices Integration:
- Service binding between D1 Database and R2 Storage
- AI Worker integration for code completion
- E2B sandbox instances for terminal and preview functionality

##### Specific Implementation Details

- Blue rectangles: Frontend components
- Green rectangles: Backend services
- Yellow diamonds: External services (Clerk, Liveblocks, E2B)
- Red hexagon: AI Worker

##### Data Flow Representation

a) User Interactions:
- Authentication flow → Clerk → Frontend → Backend
- Code editing → Monaco → Liveblocks → Other users
- File operations → Storage Worker → R2
- Terminal commands → E2B Sandbox

b) Backend Processing:
- Database operations → D1 Worker
- File storage → R2 Worker
- AI completions → Workers AI
- Real-time updates → Socket.io

##### Additional Elements

Important aspects:

- Security boundaries (authentication zones)
- Service scaling indicators
- API endpoints and WebSocket connections
- Database schema references
- File storage organization

**[Client Layer]**
- ↓↑
**[API/WebSocket Layer]**
- ↓↑
**[Service Layer]**
- ↓↑
**[Storage Layer]**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        UI[Frontend Application]
        ED["Editor Interface"]
        RT["Real-time Collaboration"]
        AUTH["Authentication System"]
        DASH["Dashboard"]
        TERM["Terminal Integration"]
        PREV["Preview Functionality"]
        FILE["File Operations"]
        LIVE["Live Collaboration"]
        PROJ["Project Management"]
    end

    subgraph "Backend Services"
        EXPRESS["Express/Socket.io Server"]
        
        subgraph "Cloudflare Workers"
            DBW["Database Worker"]
            STW["Storage Worker"]
            AIW["AI Worker"]
        end
        
        D1[(D1 Database)]
        R2[(R2 Storage)]
    end

    subgraph "External Services"
        CLERK["Clerk Auth"]
        LIVE_BLOCKS["Liveblocks"]
        E2B["E2B Sandbox"]
    end

    %% Connections
    UI --> EXPRESS
    UI --> CLERK
    UI --> LIVE_BLOCKS
    EXPRESS --> E2B
    EXPRESS --> DBW
    EXPRESS --> STW
    EXPRESS --> AIW
    DBW --> D1
    STW --> R2
    
    %% Component relationships
    ED --> RT
    RT --> LIVE_BLOCKS
    AUTH --> CLERK
    TERM --> E2B
    FILE --> STW
    
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef ai fill:#e74c3c,stroke:#c0392b,color:white

    class UI,ED,RT,AUTH,DASH,TERM,PREV,FILE,LIVE,PROJ frontend
    class EXPRESS,DBW,STW backend
    class CLERK,LIVE_BLOCKS,E2B external
    class D1,R2 storage
    class AIW ai

    %% Click events
    click ED "https://github.com/ishaan1013/sandbox/blob/main/frontend/components/editor/index.tsx"
    click RT "https://github.com/ishaan1013/sandbox/tree/main/frontend/components/editor/live"
    click AUTH "https://github.com/ishaan1013/sandbox/tree/main/frontend/app/(auth)"
    click DASH "https://github.com/ishaan1013/sandbox/tree/main/frontend/components/dashboard"
    click EXPRESS "https://github.com/ishaan1013/sandbox/blob/main/backend/server/src/index.ts"
    click DBW "https://github.com/ishaan1013/sandbox/blob/main/backend/database/src/index.ts"
    click STW "https://github.com/ishaan1013/sandbox/blob/main/backend/storage/src/index.ts"
    click AIW "https://github.com/ishaan1013/sandbox/blob/main/backend/ai/src/index.ts"
    click TERM "https://github.com/ishaan1013/sandbox/tree/main/frontend/components/editor/terminals"
    click PREV "https://github.com/ishaan1013/sandbox/tree/main/frontend/components/editor/preview"
    click FILE "https://github.com/ishaan1013/sandbox/tree/main/frontend/components/editor/sidebar"
    click LIVE "https://github.com/ishaan1013/sandbox/blob/main/frontend/components/editor/live/room.tsx"
    click PROJ "https://github.com/ishaan1013/sandbox/blob/main/frontend/components/dashboard/projects.tsx"

    %% Legend
    subgraph Legend
        F["Frontend Component"]:::frontend
        B["Backend Service"]:::backend
        E["External Service"]:::external
        S["Storage System"]:::storage
        A["AI Service"]:::ai
    end
```
