# anulsasidharan/dsa_studio architecture

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

- Interactive diagram: https://gitdiagram.com/anulsasidharan/dsa_studio
- Repository: https://github.com/anulsasidharan/dsa_studio

## Overview

1. **Repo shape**
   - This is a monorepo with three main code areas: `apps/web` for the UI, `apps/api` for the backend, and `packages/shared` for common types/contracts.
   - `infra/docker` contains the runtime topology for local and containerized deployment.

2. **Frontend boundary**
   - The web app is a React + Vite + Tailwind + shadcn/ui client.
   - It is organized by user workflow pages such as dashboard, import, learning, practice, revision, topic detail, track, and assistant.
   - Zustand stores (`authStore`, `appStore`) hold client state; a thin `api-client` module is the primary boundary to the backend.

3. **Backend boundary**
   - The API is an Express + TypeScript service.
   - Routes are split by domain: auth, chat, import, progress, questions, revision, submit, topics, health, and docs.
   - Middleware centralizes auth, validation, rate limiting, not-found handling, and error handling.

4. **Core domain services**
   - Business logic is separated from routing in `apps/api/src/services`.
   - Key services include grading, progress tracking, revision generation, import processing, analytics, daily activity, and chat orchestration.
   - This is where cross-cutting learning logic lives, rather than in the route handlers.

5. **Data persistence**
   - PostgreSQL is the primary system of record.
   - Prisma is the database layer, with migrations and a seed script for initial question-bank data.
   - The schema appears to support users, topics, questions, submissions, progress, and chat-related tables.

6. **Shared contracts**
   - `packages/shared` defines reusable domain types, enums, entity shapes, API types, and code templates.
   - This package is a compile-time contract between web and API, reducing drift in request/response structures and shared learning-domain models.

7. **AI/chat subsystem**
   - The assistant feature is backed by an LLM abstraction layer with provider implementations for OpenAI, Anthropic, and a mock provider.
   - Chat-specific services include context building, import classification, learning-path generation, and the main chat service.
   - The chat flow likely combines user history, topic theory, and progress data to produce educational responses and recommendations.

8. **Sandboxed execution**
   - The API includes a sandbox subsystem with an executor, and Docker images for Node and Python sandbox runtimes.
   - This strongly suggests isolated code execution for programming exercises or answer checking, keeping untrusted execution out of the main API process.

9. **Learning workflow**
   - The main data flow is: imported or seeded content becomes topics/questions, users practice or submit answers, the API grades and records results, and progress/revision views are updated from that state.
   - The import route/service is the ingestion entrypoint; submit/grading/progress/revision form the feedback loop that drives the learning experience.

10. **Authentication and user state**
   - Auth is JWT-based with password utilities, and the API exposes an auth route plus auth middleware.
   - The web app has an auth dialog and auth store, so login state is managed client-side but enforced server-side.

11. **Runtime and infrastructure**
   - Docker Compose is the default full-stack deployment model: PostgreSQL, Redis, API, and web.
   - The web container serves the UI and proxies `/api` to the backend through Nginx.
   - On first startup, the API runs Prisma migrations and seeds data automatically.

12. **Operational services**
   - Redis is present as a separate infrastructure dependency and is wired into the API; the visible middleware usage indicates it supports rate limiting and other transient server-side concerns.
   - The API also exposes health and OpenAPI docs endpoints for readiness and integration visibility.

