# manangandhi1810/online-ide architecture

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

- Interactive diagram: https://gitdiagram.com/manangandhi1810/online-ide
- Repository: https://github.com/manangandhi1810/online-ide

## Overview

##### Main Components

a) Client Layer:
- React.js Frontend (Port 8000/5173)
- Key features: Code Editor, Authentication UI, Problem Viewer, Leaderboard
- Integration with Shadcn/UI and Monaco Editor

b) API Layer:
- Express.js Backend (Port 3000)
- Split into distinct service routes:
- Authentication
- Code Execution
- Problem Statements
- Editorials
- Leaderboard
- User Management

c) Database Layer:
- PostgreSQL with Prisma ORM
- Redis for caching and messaging

d) Execution Layer:
- Docker Container Management
- Code Runner Service
- Python Executor

e) External Services:
- CloudFlare Workers AI (LLaMA 3.1 8B)
- Resend Email Service
- GitHub OAuth

##### Relationship Flows to Highlight

a) Authentication Flow:
- JWT-based auth
- Email verification
- OTP handling
- Password reset flow

b) Code Execution Flow:
- Code submission
- Docker container creation
- Test case verification
- Result processing

c) Data Flows:
- Problem statement delivery
- Editorial management
- Leaderboard updates
- Points system

##### Specific Design Elements

Use the following visual elements:

**[Client Layer]**
- ↓
**[API Gateway/Backend Layer]**
- ↓
**[Service Layer (Auth, Code, Problems)]**
- ↓
**[Data Layer (PostgreSQL, Redis)]**
- ↓
**[Execution Layer (Docker)]**

##### Important Details

a) Security Measures:
- Rate limiting
- Sandboxed execution
- JWT authentication
- Email verification

b) Performance Features:
- Redis caching
- Docker container management
- Streaming AI responses

c) Integration Points:
- AI Assistant integration
- Email service
- OAuth providers
- Docker API

##### Technical Specifications

- Supported languages (Python, C, C++, Java)
- Points system rules
- Resource limits for code execution
- Authentication token lifecycle

Remember to indicate the stateful vs stateless components, and show how the system handles concurrent code executions through the Docker container management system.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Client
        FE[Frontend App]:::frontend
        CE["Code Editor"]:::frontend
        PV["Problem Viewer"]:::frontend
        LB["Leaderboard UI"]:::frontend
        AU["Authentication UI"]:::frontend
        
        FE --> CE
        FE --> PV
        FE --> LB
        FE --> AU
    end

    %% API Layer
    subgraph API
        AG[API Gateway]:::backend
        AS["Auth Service"]:::backend
        CS["Code Service"]:::backend
        PS["Problem Service"]:::backend
        ES["Editorial Service"]:::backend
        LS["Leaderboard Service"]:::backend
    end

    %% Database Layer
    subgraph Data
        DB[(PostgreSQL)]:::database
        RC[(Redis Cache)]:::database
    end

    %% Execution Layer
    subgraph Execution
        DM["Docker Manager"]:::execution
        CR["Code Runner"]:::execution
        EW["Execution Worker"]:::execution
    end

    %% External Services
    subgraph External
        AI["CloudFlare Workers AI"]:::external
        EM["Resend Email"]:::external
        GH["GitHub OAuth"]:::external
    end

    %% Security Layer
    subgraph Security
        AM["Auth Middleware"]:::security
        RL["Rate Limiter"]:::security
    end

    %% Relationships
    Client --> AG
    AG --> Security
    Security --> AS
    Security --> CS
    Security --> PS
    Security --> ES
    Security --> LS

    AS --> DB
    CS --> DB
    PS --> DB
    ES --> DB
    LS --> DB

    AS --> RC
    CS --> RC
    PS --> RC
    ES --> RC
    LS --> RC

    CS --> DM
    DM --> CR
    CR --> EW
    EW --> CS

    AS --> EM
    AS --> GH
    CS --> AI

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef execution fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
    classDef security fill:#34495e,stroke:#2c3e50,color:white

    %% Click Events
    click FE "https://github.com/MananGandhi1810/online-ide/tree/main/frontend/src"
    click CE "https://github.com/MananGandhi1810/online-ide/blob/main/frontend/src/pages/Code.jsx"
    click PV "https://github.com/MananGandhi1810/online-ide/blob/main/frontend/src/pages/Problems.jsx"
    click LB "https://github.com/MananGandhi1810/online-ide/blob/main/frontend/src/pages/Leaderboard.jsx"
    click AU "https://github.com/MananGandhi1810/online-ide/blob/main/frontend/src/pages/Login.jsx"
    click AS "https://github.com/MananGandhi1810/online-ide/blob/main/backend/router/auth.js"
    click CS "https://github.com/MananGandhi1810/online-ide/blob/main/backend/router/code.js"
    click PS "https://github.com/MananGandhi1810/online-ide/blob/main/backend/router/problem-statement.js"
    click ES "https://github.com/MananGandhi1810/online-ide/blob/main/backend/router/editorial.js"
    click LS "https://github.com/MananGandhi1810/online-ide/blob/main/backend/router/leaderboard.js"
    click DB "https://github.com/MananGandhi1810/online-ide/blob/main/backend/prisma/schema.prisma"
    click RC "https://github.com/MananGandhi1810/online-ide/blob/main/backend/utils/keyvalue-db.js"
    click DM "https://github.com/MananGandhi1810/online-ide/blob/main/backend/utils/docker.js"
    click CR "https://github.com/MananGandhi1810/online-ide/blob/main/code-runner/executor.py"
    click EW "https://github.com/MananGandhi1810/online-ide/blob/main/backend/execution-worker/execute.js"
    click AI "https://github.com/MananGandhi1810/online-ide/blob/main/backend/utils/ai-model.js"
    click EM "https://github.com/MananGandhi1810/online-ide/blob/main/backend/utils/email.js"
    click GH "https://github.com/MananGandhi1810/online-ide/blob/main/backend/utils/github-api.js"
    click AM "https://github.com/MananGandhi1810/online-ide/blob/main/backend/middlewares/auth.js"
    click RL "https://github.com/MananGandhi1810/online-ide/blob/main/backend/middlewares/rate-limit.js"
```
