# charanpawarr09-sudo/foxcode architecture

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

- Interactive diagram: https://gitdiagram.com/charanpawarr09-sudo/foxcode
- Repository: https://github.com/charanpawarr09-sudo/foxcode

## Overview

1. **Overall shape**
   - This is a TypeScript monorepo for the FORGE learning platform.
   - Runtime is split into four main apps: **web** (React/Vite UI), **api** (Hono REST + WebSocket backend), **workers** (BullMQ background jobs), and a **deprecated Python ADCA** service that is no longer part of the live architecture.

2. **Frontend boundary: `apps/web`**
   - The web app is a client-side React 19 application built with Vite and React Router.
   - It owns all learner-facing pages: landing, auth, courses/lessons, workshop, scenario/challenge flows, interview forge, leaderboard, pricing, and legal pages.
   - It consumes the API through `apps/web/src/lib/api.ts`, `useApi`, `useWebSocket`, and query hooks, and persists some local UI state in stores like `editor-store.ts`.

3. **Backend boundary: `apps/api`**
   - The API is the core application server and exposes the system’s main domain endpoints.
   - Routes are organized by capability rather than by UI screen: assess, billing, blueprints, browse, calibration, courses, employer, evidence, gamification, interview-forge, learners, lessons, recommendations, scenarios, search, storage, and WebSocket execution.
   - Cross-cutting middleware enforces auth, request IDs, rate limits, body limits, security headers, submission guards, and tier-based permissions.

4. **Domain services inside the API**
   - Business logic is concentrated in `apps/api/src/services`, including scoring, interview evaluation, evidence processing, graduation, workshop readiness, and workshop profile updates.
   - The adaptive calibration system is inline in the API: `scoring.ts` and `adca-client.ts` replace the old external Python ADCA service.
   - Execution-related logic also lives here, with an `e2b-executor` integration and a `ws-execute` route for real-time code execution sessions.

5. **Async processing boundary: `apps/workers`**
   - Background and scheduled work is separated from request/response traffic in the workers app.
   - Worker jobs include leaderboard resets, daily challenge rotation, subscription expiry handling, decay, achievement checks, evidence processing, blueprint evaluation, email delivery, and scenario narrative generation.
   - This is the platform’s eventual-consistency layer for anything that should not block user interactions.

6. **Data layer: `packages/db`**
   - Persistence is centralized in Prisma, with schema, migrations, seeds, and the shared client in `packages/db`.
   - The database is the source of truth for learners, scenarios, lesson progress, assessments, evidence, leaderboard state, subscriptions, and calibration-related records.
   - Seeding is content-heavy: blueprints, scenarios, courses, lesson content, and challenge data are loaded from Prisma seed scripts.

7. **Shared contracts and logic: `packages/shared` and `packages/validation`**
   - `packages/shared` holds cross-app enums, constants, utilities, and TypeScript data shapes for API, billing, learner, scenario, execution, websocket, and evidence domains.
   - `packages/validation` contains schema-level validation for common domain objects.
   - These packages define the shared boundary between web, API, workers, and the database-backed domain model.

8. **UI system: `packages/ui`**
   - The shared UI library provides reusable React components and design-system primitives used by the web app.
   - It also contains higher-level FORGE-specific widgets such as arena cards, reasoning maps, spark cards, leaderboard rows, XP/streak components, and execution output panels.
   - This package is the presentation layer boundary that keeps page implementations thin.

9. **Content and curriculum model**
   - Static content lives in `content/` and is mirrored by the richer seed system under `packages/db/prisma/seeds`.
   - The platform’s educational model is organized around blueprints, scenarios, lessons, challenges, and language tracks, which are then surfaced through the API and rendered in the web app.
   - The content system is not just documentation; it is operational input for runtime experiences and database seeding.

10. **Infrastructure and external services**
   - Local development depends on PostgreSQL, Redis, and MailHog via Docker Compose.
   - Redis is required for queues and worker coordination; PostgreSQL backs Prisma persistence; MailHog supports email testing; Cloudflare R2 is implied by the API storage client.
   - CI/CD and quality gates are explicit: GitHub Actions cover CI, security, accessibility, Lighthouse, staging, and preview deployments, with separate deployment configs for Railway and Vercel.

11. **Request and event flows**
   - User traffic starts in the web app, which calls the API for domain data and uses WebSockets for live execution or interactive sessions.
   - The API validates, authorizes, scores, and persists state, then emits work to queues when the action should be handled asynchronously.
   - Workers consume those jobs, update the database, and trigger side effects such as emails, leaderboard refreshes, or challenge rotations.

12. **Important architectural note**
   - The repository includes a deprecated Python service under `apps/adca`, but the authoritative production path is now the TypeScript API and workers.
   - For an architecture diagram, the critical runtime boxes are: **Web App**, **API Server**, **Workers**, **PostgreSQL**, **Redis**, and optional external storage/email/analytics services.

