# naman22a/leetcode architecture

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

- Interactive diagram: https://gitdiagram.com/naman22a/leetcode
- Repository: https://github.com/naman22a/leetcode

## Overview

##### Project type and purpose
- This is a full-stack web application: a “LeetCode clone” for coding practice with real-time code execution.
- Frontend: React + TypeScript + Monaco Editor
- Backend: NestJS monolith with modular structure, Prisma ORM, PostgreSQL, Redis, and Docker for sandboxed code execution

##### File structure
- Top-level directories:
- assets (images)
- client (React/Vite app)
- server (NestJS API server)
- Client highlights:
- /src/pages – top-level page routes (Auth, Home, ProblemDetails, Profile)
- /src/components – reusable UI (Shadcn UI primitives, Header, Submissions list)
- /src/api – typed API adapters for auth, problems, submissions, users
- React Query + Monaco Editor for code editing/execution UI
- Server highlights:
- /src/modules – domain modules (auth, problems, submissions) each with controller, service, tests
- /src/shared/users – shared user-management module
- /src/prisma – PrismaModule + migrations + seed script
- /src/common – guards, pipes, constants, Redis client helper
- Docker invoked at runtime to run user‐submitted code

##### README for additional insights
- Confirms tech stack and that code runs in isolated Docker containers
- Mentions Redis (likely for caching JWT/session data or queueing execution tasks)

##### Detailed callouts
- Inside the NestJS block, cluster sub-components: AuthModule, ProblemsModule, SubmissionsModule, SharedUsersModule, PrismaModule, Common utilities
- That Prisma migrations and seed scripts initialize the DB schema
- “Code Execution Service” as a separate process invoked by SubmissionsModule
- That React Query handles client-side caching and state for API calls

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend SPA" 
        direction TB
        FrontendSpa["React/Vite SPA"]:::frontend
        Pages["Pages (Auth, Home, ProblemDetails, Profile)"]:::frontend
        Components["UI Components (Shadcn UI, Header, SubmissionsList)"]:::frontend
        APIAdapters["API Adapters (auth, problems, submissions, users)"]:::frontend
        Main["main.tsx"]:::frontend
        Utils["utils.ts"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend API Gateway (NestJS)" 
        direction TB
        Bootstrap["NestJS Bootstrap (main.ts)"]:::backend
        AppModule["AppModule"]:::backend
        AuthModule["AuthModule"]:::backend
        GitHubStrategy["GitHub OAuth Strategy"]:::backend
        ProblemsModule["ProblemsModule"]:::backend
        SubmissionsModule["SubmissionsModule"]:::backend
        SharedUsersModule["SharedUsersModule"]:::backend
        PrismaModule["PrismaModule"]:::backend
        PrismaService["PrismaService"]:::backend
        CommonUtils["Common Utilities (guards, pipes, constants)"]:::backend
        RedisClient["Redis Client"]:::backend
        Config["Config (env validation)"]:::backend
        E2ETests["E2E Tests"]:::backend
    end

    %% Code Execution Service
    DockerExec["Docker Execution Service"]:::external

    %% Data Stores
    Postgres["PostgreSQL"]:::database
    Redis["Redis"]:::database
    OAuth["GitHub OAuth"]:::external

    %% Flows
    User["User"]:::user
    User --> Browser["Browser"]:::user
    Browser --> FrontendSpa
    FrontendSpa --> Pages
    FrontendSpa --> Components
    FrontendSpa --> APIAdapters
    FrontendSpa --> Main
    FrontendSpa --> Utils

    APIAdapters -->|"HTTPS/JSON"| Bootstrap
    Bootstrap --> AppModule
    AppModule --> AuthModule
    AuthModule --> GitHubStrategy
    AuthModule --> RedisClient
    AuthModule --> Config
    AuthModule -->|"JWT Issuance"| FrontendSpa
    AuthModule -.->|OAuth Flow| OAuth
    AppModule --> ProblemsModule
    AppModule --> SubmissionsModule
    AppModule --> SharedUsersModule
    AppModule --> PrismaModule
    PrismaModule --> PrismaService
    PrismaService --> Postgres
    SubmissionsModule --> DockerExec
    DockerExec -->|executes code| SubmissionsModule
    ProblemsModule --> PrismaService
    SharedUsersModule --> PrismaService
    AuthModule --> PrismaService
    CommonUtils --> RedisClient
    CommonUtils --> Config
    Bootstrap --> E2ETests
    RedisClient --> Redis

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#3399FF,color:#000
    classDef backend fill:#DFFFE0,stroke:#33AA33,color:#000
    classDef database fill:#FFE0B2,stroke:#FF9900,color:#000
    classDef external fill:#EEEEEE,stroke:#999999,color:#000,stroke-dasharray: 5 5
    classDef user fill:#FFF0F0,stroke:#FF6666,color:#000

    %% Click Events
    click FrontendSpa "https://github.com/naman22a/leetcode/tree/master/client/"
    click Pages "https://github.com/naman22a/leetcode/tree/master/client/src/pages/"
    click Components "https://github.com/naman22a/leetcode/tree/master/client/src/components/"
    click APIAdapters "https://github.com/naman22a/leetcode/tree/master/client/src/api/"
    click Main "https://github.com/naman22a/leetcode/blob/master/client/src/main.tsx"
    click Utils "https://github.com/naman22a/leetcode/blob/master/client/src/lib/utils.ts"
    click Bootstrap "https://github.com/naman22a/leetcode/blob/master/server/src/main.ts"
    click AppModule "https://github.com/naman22a/leetcode/blob/master/server/src/app.module.ts"
    click AuthModule "https://github.com/naman22a/leetcode/blob/master/server/src/auth/auth.module.ts"
    click GitHubStrategy "https://github.com/naman22a/leetcode/blob/master/server/src/auth/github.strategy.ts"
    click ProblemsModule "https://github.com/naman22a/leetcode/tree/master/server/src/modules/problems/"
    click SubmissionsModule "https://github.com/naman22a/leetcode/tree/master/server/src/modules/submissions/"
    click SharedUsersModule "https://github.com/naman22a/leetcode/tree/master/server/src/shared/users/"
    click PrismaModule "https://github.com/naman22a/leetcode/blob/master/server/src/prisma/prisma.module.ts"
    click PrismaService "https://github.com/naman22a/leetcode/blob/master/server/src/prisma/prisma.service.ts"
    click CommonUtils "https://github.com/naman22a/leetcode/tree/master/server/src/common/"
    click RedisClient "https://github.com/naman22a/leetcode/blob/master/server/src/common/redis.ts"
    click Config "https://github.com/naman22a/leetcode/tree/master/server/src/config/"
    click E2ETests "https://github.com/naman22a/leetcode/blob/master/server/test/app.e2e-spec.ts"
    click Postgres "https://github.com/naman22a/leetcode/blob/master/server/prisma/schema.prisma"
    click Redis "https://github.com/naman22a/leetcode/tree/master/server/prisma/migrations/"
    click OAuth "https://github.com/naman22a/leetcode/blob/master/server/prisma/seed.ts"
```
