# akshatg-coder/codepro architecture

> Architecture diagram of the GitHub repository akshatg-coder/codepro, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/akshatg-coder/codepro
- Repository: https://github.com/akshatg-coder/codepro

## Overview

#### Purpose and topology
Code Pro is a competitive-programming platform monorepo. It combines a Next.js user-facing application, a separate TypeScript API service, shared Prisma data modeling, and Judge0-backed code execution. Turborepo/npm workspaces coordinate packages; Docker Compose supplies local and production-adjacent infrastructure.

Key roots: `apps/web`, `apps/api`, `packages/db`, `docker-compose.yml`.

#### User application and primary entry points
The web application is a Next.js App Router service. Its application shell and public page entry points begin at `apps/web/src/app/layout.tsx` and `apps/web/src/app/page.tsx`. Route segments implement contest browsing/problem solving, practice, authentication, contribution, and leaderboard views.

Interactive coding is centered on `apps/web/src/components/ProblemIDE.tsx`, rendered from problem routes such as `apps/web/src/app/contest/[id]/problem/[problemId]/page.tsx` and `apps/web/src/app/practice/[slug]/page.tsx`.

#### Backend API boundary
A standalone API service exposes domain endpoints for auth, contests, problems, submissions, and leaderboards. Bootstrap/control flow starts in `apps/api/src/index.ts` and `apps/api/src/app.ts`; route composition is in `apps/api/src/routes/index.ts`.

Controllers isolate domain operations behind HTTP routes: `apps/api/src/controllers/submissions.controller.ts`, `apps/api/src/controllers/contests.controller.ts`, and `apps/api/src/controllers/leaderboard.controller.ts`. Auth, validation, and error normalization are cross-cutting middleware at `apps/api/src/middleware/auth.ts`, `apps/api/src/middleware/validate.ts`, and `apps/api/src/middleware/errorHandler.ts`.

#### Authentication and identity
The web tier owns NextAuth integration and registration endpoints at `apps/web/src/app/api/auth/[...nextauth]/route.ts` and `apps/web/src/app/api/auth/register/route.ts`, with auth configuration in `apps/web/src/lib/auth.ts`. The API separately protects backend operations through `apps/api/src/middleware/auth.ts` and its auth controller/routes.

Google OAuth is an explicitly required external identity dependency. This split means browser-facing auth handling and API authorization are important integration boundaries.

#### Submission and judging flow
A user submits source through the Next.js submission API surface, notably `apps/web/src/app/api/submission/route.ts`. Submission status and streaming endpoints support asynchronous execution updates: `apps/web/src/app/api/submission/[id]/status/route.ts` and `apps/web/src/app/api/submission/[id]/stream/route.ts`.

The backend submission domain delegates execution to Judge0 through `apps/api/src/lib/judge0.ts` and `apps/api/src/controllers/submissions.controller.ts`. Judge0 callbacks enter via `apps/web/src/app/api/webhook/judge0/route.ts`, completing the external asynchronous boundary. Judge0 language IDs are configured operationally for C++, JavaScript, and Rust.

#### Contest scoring and real-time reads
Contest state is managed through API routes/controllers (`apps/api/src/routes/contests.routes.ts`, `apps/api/src/controllers/contests.controller.ts`). Leaderboard reads are exposed in both the API and web layers, with a server-streaming web endpoint at `apps/web/src/app/api/leaderboard/[contestId]/stream/route.ts` and live UI at `apps/web/src/components/LiveLeaderboard.tsx`.

This creates a flow from judged submissions to persisted results, then leaderboard query/stream delivery to contest pages.

#### Persistence, infrastructure, and deployment
Prisma defines the shared relational model at `packages/db/prisma/schema.prisma`; seed data is loaded via `packages/db/src/seed/index.ts`. Both services have Prisma integration points: `apps/api/src/lib/prisma.ts` and `apps/web/src/lib/prisma.ts`.

PostgreSQL is the system of record. Judge0 CE executes untrusted code and relies on Redis as part of its Compose-based stack (`docker-compose.yml`, `judge0.conf`). Container deployment exists for both application services (`apps/web/Dockerfile`, `apps/api/Dockerfile`), with Caddy reverse-proxy configuration at `proxy/Caddyfile`.