Main entry points: [`apps/api`](https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/api) (API Server), [`apps/web`](https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/web) (Web App), [`apps/workers`](https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/workers) (Workers), [`apps/api/src/services`](https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/api/src/services) (Domain services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Apps"]
  node_web["Web App<br/>React/Vite client"]
  node_web_api["API client<br/>HTTP/WebSocket client<br/>[api.ts]"]
  node_web_state["UI state<br/>client store<br/>[editor-store.ts]"]
  node_api["API Server<br/>Hono backend"]
  node_api_routes["Domain routes<br/>route layer"]
  node_api_mw["Middleware<br/>cross-cutting"]
  node_api_services["Domain services<br/>business logic"]
  node_api_exec["Execution<br/>runtime integration<br/>[e2b-executor.ts]"]
  node_workers["Workers<br/>BullMQ background jobs"]
  node_adca["ADCA<br/>deprecated Python service"]
end

subgraph group_packages["Shared Packages"]
  node_db[("Database<br/>Prisma/PostgreSQL")]
  node_shared["Shared Model<br/>shared contracts"]
  node_validation["Validation"]
  node_ui["UI Kit<br/>design system"]
end

subgraph group_infra["Infra"]
  node_external(("External services<br/>runtime deps"))
  node_ci["CI/CD<br/>automation<br/>[workflows]"]
end

node_content["Content<br/>curriculum assets"]

node_web -->|"calls"| node_web_api
node_web -->|"persists"| node_web_state
node_web -->|"renders with"| node_ui
node_api -->|"exposes"| node_api_routes
node_api -->|"protects with"| node_api_mw
node_api -->|"delegates to"| node_api_services
node_api -->|"executes via"| node_api_exec
node_api -->|"reads/writes"| node_db
node_api -->|"uses"| node_shared
node_api -->|"validates with"| node_validation
node_workers -->|"updates"| node_db
node_workers -->|"uses"| node_shared
node_workers -->|"uses"| node_external
node_api_services -->|"reads/writes"| node_db
node_api_services -->|"uses"| node_shared
node_api_services -.->|"replaces"| node_adca
node_content -->|"seeds"| node_db
node_content -->|"drives"| node_web
node_ci -->|"builds"| node_web
node_ci -->|"builds"| node_api
node_ci -->|"builds"| node_workers
node_external -->|"supports"| node_api
node_external -->|"supports"| node_workers

click node_web "https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/web"
click node_web_api "https://github.com/charanpawarr09-sudo/foxcode/blob/main/apps/web/src/lib/api.ts"
click node_web_state "https://github.com/charanpawarr09-sudo/foxcode/blob/main/apps/web/src/stores/editor-store.ts"
click node_api "https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/api"
click node_api_routes "https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/api/src/routes"
click node_api_mw "https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/api/src/middleware"
click node_api_services "https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/api/src/services"
click node_api_exec "https://github.com/charanpawarr09-sudo/foxcode/blob/main/apps/api/src/services/e2b-executor.ts"
click node_workers "https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/workers"
click node_db "https://github.com/charanpawarr09-sudo/foxcode/tree/main/packages/db"
click node_shared "https://github.com/charanpawarr09-sudo/foxcode/tree/main/packages/shared"
click node_validation "https://github.com/charanpawarr09-sudo/foxcode/tree/main/packages/validation"
click node_ui "https://github.com/charanpawarr09-sudo/foxcode/tree/main/packages/ui"
click node_content "https://github.com/charanpawarr09-sudo/foxcode/tree/main/content"
click node_adca "https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/adca"
click node_ci "https://github.com/charanpawarr09-sudo/foxcode/blob/main/.github/workflows"

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,node_web_api,node_web_state,node_api,node_api_routes,node_api_mw,node_api_services,node_api_exec,node_workers,node_adca toneBlue
class node_db,node_shared,node_validation,node_ui toneAmber
class node_external,node_ci toneMint
class node_content toneNeutral
```

## Components

### Apps

Runtime applications and services

- [Web App](https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/web): React/Vite client · Learner-facing SPA with routes for landing, auth, courses, workshop, scenarios, interview forge, leaderboard, and legal pages. · `apps/web`
- [API client](https://github.com/charanpawarr09-sudo/foxcode/blob/main/apps/web/src/lib/api.ts): HTTP/WebSocket client · Typed API access, hooks, and websocket integration used by the web app. · `apps/web/src/lib/api.ts`
- [UI state](https://github.com/charanpawarr09-sudo/foxcode/blob/main/apps/web/src/stores/editor-store.ts): client store · Local editor and interface state persisted in browser stores. · `apps/web/src/stores/editor-store.ts`
- [API Server](https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/api): Hono backend · Core application server exposing domain routes, validation, auth, middleware, and websocket execution. · `apps/api`
- [Domain routes](https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/api/src/routes): route layer · Capability-based endpoints for assess, billing, blueprints, browse, calibration, courses, employer, evidence, gamification, interview-forge, learners, lessons, recommendations, scenarios, search, storage, and ws-execute. · `apps/api/src/routes`
- [Middleware](https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/api/src/middleware): cross-cutting · Auth, request IDs, rate limits, body limits, security headers, submission guards, and tier permissions. · `apps/api/src/middleware`
- [Domain services](https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/api/src/services): business logic · Scoring, interview evaluation, evidence processing, graduation, workshop readiness, and workshop profile updates. · `apps/api/src/services`
- [Execution](https://github.com/charanpawarr09-sudo/foxcode/blob/main/apps/api/src/services/e2b-executor.ts): runtime integration · WebSocket execution and e2b-backed code execution integration for interactive sessions. · `apps/api/src/services/e2b-executor.ts`
- [Workers](https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/workers): BullMQ background jobs · Async processing for leaderboards, challenge rotation, subscriptions, decay, achievements, evidence, blueprint evaluation, email, and narratives. · `apps/workers`
- [ADCA](https://github.com/charanpawarr09-sudo/foxcode/tree/main/apps/adca): deprecated Python service · Legacy adaptive calibration service kept in the repo but no longer part of the live production path. · `apps/adca`

### Shared Packages

Cross-app libraries and domain packages

- [Database](https://github.com/charanpawarr09-sudo/foxcode/tree/main/packages/db): Prisma/PostgreSQL · Shared persistence layer and source of truth for learners, scenarios, progress, assessments, evidence, subscriptions, and calibration records. · `packages/db`
- [Shared Model](https://github.com/charanpawarr09-sudo/foxcode/tree/main/packages/shared): shared contracts · Cross-app enums, constants, utilities, and TypeScript data shapes for API, billing, learner, scenario, execution, websocket, and evidence domains. · `packages/shared`
- [Validation](https://github.com/charanpawarr09-sudo/foxcode/tree/main/packages/validation): schema validation · Shared validation schemas for common domain objects. · `packages/validation`
- [UI Kit](https://github.com/charanpawarr09-sudo/foxcode/tree/main/packages/ui): design system · Reusable React components and FORGE-specific presentation widgets used by the web app. · `packages/ui`

### Infra

Deployment and local runtime dependencies

- **External services**: runtime deps · PostgreSQL, Redis, MailHog, R2-like storage, and deployment targets supporting the platform.
- [CI/CD](https://github.com/charanpawarr09-sudo/foxcode/blob/main/.github/workflows): automation · GitHub Actions and deployment configs for CI, security, accessibility, Lighthouse, staging, preview, Railway, and Vercel. · `.github/workflows`

### Other components

- [Content](https://github.com/charanpawarr09-sudo/foxcode/tree/main/content): curriculum assets · Blueprints, scenarios, templates, and other operational content consumed by seeding and runtime experiences. · `content`

## Connections

- Web App → API client: calls · Web UI fetches domain data and opens realtime sessions.
- Web App → UI state: persists · Client-side UI state and editor state remain local.
- Web App → UI Kit: renders with · Page implementations use shared UI primitives and widgets.
- API Server → Domain routes: exposes · Server mounts capability-based REST and websocket routes.
- API Server → Middleware: protects with · Requests pass through authentication, limits, and security middleware.
- API Server → Domain services: delegates to · Routes hand off core business logic to services.
- API Server → Execution: executes via · Interactive coding sessions use websocket and executor integration.
- API Server → Database: reads/writes · Server persists and queries primary application state.
- API Server → Shared Model: uses · API contracts and domain types are shared across runtimes.
- API Server → Validation: validates with · Domain payloads use shared schema validation.
- Workers → Database: updates · Jobs apply eventual-consistency changes in the database.
- Workers → Shared Model: uses · Jobs share domain enums, limits, and data shapes.
- Workers → External services: uses · Queues, email delivery, and other side effects rely on external services.
- Domain services → Database: reads/writes · Scoring, evidence, and readiness logic operate on persisted records.
- Domain services → Shared Model: uses · Business rules depend on shared constants and utilities.
- Domain services → ADCA: replaces · Inline calibration logic supersedes the deprecated Python service.
- Content → Database: seeds · Static curriculum content is loaded into Prisma seed data.
- Content → Web App: drives · Content shapes user-facing learning experiences.
- CI/CD → Web App: builds · Preview and production pipelines cover the frontend.
- CI/CD → API Server: builds · CI and deployment workflows package the backend.
- CI/CD → Workers: builds · Worker deployment is covered by automation.
- External services → API Server: supports · Storage, email, Redis, and Postgres back the live system.
- External services → Workers: supports · Workers depend on queues, mail, and datastore infrastructure.
