# abhiiinav6/codecook architecture

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

- Interactive diagram: https://gitdiagram.com/abhiiinav6/codecook
- Repository: https://github.com/abhiiinav6/codecook

## Overview

##### Project Type and Purpose
- This is a full-stack, web-based “Codecook” platform for coding problems, submissions, and live code execution.
- The client is a React + TypeScript single-page-app (SPA) built with Vite and Tailwind CSS.
- The server is a Node.js/Express API using Prisma ORM to talk to a SQL database and integrates with Judge0 for code compilation/execution.

##### Main Components
a. Frontend (Client)
- App shell: React, TypeScript, Vite, Tailwind.
- UI components: Navbar, Problem tables/cards, CodePlayground, Submission views, Auth flows.
- Context: AuthContext for JWT and user session.
- Routes: Home, Login, Signup, Problem detail, Submission detail, Top submissions.
b. Backend (Server)
- HTTP API: Express app (`index.ts`) with route modules (auth, problem, submissions).
- Controllers: Business logic for each resource.
- Middlewares: JWT auth guard, request logger.
- Prisma ORM: `schema.prisma` + migrations → SQL database.
- Utils: Compiler integration with Judge0 REST API.
c. Database
- PostgreSQL (or compatible) with tables for users, problems, submissions, testcases, etc.
- Managed via Prisma migration files under `server/prisma/migrations`.
d. External Service
- Judge0 code-execution engine (REST endpoint) for sandboxed code compiling and running.

##### Relationships and Data Flows
- Browser → HTTP(S) requests → Frontend React Router → API calls to Backend endpoints (e.g., `/api/auth/login`, `/api/problems`, `/api/submissions`).
- Backend routes → Controllers → Prisma client → Database (CRUD).
- On code submission: Controller calls `compiler.ts` util → judge0 REST API → receives execution results → stores results via Prisma → returns to client.
- Frontend reads execution result, errors, TestCaseResults from response and updates UI.