Main entry points: [`apps/api/src/routes/index.ts`](https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/routes/index.ts) (Route composition), [`docker-compose.yml`](https://github.com/akshatg-coder/codepro/blob/main/docker-compose.yml) (PostgreSQL), [`apps/api/src/controllers/submissions.controller.ts`](https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/controllers/submissions.controller.ts) (Submission domain), [`apps/api/src/controllers/leaderboard.controller.ts`](https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/controllers/leaderboard.controller.ts) (Leaderboard domain)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Next.js web"]
  node_web_shell["App shell and pages<br/>Next.js App Router<br/>[layout.tsx]"]
  node_problem_ide["Problem IDE<br/>coding UI<br/>[ProblemIDE.tsx]"]
  node_submission_api["Submission API<br/>Next.js route<br/>[route.ts]"]
  node_judge_callback["Judge0 webhook<br/>Next.js route<br/>[route.ts]"]
  node_live_leaderboard["Live leaderboard<br/>UI and SSE route"]
  node_nextauth["Browser auth<br/>NextAuth routes<br/>[route.ts]"]
end

subgraph group_api["API service"]
  node_api_bootstrap["API bootstrap<br/>TypeScript service<br/>[index.ts]"]
  node_api_routes["Route composition<br/>HTTP routes<br/>[index.ts]"]
  node_api_middleware["Auth, validation, errors<br/>middleware<br/>[auth.ts]"]
  node_submission_controller["Submission domain<br/>controller"]
  node_contest_controller["Contest domain<br/>controller"]
  node_leaderboard_controller["Leaderboard domain<br/>controller"]
  node_judge0_client["Judge0 client<br/>execution adapter<br/>[judge0.ts]"]
end

subgraph group_data["Data and execution"]
  node_prisma_model["Prisma schema<br/>shared data model<br/>[schema.prisma]"]
  node_postgres[("PostgreSQL<br/>system of record<br/>[docker-compose.yml]")]
  node_judge0{{"Judge0 CE<br/>code execution<br/>[docker-compose.yml]"}}
  node_redis[("Redis<br/>Judge0 dependency<br/>[docker-compose.yml]")]
end

node_google_oauth(("Google OAuth<br/>external identity"))
node_edge_proxy["Caddy proxy<br/>reverse proxy"]

node_edge_proxy -->|"routes browser traffic"| node_web_shell
node_edge_proxy -->|"routes API traffic"| node_api_bootstrap
node_web_shell -->|"renders"| node_problem_ide
node_problem_ide -->|"submits source"| node_submission_api
node_submission_api -->|"calls submission API"| node_api_routes
node_nextauth -->|"OAuth login"| node_google_oauth
node_api_bootstrap -->|"mounts"| node_api_routes
node_api_routes -->|"applies"| node_api_middleware
node_api_routes -->|"submission endpoints"| node_submission_controller
node_api_routes -->|"contest endpoints"| node_contest_controller
node_api_routes -->|"leaderboard endpoints"| node_leaderboard_controller
node_submission_controller -->|"queues execution"| node_judge0_client
node_judge0_client -->|"Judge0 API"| node_judge0
node_judge0 -->|"uses"| node_redis
node_judge0 -->|"execution callback"| node_judge_callback
node_judge_callback -->|"persists result"| node_postgres
node_submission_controller -->|"persists submissions"| node_postgres
node_contest_controller -->|"reads and writes contests"| node_postgres
node_leaderboard_controller -->|"queries scores"| node_postgres
node_live_leaderboard -->|"live score reads"| node_leaderboard_controller
node_postgres -.->|"modeled by"| node_prisma_model

click node_web_shell "https://github.com/akshatg-coder/codepro/blob/main/apps/web/src/app/layout.tsx"
click node_problem_ide "https://github.com/akshatg-coder/codepro/blob/main/apps/web/src/components/ProblemIDE.tsx"
click node_submission_api "https://github.com/akshatg-coder/codepro/blob/main/apps/web/src/app/api/submission/route.ts"
click node_judge_callback "https://github.com/akshatg-coder/codepro/blob/main/apps/web/src/app/api/webhook/judge0/route.ts"
click node_live_leaderboard "https://github.com/akshatg-coder/codepro/blob/main/apps/web/src/components/LiveLeaderboard.tsx"
click node_nextauth "https://github.com/akshatg-coder/codepro/blob/main/apps/web/src/app/api/auth/%5B...nextauth%5D/route.ts"
click node_api_bootstrap "https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/index.ts"
click node_api_routes "https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/routes/index.ts"
click node_api_middleware "https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/middleware/auth.ts"
click node_submission_controller "https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/controllers/submissions.controller.ts"
click node_contest_controller "https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/controllers/contests.controller.ts"
click node_leaderboard_controller "https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/controllers/leaderboard.controller.ts"
click node_judge0_client "https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/lib/judge0.ts"
click node_prisma_model "https://github.com/akshatg-coder/codepro/blob/main/packages/db/prisma/schema.prisma"
click node_postgres "https://github.com/akshatg-coder/codepro/blob/main/docker-compose.yml"
click node_judge0 "https://github.com/akshatg-coder/codepro/blob/main/docker-compose.yml"
click node_redis "https://github.com/akshatg-coder/codepro/blob/main/docker-compose.yml"
click node_edge_proxy "https://github.com/akshatg-coder/codepro/blob/main/proxy/Caddyfile"

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_web_shell,node_problem_ide,node_submission_api,node_judge_callback,node_live_leaderboard,node_nextauth toneBlue
class node_api_bootstrap,node_api_routes,node_api_middleware,node_submission_controller,node_contest_controller,node_leaderboard_controller,node_judge0_client toneAmber
class node_prisma_model,node_postgres,node_judge0,node_redis toneMint
class node_google_oauth,node_edge_proxy toneNeutral
```

## Components

### Next.js web

Browser UI, auth, and streaming API surface.

- [App shell and pages](https://github.com/akshatg-coder/codepro/blob/main/apps/web/src/app/layout.tsx): Next.js App Router · `apps/web/src/app/layout.tsx`
- [Problem IDE](https://github.com/akshatg-coder/codepro/blob/main/apps/web/src/components/ProblemIDE.tsx): coding UI · `apps/web/src/components/ProblemIDE.tsx`
- [Submission API](https://github.com/akshatg-coder/codepro/blob/main/apps/web/src/app/api/submission/route.ts): Next.js route · Creates submissions and exposes status streams. · `apps/web/src/app/api/submission/route.ts`
- [Judge0 webhook](https://github.com/akshatg-coder/codepro/blob/main/apps/web/src/app/api/webhook/judge0/route.ts): Next.js route · Receives asynchronous execution results. · `apps/web/src/app/api/webhook/judge0/route.ts`
- [Live leaderboard](https://github.com/akshatg-coder/codepro/blob/main/apps/web/src/components/LiveLeaderboard.tsx): UI and SSE route · `apps/web/src/components/LiveLeaderboard.tsx`
- [Browser auth](https://github.com/akshatg-coder/codepro/blob/main/apps/web/src/app/api/auth/%5B...nextauth%5D/route.ts): NextAuth routes · Handles browser sessions and registration. · `apps/web/src/app/api/auth/[...nextauth]/route.ts`

### API service

Standalone TypeScript domain API.

- [API bootstrap](https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/index.ts): TypeScript service · `apps/api/src/index.ts`
- [Route composition](https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/routes/index.ts): HTTP routes · `apps/api/src/routes/index.ts`
- [Auth, validation, errors](https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/middleware/auth.ts): middleware · `apps/api/src/middleware/auth.ts`
- [Submission domain](https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/controllers/submissions.controller.ts): controller · `apps/api/src/controllers/submissions.controller.ts`
- [Contest domain](https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/controllers/contests.controller.ts): controller · `apps/api/src/controllers/contests.controller.ts`
- [Leaderboard domain](https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/controllers/leaderboard.controller.ts): controller · `apps/api/src/controllers/leaderboard.controller.ts`
- [Judge0 client](https://github.com/akshatg-coder/codepro/blob/main/apps/api/src/lib/judge0.ts): execution adapter · `apps/api/src/lib/judge0.ts`

### Data and execution

Shared persistence and asynchronous judging infrastructure.

- [Prisma schema](https://github.com/akshatg-coder/codepro/blob/main/packages/db/prisma/schema.prisma): shared data model · `packages/db/prisma/schema.prisma`
- [PostgreSQL](https://github.com/akshatg-coder/codepro/blob/main/docker-compose.yml): system of record · `docker-compose.yml`
- [Judge0 CE](https://github.com/akshatg-coder/codepro/blob/main/docker-compose.yml): code execution · Executes untrusted C++, JavaScript, and Rust submissions. · `docker-compose.yml`
- [Redis](https://github.com/akshatg-coder/codepro/blob/main/docker-compose.yml): Judge0 dependency · `docker-compose.yml`

### Other components

- **Google OAuth**: external identity
- [Caddy proxy](https://github.com/akshatg-coder/codepro/blob/main/proxy/Caddyfile): reverse proxy · `proxy/Caddyfile`

## Connections

- Caddy proxy → App shell and pages: routes browser traffic
- Caddy proxy → API bootstrap: routes API traffic
- App shell and pages → Problem IDE: renders
- Problem IDE → Submission API: submits source
- Submission API → Route composition: calls submission API
- Browser auth → Google OAuth: OAuth login
- API bootstrap → Route composition: mounts
- Route composition → Auth, validation, errors: applies
- Route composition → Submission domain: submission endpoints
- Route composition → Contest domain: contest endpoints
- Route composition → Leaderboard domain: leaderboard endpoints
- Submission domain → Judge0 client: queues execution
- Judge0 client → Judge0 CE: Judge0 API
- Judge0 CE → Redis: uses
- Judge0 CE → Judge0 webhook: execution callback
- Judge0 webhook → PostgreSQL: persists result
- Submission domain → PostgreSQL: persists submissions
- Contest domain → PostgreSQL: reads and writes contests
- Leaderboard domain → PostgreSQL: queries scores
- Live leaderboard → Leaderboard domain: live score reads
- PostgreSQL → Prisma schema: modeled by
