# salmonsteakk/cs5224-grp-22 architecture

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

- Interactive diagram: https://gitdiagram.com/salmonsteakk/cs5224-grp-22
- Repository: https://github.com/salmonsteakk/cs5224-grp-22

## Overview

1. **Overall shape**
   - LearnBright is split into a browser SPA, an Express API, and a DynamoDB-backed data layer.
   - The active codebase is `client/` + `server/`, with local orchestration via `docker-compose.yml`.
   - Production splits static frontend delivery from API delivery: CloudFront fronts S3 for the SPA and an ALB → ECS Fargate service for `/api/*`.

2. **Frontend boundary**
   - The client is a **React 19 + Vite** single-page app written in TypeScript.
   - `client/src/main.tsx` boots the app, and `App.tsx` wires route handling plus top-level providers.
   - Routing is page-based: home, learn, practice, dashboard, exams, auth pages, subject/topic drill-down pages, and a 404 fallback.

3. **Client-side UI composition**
   - Reusable presentation pieces live in `client/src/components/` such as navigation, subject/topic cards, quiz UI, video player, protected route wrapper, and chatbot sidebar.
   - The app uses shadcn/ui primitives for common controls and layouts, with Tailwind for styling.
   - `VideoPlayer` is a simulated lesson experience rather than a separate media service.

4. **Client state and session boundaries**
   - There are three notable client contexts: auth, chatbot, and progress.
   - `progress-context.tsx` owns learner progress behavior and persists guest progress in `localStorage`.
   - Auth state is used to gate protected pages; authenticated users can have progress mirrored to the backend, while anonymous users stay local.
   - The chatbot has its own UI/state boundary, suggesting assistant interactions are separate from the core lesson/practice flow.

5. **Learning content flow**
   - The learning path is hierarchical: subject → topic → lesson.
   - The client pages `LearnPage`, `SubjectLearnPage`, and `TopicLessonPage` navigate this hierarchy and render content from the API.
   - On the server, `learn.controller.ts` serves subject/topic content from the `Subject` model, which stores nested topics and lessons in a single item per subject.

6. **Practice and assessment flow**
   - Practice mirrors the learning hierarchy but adds quiz attempts and scoring.
   - `PracticePage`, `SubjectPracticePage`, and `TopicQuizPage` drive topic-level quizzes.
   - The server’s `practice` routes/controller return questions for a topic and likely record attempts via the attempt models.
   - Separate exam pages and hooks (`ExamPaperPage`, `useExamPaper`, `useExamAttempts`, `useExamPaperList`) indicate a second assessment track for exam papers, distinct from topic quizzes.

7. **Progress, dashboard, and recommendations**
   - The dashboard is a synthesis layer over learning and quiz history.
   - Client-side helpers such as `progress-metrics`, `dashboard-recommendations`, and `dashboard-coach-payload` compute learner KPIs and likely shape data for assistant/coaching features.
   - Server-side progress models (`UserProgressProfile`, `UserTopicProgress`, `TopicQuizAttempt`, `ExamAttempt`) separate raw attempts from aggregate user progress.
   - This is the main analytics boundary in the system: content data vs per-user progression data.

8. **API surface and server structure**
   - The Express server is organized by resource: auth, learn, practice, progress, exams, chat, and dashboard-coach routes.
   - `app.ts` assembles middleware and route registration; `index.ts` handles startup, DB initialization, and seeding.
   - Middleware includes auth protection and exam-admin gating, so not all endpoints are public.
   - Utilities for JWT and password handling indicate token-based authentication with server-side credential verification.

9. **Content and persistence model**
   - The core content catalog is seeded from `server/src/data/subjects.ts` into a DynamoDB `Subjects` table.
   - Each subject contains nested topics, lessons, and questions, which keeps learning content compact and easy to fetch by subject or topic.
   - User-related entities are modeled separately from content, which is important for diagramming the boundary between static curriculum and mutable learner state.

10. **Local development vs production**
   - Locally, `docker-compose.yml` runs three containers: client on 5173, server on 3001, and DynamoDB Local on 8000.
   - The server retries DB connection on startup, because DynamoDB Local may not be ready immediately.
   - In production, Terraform provisions the network, ECR, ECS/Fargate, ALB, S3, CloudFront, and DynamoDB, while `scripts/deploy.sh` builds/publishes the client and server artifacts.
   - The frontend and API share a single CloudFront entry point, which avoids cross-origin complexity.

11. **Legacy code boundary**
   - `v0-old/` is a previous Next.js-based implementation and appears to be archived rather than part of the active architecture.
   - For an architecture diagram, it should be treated as historical reference, not a live subsystem.