Main entry points: [`apps/api/src/services`](https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/services) (Services), [`apps/api/src/index.ts`](https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/src/index.ts) (API app), [`apps/web/src/App.tsx`](https://github.com/anulsasidharan/dsa_studio/blob/development/apps/web/src/App.tsx) (Web app), [`packages/shared/src/index.ts`](https://github.com/anulsasidharan/dsa_studio/blob/development/packages/shared/src/index.ts) (Shared contracts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Apps"]
  node_web["Web app<br/>React client<br/>[App.tsx]"]
  node_api["API app<br/>Express server<br/>[index.ts]"]
  node_web_pages["Pages<br/>workflow views"]
  node_web_state(("Client state<br/>Zustand stores"))
  node_web_api_client["API client<br/>frontend boundary<br/>[api-client.ts]"]
  node_api_routes["Routes"]
  node_api_middleware(("Middleware<br/>cross-cutting"))
  node_api_services["Services<br/>domain logic"]
  node_chat_services["Chat services<br/>assistant orchestration"]
  node_grading["Grading<br/>assessment service<br/>[grading.ts]"]
  node_progress["Progress<br/>tracking service<br/>[progress.ts]"]
  node_revision["Revision<br/>recommendation service<br/>[revision.ts]"]
  node_importing["Import<br/>ingestion service<br/>[import.ts]"]
  node_sandbox{{"Sandbox<br/>isolated execution"}}
  node_db[("Prisma DB<br/>PostgreSQL layer<br/>[schema.prisma]")]
  node_llm(("LLM layer<br/>providers"))
end

subgraph group_shared["Shared"]
  node_shared_contracts["Shared contracts<br/>shared types<br/>[index.ts]"]
end

subgraph group_infra["Infra"]
  node_docker_stack["Docker stack<br/>deployment topology<br/>[docker-compose.yml]"]
end

node_web -->|"renders"| node_web_pages
node_web -->|"uses"| node_web_state
node_web -->|"calls"| node_web_api_client
node_web_api_client -->|"typed by"| node_shared_contracts
node_api -->|"hosts"| node_api_routes
node_api -->|"wraps"| node_api_middleware
node_api_routes -->|"delegates"| node_api_services
node_api_routes -->|"shares types"| node_shared_contracts
node_api_services -->|"includes"| node_grading
node_api_services -->|"includes"| node_progress
node_api_services -->|"includes"| node_revision
node_api_services -->|"includes"| node_importing
node_api_services -->|"includes"| node_chat_services
node_chat_services -->|"uses"| node_llm
node_chat_services -->|"shares types"| node_shared_contracts
node_grading -->|"executes in"| node_sandbox
node_api -->|"persists to"| node_db
node_api -->|"depends on"| node_shared_contracts
node_web -.->|"deploys with"| node_docker_stack
node_api -.->|"deploys with"| node_docker_stack

click node_web "https://github.com/anulsasidharan/dsa_studio/blob/development/apps/web/src/App.tsx"
click node_api "https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/src/index.ts"
click node_web_pages "https://github.com/anulsasidharan/dsa_studio/tree/development/apps/web/src/pages"
click node_web_state "https://github.com/anulsasidharan/dsa_studio/tree/development/apps/web/src/store"
click node_web_api_client "https://github.com/anulsasidharan/dsa_studio/blob/development/apps/web/src/lib/api-client.ts"
click node_api_routes "https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/routes"
click node_api_middleware "https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/middleware"
click node_api_services "https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/services"
click node_chat_services "https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/services/chat"
click node_grading "https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/src/services/grading.ts"
click node_progress "https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/src/services/progress.ts"
click node_revision "https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/src/services/revision.ts"
click node_importing "https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/src/services/import.ts"
click node_sandbox "https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/sandbox"
click node_db "https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/prisma/schema.prisma"
click node_shared_contracts "https://github.com/anulsasidharan/dsa_studio/blob/development/packages/shared/src/index.ts"
click node_llm "https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/lib/llm"
click node_docker_stack "https://github.com/anulsasidharan/dsa_studio/blob/development/infra/docker/docker-compose.yml"

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_api,node_web_pages,node_web_state,node_web_api_client,node_api_routes,node_api_middleware,node_api_services,node_chat_services,node_grading,node_progress,node_revision,node_importing,node_sandbox,node_db,node_llm toneBlue
class node_shared_contracts toneAmber
class node_docker_stack toneMint
```

## Components

### Apps

Runtime applications for UI and API

- [Web app](https://github.com/anulsasidharan/dsa_studio/blob/development/apps/web/src/App.tsx): React client · Vite-based learning UI with workflow pages and client state · `apps/web/src/App.tsx`
- [API app](https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/src/index.ts): Express server · TypeScript backend exposing domain routes and middleware · `apps/api/src/index.ts`
- [Pages](https://github.com/anulsasidharan/dsa_studio/tree/development/apps/web/src/pages): workflow views · Dashboard, import, learning, practice, revision, topic detail, track, and assistant screens · `apps/web/src/pages`
- [Client state](https://github.com/anulsasidharan/dsa_studio/tree/development/apps/web/src/store): Zustand stores · Auth and app state used across the UI · `apps/web/src/store`
- [API client](https://github.com/anulsasidharan/dsa_studio/blob/development/apps/web/src/lib/api-client.ts): frontend boundary · Thin client wrapper for backend requests · `apps/web/src/lib/api-client.ts`
- [Routes](https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/routes): HTTP routes · Auth, chat, import, progress, questions, revision, submit, topics, health, and docs endpoints · `apps/api/src/routes`
- [Middleware](https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/middleware): cross-cutting · Auth, validation, rate limiting, not-found handling, and errors · `apps/api/src/middleware`
- [Services](https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/services): domain logic · Core learning logic separated from route handlers · `apps/api/src/services`
- [Chat services](https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/services/chat): assistant orchestration · Context building, import classification, learning-path generation, and chat coordination · `apps/api/src/services/chat`
- [Grading](https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/src/services/grading.ts): assessment service · Evaluates submissions and supports answer checking · `apps/api/src/services/grading.ts`
- [Progress](https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/src/services/progress.ts): tracking service · Persists and reads user learning progress · `apps/api/src/services/progress.ts`
- [Revision](https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/src/services/revision.ts): recommendation service · Generates revision content and schedules · `apps/api/src/services/revision.ts`
- [Import](https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/src/services/import.ts): ingestion service · Processes imported content into topics and questions · `apps/api/src/services/import.ts`
- [Sandbox](https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/sandbox): isolated execution · Executor for untrusted code and exercise evaluation · `apps/api/src/sandbox`
- [Prisma DB](https://github.com/anulsasidharan/dsa_studio/blob/development/apps/api/prisma/schema.prisma): PostgreSQL layer · Primary system of record with schema, migrations, and seed data · `apps/api/prisma/schema.prisma`
- [LLM layer](https://github.com/anulsasidharan/dsa_studio/tree/development/apps/api/src/lib/llm): providers · Abstraction over OpenAI, Anthropic, and mock providers · `apps/api/src/lib/llm`

### Shared

Cross-app contracts and reusable domain models

- [Shared contracts](https://github.com/anulsasidharan/dsa_studio/blob/development/packages/shared/src/index.ts): shared types · Reusable API types, entities, enums, and code templates · `packages/shared/src/index.ts`

### Infra

Container and deployment topology

- [Docker stack](https://github.com/anulsasidharan/dsa_studio/blob/development/infra/docker/docker-compose.yml): deployment topology · Compose-based runtime with API, web, PostgreSQL, Redis, and sandbox images · `infra/docker/docker-compose.yml`

## Connections

- Web app → Pages: renders · The UI is organized around workflow-specific pages
- Web app → Client state: uses · Client state is managed through local stores
- Web app → API client: calls · UI actions reach the backend through a thin API boundary
- API client → Shared contracts: typed by · Client requests and responses rely on shared contracts
- API app → Routes: hosts · The service mounts domain route modules
- API app → Middleware: wraps · Request handling is centralized through middleware
- Routes → Services: delegates · Routes keep business logic out of handlers
- Routes → Shared contracts: shares types · Route payloads align with shared domain models
- Services → Grading: includes · Submission assessment is a core learning workflow
- Services → Progress: includes · Progress tracking updates learning state
- Services → Revision: includes · Revision generation powers review flows
- Services → Import: includes · Ingestion turns imported content into domain data
- Services → Chat services: includes · Assistant orchestration sits in the service layer
- Chat services → LLM layer: uses · Chat flows are backed by provider abstractions
- Chat services → Shared contracts: shares types · Assistant and learning-path responses use shared models
- Grading → Sandbox: executes in · Untrusted code runs outside the main API process
- API app → Prisma DB: persists to · The backend stores and reads learning data from PostgreSQL via Prisma
- API app → Shared contracts: depends on · Backend and frontend share compile-time contracts
- Web app → Docker stack: deploys with · The UI is shipped as part of the compose-based stack
- API app → Docker stack: deploys with · The API runs within the containerized stack