##### Architectural Patterns and Principles
- Client-server separation (SPA frontend + RESTful backend).
- Layered backend: Routes → Middlewares → Controllers → Data access (ORM).
- Single source of truth for state in frontend via React contexts and routed pages.
- Externalization of compute-heavy work to Judge0 (microservice integration).
- Database schema versioning and migrations handled by Prisma.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Swimlanes
    subgraph "User / Browser"
        U["User / Browser"]
    end

    subgraph "Frontend SPA"
        AppShell["React + TS + Vite + Tailwind"]:::frontend
        subgraph "Routes"
            Home["Home"]:::frontend
            Login["Login"]:::frontend
            Signup["Signup"]:::frontend
            ProblemRouteFE["Problem Detail"]:::frontend
            SubmissionRouteFE["Submission Detail"]:::frontend
            TopSubmissions["Top Submissions"]:::frontend
        end
        subgraph "UI Components"
            Navbar["Navbar"]:::frontend
            ProblemCard["ProblemCard"]:::frontend
            ProblemTable["ProblemTable"]:::frontend
            ProblemTableSkeleton["ProblemTableSkeleton"]:::frontend
            ProblemNotExist["ProblemNotExist"]:::frontend
            SubmissionCard["SubmissionCard"]:::frontend
            CodePlayground["CodePlayground"]:::frontend
        end
        AuthContext["AuthContext"]:::frontend
        UtilsFE["utils.ts"]:::frontend
    end

    subgraph "Backend API"
        Express["Node.js + Express"]:::backend
        subgraph "Routes"
            AuthRoute["auth.ts"]:::backend
            ProblemRouteBE["problem.ts"]:::backend
            SubmissionRouteBE["submissions.ts"]:::backend
        end
        subgraph "Controllers"
            AuthCtrl["AuthController"]:::backend
            ProblemCtrl["ProblemController"]:::backend
            SubmissionCtrl["SubmissionController"]:::backend
        end
        subgraph "Middlewares"
            AuthGuard["JWT Auth Guard"]:::backend
            Logger["Request Logger"]:::backend
        end
        subgraph "Utils"
            Compiler["compiler.ts"]:::backend
        end
        DBInit["db/index.ts"]:::backend
    end

    subgraph "External Services & Database"
        DB["Prisma → PostgreSQL"]:::database
        Migrations["migrations/*"]:::database
        Judge0["Judge0 API"]:::external
    end

    %% Data Flows
    U -->|"interacts with"| AppShell
    AppShell -->|"renders"| Navbar
    AppShell -->|"routes to"| Home
    Home -->|"navigates"| Login
    Home -->|"navigates"| Signup
    Home -->|"navigates"| ProblemRouteFE
    Home -->|"navigates"| SubmissionRouteFE
    Home -->|"navigates"| TopSubmissions
    AppShell -->|"provides"| AuthContext

    CodePlayground -->|"POST /api/submissions"| SubmissionRouteBE
    SubmissionRouteBE -->|"uses"| AuthGuard
    SubmissionRouteBE -->|"calls"| SubmissionCtrl
    SubmissionRouteBE -->|"response"| CodePlayground

    AuthRoute -->|"calls"| AuthCtrl
    ProblemRouteBE -->|"calls"| ProblemCtrl

    SubmissionCtrl -->|"prisma query"| DBInit
    ProblemCtrl -->|"prisma query"| DBInit
    AuthCtrl -->|"prisma query"| DBInit

    DBInit -->|"connects to"| DB
    DBInit -->|"runs migrations"| Migrations

    SubmissionCtrl -->|"calls"| Compiler
    Compiler -->|"HTTP request"| Judge0
    Judge0 -->|"execution result"| Compiler
    Compiler -->|"returns result"| SubmissionCtrl

    %% Click Events
    click AppShell "https://github.com/abhiiinav6/codecook/blob/main/client/src/App.tsx"
    click Navbar "https://github.com/abhiiinav6/codecook/blob/main/client/src/components/Navbar.tsx"
    click ProblemCard "https://github.com/abhiiinav6/codecook/blob/main/client/src/components/problem/ProblemCard.tsx"
    click ProblemTable "https://github.com/abhiiinav6/codecook/blob/main/client/src/components/problem/ProblemTable.tsx"
    click ProblemTableSkeleton "https://github.com/abhiiinav6/codecook/blob/main/client/src/components/problem/ProblemTableSkeleton.tsx"
    click ProblemNotExist "https://github.com/abhiiinav6/codecook/blob/main/client/src/components/problem/ProblemNotExist.tsx"
    click SubmissionCard "https://github.com/abhiiinav6/codecook/blob/main/client/src/components/problem/SubmissionCard.tsx"
    click CodePlayground "https://github.com/abhiiinav6/codecook/blob/main/client/src/components/playground/CodePlayground.tsx"
    click AuthContext "https://github.com/abhiiinav6/codecook/blob/main/client/src/context/AuthContext.tsx"
    click Home "https://github.com/abhiiinav6/codecook/blob/main/client/src/routes/Home.tsx"
    click Login "https://github.com/abhiiinav6/codecook/blob/main/client/src/routes/Login.tsx"
    click Signup "https://github.com/abhiiinav6/codecook/blob/main/client/src/routes/Signup.tsx"
    click ProblemRouteFE "https://github.com/abhiiinav6/codecook/blob/main/client/src/routes/Problem.tsx"
    click SubmissionRouteFE "https://github.com/abhiiinav6/codecook/blob/main/client/src/routes/Submission.tsx"
    click TopSubmissions "https://github.com/abhiiinav6/codecook/blob/main/client/src/routes/TopSubmissions.tsx"
    click UtilsFE "https://github.com/abhiiinav6/codecook/blob/main/client/src/lib/utils.ts"
    click Express "https://github.com/abhiiinav6/codecook/blob/main/server/src/index.ts"
    click AuthRoute "https://github.com/abhiiinav6/codecook/blob/main/server/src/routes/auth.ts"
    click ProblemRouteBE "https://github.com/abhiiinav6/codecook/blob/main/server/src/routes/problem.ts"
    click SubmissionRouteBE "https://github.com/abhiiinav6/codecook/blob/main/server/src/routes/submissions.ts"
    click AuthCtrl "https://github.com/abhiiinav6/codecook/blob/main/server/src/controllers/auth.ts"
    click ProblemCtrl "https://github.com/abhiiinav6/codecook/blob/main/server/src/controllers/problem.ts"
    click SubmissionCtrl "https://github.com/abhiiinav6/codecook/blob/main/server/src/controllers/submissions.ts"
    click AuthGuard "https://github.com/abhiiinav6/codecook/blob/main/server/src/middlewares/auth.ts"
    click Logger "https://github.com/abhiiinav6/codecook/blob/main/server/src/middlewares/logger.ts"
    click Compiler "https://github.com/abhiiinav6/codecook/blob/main/server/src/utils/compiler.ts"
    click DBInit "https://github.com/abhiiinav6/codecook/blob/main/server/src/db/index.ts"
    click DB "https://github.com/abhiiinav6/codecook/blob/main/server/prisma/schema.prisma"
    click Migrations "https://github.com/abhiiinav6/codecook/tree/main/server/prisma/migrations/"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef external fill:#fff3cd,stroke:#856404,color:#856404
    classDef database fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
