# rahulc34/online-compiler-backend architecture

> Architecture diagram of the GitHub repository rahulc34/online-compiler-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rahulc34/online-compiler-backend
- Repository: https://github.com/rahulc34/online-compiler-backend

## Overview

This is a Compiler API: users authenticate and submit source files and input, then retrieve execution results. The API validates and queues jobs; a separate worker claims them, dispatches by language, runs them in Docker, and records status and output. Auth also supports email verification, password reset, sessions, and Google sign-in. Edges are limited to relationships shown in excerpts or the source index; unsampled recovery, cancellation, and integrations are represented only where their wiring is evidenced.

Main entry points: [`src/workers/execution.worker.ts`](https://github.com/rahulc34/online-compiler-backend/blob/main/src/workers/execution.worker.ts) (Execution worker), [`src/services/docker.service.ts`](https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/docker.service.ts) (Docker sandbox), [`src/models/execution.model.ts`](https://github.com/rahulc34/online-compiler-backend/blob/main/src/models/execution.model.ts) (Execution records), [`src/modules/auth/auth.controller.ts`](https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/auth/auth.controller.ts) (Auth controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_app["HTTP application<br/>[app.ts]"]
  node_auth_routes["Auth routes<br/>[auth.routes.ts]"]
  node_execution_routes["Execution routes"]
end

subgraph group_identity["Identity"]
  node_auth_controller["Auth controller<br/>[auth.controller.ts]"]
  node_auth_service["Auth service<br/>[auth.service.ts]"]
  node_otp_service["Email OTP<br/>[otp.service.ts]"]
  node_mail_service["Mail delivery<br/>[mail.service.ts]"]
  node_user_model[("User records<br/>[user.model.ts]")]
  node_otp_model[("OTP records<br/>[otp.model.ts]")]
  node_passport["Google authentication<br/>[passport.ts]"]
end

subgraph group_execution["Execution"]
  node_execution_controller["Execution controller"]
  node_execution_service["Execution service"]
  node_cancellation["Cancellation service"]
  node_execution_model[("Execution records<br/>[execution.model.ts]")]
  node_queue["Job queue<br/>[execution.queue.ts]"]
  node_worker["Execution worker"]
end

subgraph group_runtime["Language runtime"]
  node_cpp["C++ runner"]
  node_java["Java runner"]
  node_script["Script runner"]
  node_javascript["JavaScript runner"]
  node_python["Python runner"]
  node_typescript["TypeScript runner"]
  node_docker["Docker sandbox<br/>[docker.service.ts]"]
end

node_user(("Client user"))
node_docker_engine{{"Docker Engine"}}
node_mongodb[("MongoDB")]
node_redis[("Redis")]
node_email_provider{{"SMTP provider"}}

node_user -->|"calls API"| node_app
node_app -->|"mounts routes"| node_auth_routes
node_app -->|"mounts routes"| node_execution_routes
node_auth_routes -->|"routes requests"| node_auth_controller
node_auth_controller -->|"delegates auth"| node_auth_service
node_auth_service -->|"reads and writes"| node_user_model
node_auth_controller -->|"verifies OTP"| node_otp_service
node_auth_service -->|"creates OTP"| node_otp_service
node_otp_service -->|"stores OTP"| node_otp_model
node_otp_service -->|"updates user"| node_user_model
node_auth_service -->|"sends reset mail"| node_mail_service
node_auth_controller -->|"authenticates Google"| node_passport
node_execution_routes -->|"routes requests"| node_execution_controller
node_execution_controller -->|"creates job"| node_execution_service
node_execution_controller -->|"reads result"| node_execution_model
node_execution_service -->|"creates record"| node_execution_model
node_execution_service -->|"enqueues job"| node_queue
node_cancellation -->|"updates status"| node_execution_model
node_cancellation -->|"removes job"| node_queue
node_cancellation -->|"uses Redis"| node_redis
node_worker -->|"consumes jobs"| node_queue
node_worker -->|"claims and updates"| node_execution_model
node_worker -->|"dispatches C++"| node_cpp
node_worker -->|"dispatches Java"| node_java
node_worker -->|"dispatches JavaScript"| node_javascript
node_worker -->|"dispatches Python"| node_python
node_worker -->|"dispatches TypeScript"| node_typescript
node_cpp -->|"runs in sandbox"| node_docker
node_java -->|"runs in sandbox"| node_docker
node_script -->|"runs in sandbox"| node_docker
node_docker -->|"controls containers"| node_docker_engine
node_docker -.->|"execution persistence"| node_mongodb
node_docker -.->|"queue infrastructure"| node_redis
node_mail_service -.->|"sends email"| node_email_provider
node_user_model -.->|"persists users"| node_mongodb
node_execution_model -.->|"persists executions"| node_mongodb

click node_app "https://github.com/rahulc34/online-compiler-backend/blob/main/src/app.ts"
click node_auth_routes "https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/auth/auth.routes.ts"
click node_auth_controller "https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/auth/auth.controller.ts"
click node_auth_service "https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/auth/auth.service.ts"
click node_otp_service "https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/otp.service.ts"
click node_mail_service "https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/mail.service.ts"
click node_user_model "https://github.com/rahulc34/online-compiler-backend/blob/main/src/models/user.model.ts"
click node_otp_model "https://github.com/rahulc34/online-compiler-backend/blob/main/src/models/otp.model.ts"
click node_passport "https://github.com/rahulc34/online-compiler-backend/blob/main/src/config/passport.ts"
click node_execution_routes "https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/execution/execution.routes.ts"
click node_execution_controller "https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/execution/execution.controller.ts"
click node_execution_service "https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/execution/execution.service.ts"
click node_cancellation "https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/execution/execution-cancellation.service.ts"
click node_execution_model "https://github.com/rahulc34/online-compiler-backend/blob/main/src/models/execution.model.ts"
click node_queue "https://github.com/rahulc34/online-compiler-backend/blob/main/src/queues/execution.queue.ts"
click node_worker "https://github.com/rahulc34/online-compiler-backend/blob/main/src/workers/execution.worker.ts"
click node_cpp "https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/cpp-execution.service.ts"
click node_java "https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/java-execution.service.ts"
click node_script "https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/script-execution.service.ts"
click node_javascript "https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/javascript-execution.service.ts"
click node_python "https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/python-execution.service.ts"
click node_typescript "https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/typescript-execution.service.ts"
click node_docker "https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/docker.service.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_auth_routes,node_execution_routes,node_user toneBlue
class node_auth_controller,node_auth_service,node_otp_service,node_mail_service,node_user_model,node_otp_model,node_passport,node_mongodb,node_redis toneAmber
class node_execution_controller,node_execution_service,node_cancellation,node_execution_model,node_queue,node_worker toneMint
class node_cpp,node_java,node_script,node_javascript,node_python,node_typescript,node_docker toneRose
class node_docker_engine,node_email_provider toneIndigo
```

## Components

### API and access

- [HTTP application](https://github.com/rahulc34/online-compiler-backend/blob/main/src/app.ts): `src/app.ts`
- [Auth routes](https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/auth/auth.routes.ts): `src/modules/auth/auth.routes.ts`
- [Execution routes](https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/execution/execution.routes.ts): `src/modules/execution/execution.routes.ts`

### Identity

- [Auth controller](https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/auth/auth.controller.ts): `src/modules/auth/auth.controller.ts`
- [Auth service](https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/auth/auth.service.ts): `src/modules/auth/auth.service.ts`
- [Email OTP](https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/otp.service.ts): `src/services/otp.service.ts`
- [Mail delivery](https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/mail.service.ts): `src/services/mail.service.ts`
- [User records](https://github.com/rahulc34/online-compiler-backend/blob/main/src/models/user.model.ts): `src/models/user.model.ts`
- [OTP records](https://github.com/rahulc34/online-compiler-backend/blob/main/src/models/otp.model.ts): `src/models/otp.model.ts`
- [Google authentication](https://github.com/rahulc34/online-compiler-backend/blob/main/src/config/passport.ts): `src/config/passport.ts`

### Execution

- [Execution controller](https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/execution/execution.controller.ts): `src/modules/execution/execution.controller.ts`
- [Execution service](https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/execution/execution.service.ts): `src/modules/execution/execution.service.ts`
- [Cancellation service](https://github.com/rahulc34/online-compiler-backend/blob/main/src/modules/execution/execution-cancellation.service.ts): `src/modules/execution/execution-cancellation.service.ts`
- [Execution records](https://github.com/rahulc34/online-compiler-backend/blob/main/src/models/execution.model.ts): `src/models/execution.model.ts`
- [Job queue](https://github.com/rahulc34/online-compiler-backend/blob/main/src/queues/execution.queue.ts): `src/queues/execution.queue.ts`
- [Execution worker](https://github.com/rahulc34/online-compiler-backend/blob/main/src/workers/execution.worker.ts): `src/workers/execution.worker.ts`

### Language runtime

- [C++ runner](https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/cpp-execution.service.ts): `src/services/cpp-execution.service.ts`
- [Java runner](https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/java-execution.service.ts): `src/services/java-execution.service.ts`
- [Script runner](https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/script-execution.service.ts): `src/services/script-execution.service.ts`
- [JavaScript runner](https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/javascript-execution.service.ts): `src/services/javascript-execution.service.ts`
- [Python runner](https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/python-execution.service.ts): `src/services/python-execution.service.ts`
- [TypeScript runner](https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/typescript-execution.service.ts): `src/services/typescript-execution.service.ts`
- [Docker sandbox](https://github.com/rahulc34/online-compiler-backend/blob/main/src/services/docker.service.ts): `src/services/docker.service.ts`

### Other components

- **Client user**
- **Docker Engine**
- **MongoDB**
- **Redis**
- **SMTP provider**

## Connections

- Client user → HTTP application: calls API (evidence: `src/app.ts`)
- HTTP application → Auth routes: mounts routes (evidence: `src/app.ts`)
- HTTP application → Execution routes: mounts routes (evidence: `src/app.ts`)
- Auth routes → Auth controller: routes requests (evidence: `src/modules/auth/auth.routes.ts`)
- Auth controller → Auth service: delegates auth (evidence: `src/modules/auth/auth.controller.ts`)
- Auth service → User records: reads and writes (evidence: `src/modules/auth/auth.service.ts`)
- Auth controller → Email OTP: verifies OTP (evidence: `src/modules/auth/auth.controller.ts`)
- Auth service → Email OTP: creates OTP (evidence: `src/modules/auth/auth.service.ts`)
- Email OTP → OTP records: stores OTP (evidence: `src/services/otp.service.ts`)
- Email OTP → User records: updates user (evidence: `src/services/otp.service.ts`)
- Auth service → Mail delivery: sends reset mail (evidence: `src/modules/auth/auth.service.ts`)
- Auth controller → Google authentication: authenticates Google (evidence: `src/modules/auth/auth.controller.ts`)
- Execution routes → Execution controller: routes requests (evidence: `src/modules/execution/execution.routes.ts`)
- Execution controller → Execution service: creates job (evidence: `src/modules/execution/execution.controller.ts`)
- Execution controller → Execution records: reads result (evidence: `src/modules/execution/execution.controller.ts`)
- Execution service → Execution records: creates record (evidence: `src/modules/execution/execution.service.ts`)
- Execution service → Job queue: enqueues job (evidence: `src/modules/execution/execution.service.ts`)
- Cancellation service → Execution records: updates status (evidence: `src/modules/execution/execution-cancellation.service.ts`)
- Cancellation service → Job queue: removes job (evidence: `src/modules/execution/execution-cancellation.service.ts`)
- Cancellation service → Redis: uses Redis (evidence: `src/modules/execution/execution-cancellation.service.ts`)
- Execution worker → Job queue: consumes jobs (evidence: `src/workers/execution.worker.ts`)
- Execution worker → Execution records: claims and updates (evidence: `src/workers/execution.worker.ts`)
- Execution worker → C++ runner: dispatches C++ (evidence: `src/workers/execution.worker.ts`)
- Execution worker → Java runner: dispatches Java (evidence: `src/workers/execution.worker.ts`)
- Execution worker → JavaScript runner: dispatches JavaScript (evidence: `src/workers/execution.worker.ts`)
- Execution worker → Python runner: dispatches Python (evidence: `src/workers/execution.worker.ts`)
- Execution worker → TypeScript runner: dispatches TypeScript (evidence: `src/workers/execution.worker.ts`)
- C++ runner → Docker sandbox: runs in sandbox (evidence: `src/services/cpp-execution.service.ts`)
- Java runner → Docker sandbox: runs in sandbox (evidence: `src/services/java-execution.service.ts`)
- Script runner → Docker sandbox: runs in sandbox (evidence: `src/services/script-execution.service.ts`)
- Docker sandbox → Docker Engine: controls containers (evidence: `src/services/docker.service.ts`)
- Docker sandbox → MongoDB: execution persistence
- Docker sandbox → Redis: queue infrastructure
- Mail delivery → SMTP provider: sends email
- User records → MongoDB: persists users
- Execution records → MongoDB: persists executions