Main entry points: [`client/src/App.tsx`](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/client/src/App.tsx) (Routes), [`server/src/routes/index.ts`](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/routes/index.ts) (API routes), [`server/src/models`](https://github.com/salmonsteakk/cs5224-grp-22/tree/main/server/src/models) (Dynamo models), [`server/src/app.ts`](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/app.ts) (App setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client SPA"]
  node_client_entry(("App shell<br/>React entry<br/>[main.tsx]"))
  node_client_routes["Routes<br/>SPA router<br/>[App.tsx]"]
  node_client_pages_core["Core pages<br/>page views"]
  node_client_pages_drill["Drill pages<br/>learning flow"]
  node_client_ui["UI components<br/>presentational"]
  node_client_contexts["App contexts<br/>state providers"]
  node_client_progress_logic["Progress logic<br/>client analytics"]
  node_client_reco["Coach data<br/>recommendations"]
  node_client_exam_hooks["Exam hooks<br/>data hooks"]
  node_client_api["API client<br/>HTTP client<br/>[api.ts]"]
end

subgraph group_server["API Server"]
  node_server_entry(("Server boot<br/>Express startup<br/>[index.ts]"))
  node_server_app["App setup<br/>Express app<br/>[app.ts]"]
  node_server_routes["API routes<br/>route registry<br/>[index.ts]"]
  node_server_learn["Learn API<br/>content API"]
  node_server_practice["Practice API<br/>quiz API"]
  node_server_exams["Exams API<br/>assessment API<br/>[exam.controller.ts]"]
  node_server_progress["Progress API<br/>user analytics"]
  node_server_auth["Auth API<br/>identity<br/>[auth.controller.ts]"]
  node_server_models[("Dynamo models<br/>persistence models")]
  node_server_content["Curriculum data<br/>seed content"]
  node_server_db[("DynamoDB<br/>NoSQL store<br/>[index.ts]")]
  node_server_mw["Middleware<br/>guards"]
end

subgraph group_infra["Delivery & Infra"]
  node_infra_local["Local compose<br/>dev orchestration<br/>[docker-compose.yml]"]
  node_infra_deploy["Deploy script<br/>build/release<br/>[deploy.sh]"]
  node_infra_terraform["Terraform<br/>cloud infra"]
end

subgraph group_legacy["Legacy App"]
  node_legacy_app["Old app<br/>legacy Next.js"]
end

node_client_entry -->|"boots"| node_client_routes
node_client_routes -->|"renders"| node_client_pages_core
node_client_routes -->|"renders"| node_client_pages_drill
node_client_routes -->|"composes"| node_client_ui
node_client_routes -->|"provides"| node_client_contexts
node_client_contexts -->|"includes"| node_client_progress_logic
node_client_pages_core -->|"fetches via"| node_client_api
node_client_pages_drill -->|"fetches via"| node_client_api
node_client_exam_hooks -->|"queries"| node_client_api
node_client_reco -->|"derives from"| node_client_progress_logic
node_server_entry -->|"starts"| node_server_app
node_server_app -->|"registers"| node_server_routes
node_server_app -->|"uses"| node_server_mw
node_server_routes -->|"maps"| node_server_auth
node_server_routes -->|"maps"| node_server_learn
node_server_routes -->|"maps"| node_server_practice
node_server_routes -->|"maps"| node_server_exams
node_server_routes -->|"maps"| node_server_progress
node_server_learn -->|"reads"| node_server_models
node_server_practice -->|"reads/writes"| node_server_models
node_server_exams -->|"reads/writes"| node_server_models
node_server_progress -->|"aggregates"| node_server_models
node_server_auth -->|"uses"| node_server_models
node_server_models -->|"persists to"| node_server_db
node_server_content -->|"seeds"| node_server_db
node_infra_local -->|"runs"| node_client_entry
node_infra_local -->|"runs"| node_server_entry
node_infra_local -->|"runs"| node_server_db
node_infra_deploy -->|"packages"| node_client_routes
node_infra_deploy -->|"packages"| node_server_app
node_infra_terraform -->|"provisions"| node_server_db
node_infra_terraform -->|"provisions"| node_server_app
node_infra_terraform -->|"provisions"| node_client_routes

click node_client_entry "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/client/src/main.tsx"
click node_client_routes "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/client/src/App.tsx"
click node_client_pages_core "https://github.com/salmonsteakk/cs5224-grp-22/tree/main/client/src/pages"
click node_client_pages_drill "https://github.com/salmonsteakk/cs5224-grp-22/tree/main/client/src/pages"
click node_client_ui "https://github.com/salmonsteakk/cs5224-grp-22/tree/main/client/src/components"
click node_client_contexts "https://github.com/salmonsteakk/cs5224-grp-22/tree/main/client/src/context"
click node_client_progress_logic "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/client/src/context/progress-context.tsx"
click node_client_reco "https://github.com/salmonsteakk/cs5224-grp-22/tree/main/client/src/lib"
click node_client_exam_hooks "https://github.com/salmonsteakk/cs5224-grp-22/tree/main/client/src/hooks"
click node_client_api "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/client/src/services/api.ts"
click node_server_entry "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/index.ts"
click node_server_app "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/app.ts"
click node_server_routes "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/routes/index.ts"
click node_server_learn "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/controllers/learn.controller.ts"
click node_server_practice "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/controllers/practice.controller.ts"
click node_server_exams "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/controllers/exam.controller.ts"
click node_server_progress "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/controllers/progress.controller.ts"
click node_server_auth "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/controllers/auth.controller.ts"
click node_server_models "https://github.com/salmonsteakk/cs5224-grp-22/tree/main/server/src/models"
click node_server_content "https://github.com/salmonsteakk/cs5224-grp-22/tree/main/server/src/data"
click node_server_db "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/db/index.ts"
click node_server_mw "https://github.com/salmonsteakk/cs5224-grp-22/tree/main/server/src/middleware"
click node_infra_local "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/docker-compose.yml"
click node_infra_deploy "https://github.com/salmonsteakk/cs5224-grp-22/blob/main/scripts/deploy.sh"
click node_infra_terraform "https://github.com/salmonsteakk/cs5224-grp-22/tree/main/terraform"
click node_legacy_app "https://github.com/salmonsteakk/cs5224-grp-22/tree/main/v0-old"

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_client_entry,node_client_routes,node_client_pages_core,node_client_pages_drill,node_client_ui,node_client_contexts,node_client_progress_logic,node_client_reco,node_client_exam_hooks,node_client_api toneBlue
class node_server_entry,node_server_app,node_server_routes,node_server_learn,node_server_practice,node_server_exams,node_server_progress,node_server_auth,node_server_models,node_server_content,node_server_db,node_server_mw toneAmber
class node_infra_local,node_infra_deploy,node_infra_terraform toneMint
class node_legacy_app toneRose
```

## Components

### Client SPA

React single-page app and its UI/state layers.

- [App shell](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/client/src/main.tsx): React entry · Bootstraps the SPA and top-level app wiring. · `client/src/main.tsx`
- [Routes](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/client/src/App.tsx): SPA router · Top-level page routing and providers for the client app. · `client/src/App.tsx`
- [Core pages](https://github.com/salmonsteakk/cs5224-grp-22/tree/main/client/src/pages): page views · Home, learn, practice, dashboard, exams, auth, and fallback screens. · `client/src/pages`
- [Drill pages](https://github.com/salmonsteakk/cs5224-grp-22/tree/main/client/src/pages): learning flow · Subject and topic pages for lesson and quiz drill-down. · `client/src/pages`
- [UI components](https://github.com/salmonsteakk/cs5224-grp-22/tree/main/client/src/components): presentational · Navigation, cards, quiz UI, video player, protected route, and chatbot sidebar. · `client/src/components`
- [App contexts](https://github.com/salmonsteakk/cs5224-grp-22/tree/main/client/src/context): state providers · Auth, chatbot, and progress context boundaries. · `client/src/context`
- [Progress logic](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/client/src/context/progress-context.tsx): client analytics · Learner progress metrics and local guest progress persistence. · `client/src/context/progress-context.tsx`
- [Coach data](https://github.com/salmonsteakk/cs5224-grp-22/tree/main/client/src/lib): recommendations · Dashboard recommendation and coach-payload shaping helpers. · `client/src/lib`
- [Exam hooks](https://github.com/salmonsteakk/cs5224-grp-22/tree/main/client/src/hooks): data hooks · Client hooks for exam paper lists, paper detail, and attempts. · `client/src/hooks`
- [API client](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/client/src/services/api.ts): HTTP client · Shared client-side API access layer. · `client/src/services/api.ts`

### API Server

Express API, domain controllers, and persistence models.

- [Server boot](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/index.ts): Express startup · Starts the API, initializes DB access, and runs seeding. · `server/src/index.ts`
- [App setup](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/app.ts): Express app · Assembles middleware and registers routes. · `server/src/app.ts`
- [API routes](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/routes/index.ts): route registry · Central route composition for auth, learn, practice, progress, exams, chat, and coaching. · `server/src/routes/index.ts`
- [Learn API](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/controllers/learn.controller.ts): content API · Serves subject/topic/lesson content from the curriculum model. · `server/src/controllers/learn.controller.ts`
- [Practice API](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/controllers/practice.controller.ts): quiz API · Serves topic practice questions and related attempt flow. · `server/src/controllers/practice.controller.ts`
- [Exams API](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/controllers/exam.controller.ts): assessment API · Handles exam paper access and attempt tracking. · `server/src/controllers/exam.controller.ts`
- [Progress API](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/controllers/progress.controller.ts): user analytics · Exposes user progress and dashboard-facing progress data. · `server/src/controllers/progress.controller.ts`
- [Auth API](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/controllers/auth.controller.ts): identity · Login/signup and session credential handling. · `server/src/controllers/auth.controller.ts`
- [Dynamo models](https://github.com/salmonsteakk/cs5224-grp-22/tree/main/server/src/models): persistence models · Subjects, users, progress profiles, topic quiz attempts, and exam attempts. · `server/src/models`
- [Curriculum data](https://github.com/salmonsteakk/cs5224-grp-22/tree/main/server/src/data): seed content · Seed data for subjects, nested topics, lessons, questions, and exam papers. · `server/src/data`
- [DynamoDB](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/server/src/db/index.ts): NoSQL store · Persistent store for curriculum and learner state. · `server/src/db/index.ts`
- [Middleware](https://github.com/salmonsteakk/cs5224-grp-22/tree/main/server/src/middleware): guards · Auth protection and exam-admin gating. · `server/src/middleware`

### Delivery & Infra

Local orchestration and production deployment infrastructure.

- [Local compose](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/docker-compose.yml): dev orchestration · Runs client, server, and DynamoDB Local together. · `docker-compose.yml`
- [Deploy script](https://github.com/salmonsteakk/cs5224-grp-22/blob/main/scripts/deploy.sh): build/release · Builds and publishes client and server artifacts. · `scripts/deploy.sh`
- [Terraform](https://github.com/salmonsteakk/cs5224-grp-22/tree/main/terraform): cloud infra · Defines network, ECR, ECS/Fargate, ALB, CloudFront, S3, and DynamoDB infrastructure. · `terraform`

### Legacy App

Archived prior implementation kept as historical reference.

- [Old app](https://github.com/salmonsteakk/cs5224-grp-22/tree/main/v0-old): legacy Next.js · Archived prior implementation, not part of the active architecture. · `v0-old`

## Connections

- App shell → Routes: boots · Entry initializes the app shell and hands off to routing.
- Routes → Core pages: renders · Routing selects the main page-level screens.
- Routes → Drill pages: renders · Routing drives subject/topic drill-down pages.
- Routes → UI components: composes · Pages are built from reusable UI components.
- Routes → App contexts: provides · Top-level providers supply shared auth, chatbot, and progress state.
- App contexts → Progress logic: includes · Progress context owns metrics and guest persistence behavior.
- Core pages → API client: fetches via · Core pages retrieve data from the API client.
- Drill pages → API client: fetches via · Learning drill-down pages load subject/topic/lesson and quiz data.
- Exam hooks → API client: queries · Hooks centralize exam-related API reads and attempt state.
- Coach data → Progress logic: derives from · Recommendations and coach payloads are shaped from progress data.
- Server boot → App setup: starts · Startup delegates to the Express application assembly.
- App setup → API routes: registers · App setup mounts the route tree.
- App setup → Middleware: uses · Middleware applies protection and admin gating.
- API routes → Auth API: maps · Route registry exposes auth endpoints.
- API routes → Learn API: maps · Route registry exposes learn endpoints.
- API routes → Practice API: maps · Route registry exposes practice endpoints.
- API routes → Exams API: maps · Route registry exposes exam endpoints.
- API routes → Progress API: maps · Route registry exposes progress endpoints.
- Learn API → Dynamo models: reads · Learning endpoints use the subject/content model.
- Practice API → Dynamo models: reads/writes · Practice endpoints work with topic quizzes and attempts.
- Exams API → Dynamo models: reads/writes · Exam endpoints access exam papers and attempts.
- Progress API → Dynamo models: aggregates · Progress endpoints aggregate user progress state from attempts and profiles.
- Auth API → Dynamo models: uses · Auth endpoints operate on user records.
- Dynamo models → DynamoDB: persists to · Models map application state into DynamoDB.
- Curriculum data → DynamoDB: seeds · Seed data populates the curriculum store.
- Local compose → App shell: runs · Local compose starts the client container.
- Local compose → Server boot: runs · Local compose starts the API container.
- Local compose → DynamoDB: runs · Local compose provides DynamoDB Local.
- Deploy script → Routes: packages · Deployment builds and publishes the SPA.
- Deploy script → App setup: packages · Deployment builds and publishes the API service.
- Terraform → DynamoDB: provisions · Terraform defines the managed DynamoDB table.
- Terraform → App setup: provisions · Terraform provisions ECS/Fargate delivery for the API.
- Terraform → Routes: provisions · Terraform provisions S3 and CloudFront for SPA delivery.
