# harshit27gupta/algo_project architecture

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

- Interactive diagram: https://gitdiagram.com/harshit27gupta/algo_project
- Repository: https://github.com/harshit27gupta/algo_project

## Overview

##### Project Type and Purpose
- From the file‐tree and README we see a “client” (React/Vite), “server” (Node/Express/MongoDB) and a separate “Compiler” service (Node scripts for C/C++/Java execution).
- It’s a full-stack online judge platform: users interact via the web UI, the backend handles auth, problems, submissions and persistence, and the Compiler service compiles/runs code in isolation.

##### High-Level Architecture
- Three core components, each running in its own container:
a. Frontend (client) – React app served by Nginx
b. Backend API – Express.js app with controllers, models, middleware, MongoDB persistence
c. Compiler Service – lightweight microservice exposing endpoints to compile & run code

- Supporting services:
- MongoDB for data storage (users, problems, submissions, stats)
- External OAuth (Google) & AI (Gemini) APIs
- (Optional) Redis for caching/rate-limiting

##### Detail & Clarity
- Include:
- Component names & responsibilities
- Data flows with arrowheads and labels (e.g., “User code + metadata”)
- Authentication flow: Login → JWT issuance → Protected endpoints
- AI hint/chat workflow: Frontend → aiController → Gemini API → Frontend

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External User
    Browser["Browser"]:::external

    %% Frontend Layer
    subgraph "Frontend (React/Vite, port 3000)"
        direction TB
        Nginx["Nginx\nserving static (client/nginx.conf)"]:::frontend
        ReactApp["React App\n(src/main.jsx, src/App.jsx)"]:::frontend
        subgraph "Frontend Pages"
            Pages["Pages\n(client/src/pages/)"]:::frontend
        end
        subgraph "Frontend Components"
            Components["Components\n(client/src/components/)"]:::frontend
        end
        APIService["API Service\n(client/src/services/api.js)"]:::frontend
        Utils["Utils\n(client/src/utils/)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend API (Express.js, port 5000)"
        direction TB
        BackendEntry["Entry Point\n(server/index.js)"]:::backend
        Controllers["Controllers\n(server/controllers/)"]:::backend
        Routes["Routes\n(server/routes/)"]:::backend
        Middleware["Middleware\n(server/middleware/)"]:::backend
        Models["Models\n(server/models/)"]:::backend
        UtilsBE["Utilities\n(server/utils/)"]:::backend
    end

    %% Compiler Service Layer
    subgraph "Compiler Service (HTTP, port 8000)"
        direction TB
        CompilerEntry["Entry Point\n(Compiler/index.js)"]:::compiler
        Executors["Executors\n(Compiler/executeC.js, executeCpp.js, executeJava.js)"]:::compiler
        Helpers["Helpers\n(Compiler/sanitizeCode.js, generateFile.js)"]:::compiler
    end

    %% Databases and External Services
    MongoDB["MongoDB\n(persistent storage)"]:::external
    GoogleOAuth["Google OAuth\n(external API)"]:::external
    GeminiAI["Gemini AI\n(external API)"]:::external
    Redis["Redis\n(optional cache)"]:::external

    %% Interactions
    Browser -->|"load app"| Nginx
    Nginx -->|"serve React"| ReactApp
    ReactApp -->|"HTTP: login, fetch problems, submit code, fetch stats"| BackendEntry
    ReactApp -->|"async AI hints/chat"| BackendEntry
    ReactApp -->|"static asset requests"| Nginx

    BackendEntry -->|"uses Controllers & Routes"| Controllers
    BackendEntry --> Controllers
    BackendEntry --> Routes
    Controllers --> Models
    Controllers --> UtilsBE
    Routes --> Middleware
    Middleware --> BackendEntry

    BackendEntry -->|"CRUD operations"| MongoDB
    BackendEntry -->|"POST /api/v1/submissions"| CompilerEntry
    BackendEntry -->|"AI hints request"| GeminiAI
    BackendEntry -.->|"optional caching"| Redis

    CompilerEntry --> Executors
    CompilerEntry --> Helpers
    Executors --> Helpers

    %% Click Events
    click Nginx "https://github.com/harshit27gupta/algo_project/blob/main/client/nginx.conf"
    click ReactApp "https://github.com/harshit27gupta/algo_project/blob/main/client/src/main.jsx"
    click ReactApp "https://github.com/harshit27gupta/algo_project/blob/main/client/src/App.jsx"
    click Pages "https://github.com/harshit27gupta/algo_project/tree/main/client/src/pages/"
    click Components "https://github.com/harshit27gupta/algo_project/tree/main/client/src/components/"
    click APIService "https://github.com/harshit27gupta/algo_project/blob/main/client/src/services/api.js"
    click Utils "https://github.com/harshit27gupta/algo_project/tree/main/client/src/utils/"
    click BackendEntry "https://github.com/harshit27gupta/algo_project/blob/main/server/index.js"
    click Controllers "https://github.com/harshit27gupta/algo_project/tree/main/server/controllers/"
    click Routes "https://github.com/harshit27gupta/algo_project/tree/main/server/routes/"
    click Middleware "https://github.com/harshit27gupta/algo_project/tree/main/server/middleware/"
    click Models "https://github.com/harshit27gupta/algo_project/tree/main/server/models/"
    click UtilsBE "https://github.com/harshit27gupta/algo_project/tree/main/server/utils/"
    click CompilerEntry "https://github.com/harshit27gupta/algo_project/blob/main/Compiler/index.js"
    click Executors "https://github.com/harshit27gupta/algo_project/blob/main/Compiler/executeC.js"
    click Helpers "https://github.com/harshit27gupta/algo_project/blob/main/Compiler/sanitizeCode.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef backend fill:#DFF6DD,stroke:#22863A,color:#22863A;
    classDef compiler fill:#FFE8A1,stroke:#D29922,color:#D29922;
    classDef external fill:#F0F0F0,stroke:#666666,color:#333333,stroke-dasharray: 2 2;
```
