# sebastianbo2/testem architecture

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

- Interactive diagram: https://gitdiagram.com/sebastianbo2/testem
- Repository: https://github.com/sebastianbo2/testem

## Overview

1. **Repository shape**
   - This is a two-part application: a **React/Vite frontend** and a **Node/Express backend**.
   - The frontend is the main user-facing product; the backend acts as an orchestration layer for AI exam generation, document ingestion, and Supabase-backed data access.

2. **Frontend as the main app shell**
   - `frontend/src/main.tsx` boots a single-page app built with **React + Vite + TypeScript**.
   - Routing is organized by pages such as `Dashboard`, `DocumentManagement`, `ActiveExam`, `Results`, `History`, `Login`, `Signup`, and `Onboarding`.
   - `AuthContext` and `ProtectedRoutes` indicate that authentication gates most of the app.

3. **Domain-oriented UI structure**
   - Components are grouped by business area: `documents`, `exam`, `folders`, `history`, `onboarding`, plus shared `ui` primitives.
   - This suggests a layered UI architecture where reusable shadcn/Radix components sit underneath feature-specific components like `QuestionCard`, `FolderSidebar`, and `DocumentCard`.

4. **Primary user flow**
   - The product flow is: **authenticate → organize documents → select source material → configure an exam → take the exam → view results → revisit history**.
   - The dashboard acts as the workspace hub, while document management and exam pages handle the core learning workflow.

5. **Document management boundary**
   - The `DocumentManagement` area is centered on folder-based organization and selection of study files.
   - The presence of `requestFiles.ts`, `tmpReq.ts`, and `tmpDocument/addDocToFolder.js` suggests a document-upload and folder-assignment workflow with temporary API helpers during development or integration.
   - Supported source material is explicitly PDF/TXT from the README.

6. **Exam session boundary**
   - `useExamSession` and the `ActiveExam` page imply a client-side session model for question navigation, answer entry, and progress tracking.
   - The exam experience uses a sticky navigator/sidebar and supports multiple question types, including math/STEM rendering through `LatexRenderer`.

7. **Results and history are separate read models**
   - `Results` focuses on per-question feedback and answer comparison after submission.
   - `History` is a distinct persistence/reporting surface with sortable past attempts and summary statistics.
   - This separation suggests the app stores exam attempts and then rehydrates them for review rather than keeping everything in transient UI state.

8. **Backend AI orchestration**
   - The backend `src/backboard/*` folder is the AI pipeline: `assistant.js`, `thread.js`, `docUploader.js`, and `prompts.js`.
   - This points to a workflow where uploaded documents are sent to **Backboard.io**, then threaded prompts generate structured exam content.
   - The backend likely shapes model output into an application-friendly format before returning it to the frontend.

9. **Data and persistence**
   - `src/config/supabaseClient.js` on both frontend and backend indicates **Supabase** is the shared persistence/auth boundary.
   - Backend helpers in `src/lib/db_requests.js`, `fetchQuestions.js`, and `fetchAnswers.js` suggest database access is abstracted behind small request utilities rather than being scattered across handlers.
   - The frontend also has `src/config/supabaseClient.ts`, so some auth or user-state integration likely happens directly from the client.

10. **Mocking and local simulation**
   - `frontend/src/lib/mockApi.ts` and `mockData.ts` show the UI can run against simulated data or stubbed responses.
   - The README’s “CSV-based question parsing” and the presence of temporary request files suggest the app can simulate backend output during development or for deterministic exam rendering.

11. **Loading and state transitions**
   - Dedicated loading pages such as `ExamLoadingState`, `GradingLoading`, and `LoadingScreen` indicate the UI has explicit states for long-running generation and grading phases.
   - This is important architecturally because the AI generation step is asynchronous and likely spans document ingestion, prompt execution, and result formatting.

12. **Deployment and tooling**
   - The frontend is built with **Tailwind CSS**, **shadcn/ui**, **Lucide icons**, and likely uses **KaTeX/react-latex-next** for STEM rendering.
   - Root `vercel.json` suggests the app is deployed with Vercel, while backend/runtime dependencies are managed via npm in `backend/package.json`.
   - Overall, the repo is optimized for a modern SPA frontend plus a lightweight service backend that mediates AI and persistence.

Main entry points: [`frontend/src/components/ProtectedRoutes.tsx`](https://github.com/sebastianbo2/testem/blob/main/frontend/src/components/ProtectedRoutes.tsx) (Protected routes), [`frontend/src/pages/ActiveExam.tsx`](https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/ActiveExam.tsx) (Active exam), [`backend/src/backboard/assistant.js`](https://github.com/sebastianbo2/testem/blob/main/backend/src/backboard/assistant.js) (Backboard pipeline), [`frontend/src/pages/DocumentManagement.tsx`](https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/DocumentManagement.tsx) (Documents)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_fe_main["App shell<br/>React/Vite entry<br/>[main.tsx]"]
  node_fe_routes["Pages<br/>Route layer<br/>[App.tsx]"]
  node_fe_auth(("Auth context<br/>Session state<br/>[AuthContext.tsx]"))
  node_fe_guard{{"Protected routes<br/>Route guard"}}
  node_fe_dashboard["Dashboard<br/>Workspace page<br/>[Dashboard.tsx]"]
  node_fe_docs["Documents<br/>Doc workflow"]
  node_fe_exam["Active exam<br/>Exam session<br/>[ActiveExam.tsx]"]
  node_fe_results["Results<br/>Review page<br/>[Results.tsx]"]
  node_fe_history["History<br/>Attempts view<br/>[History.tsx]"]
  node_fe_onboard["Onboarding<br/>Intro flow<br/>[Onboarding.tsx]"]
  node_fe_examhook(("Exam session hook<br/>Client state<br/>[useExamSession.ts]"))
  node_fe_ui["UI kit<br/>Shared primitives<br/>[button.tsx]"]
  node_fe_featdocs["Doc components<br/>Feature UI<br/>[DocumentCard.tsx]"]
  node_fe_featexam["Exam components<br/>Feature UI<br/>[QuestionCard.tsx]"]
  node_fe_load["Loading states<br/>UX states<br/>[LoadingScreen.tsx]"]
  node_fe_mock(("Mock API<br/>Stub layer<br/>[mockApi.ts]"))
  node_fe_supabase[("Supabase client<br/>Client data<br/>[supabaseClient.ts]")]
end

subgraph group_backend["Backend"]
  node_be_entry["Server entry<br/>Express app<br/>[index.js]"]
  node_be_board{{"Backboard pipeline<br/>AI orchestration<br/>[assistant.js]"}}
  node_be_prompts["Prompts<br/>Prompt shaping<br/>[prompts.js]"]
  node_be_db(("DB requests<br/>Data access<br/>[db_requests.js]"))
  node_be_supabase[("Supabase client<br/>Server data<br/>[supabaseClient.js]")]
end

node_fe_main -->|"renders"| node_fe_routes
node_fe_main -->|"provides"| node_fe_auth
node_fe_routes -->|"wraps"| node_fe_guard
node_fe_guard -->|"unlocks"| node_fe_dashboard
node_fe_guard -->|"unlocks"| node_fe_docs
node_fe_guard -->|"unlocks"| node_fe_exam
node_fe_guard -->|"unlocks"| node_fe_results
node_fe_guard -->|"unlocks"| node_fe_history
node_fe_guard -->|"unlocks"| node_fe_onboard
node_fe_exam -->|"uses"| node_fe_examhook
node_fe_routes -->|"shows"| node_fe_load
node_fe_docs -->|"composes"| node_fe_featdocs
node_fe_exam -->|"composes"| node_fe_featexam
node_fe_dashboard -->|"navigates"| node_fe_docs
node_fe_dashboard -->|"starts"| node_fe_exam
node_fe_results -->|"feeds"| node_fe_history
node_fe_ui -->|"supports"| node_fe_featdocs
node_fe_ui -->|"supports"| node_fe_featexam
node_fe_mock -.->|"simulates"| node_fe_exam
node_fe_supabase -->|"shared boundary"| node_be_supabase
node_be_entry -->|"orchestrates"| node_be_board
node_be_board -->|"builds from"| node_be_prompts
node_be_entry -->|"queries"| node_be_db
node_be_db -->|"uses"| node_be_supabase
node_be_board -->|"stores"| node_be_supabase
node_be_board -->|"serves"| node_fe_docs

click node_fe_main "https://github.com/sebastianbo2/testem/blob/main/frontend/src/main.tsx"
click node_fe_routes "https://github.com/sebastianbo2/testem/blob/main/frontend/src/App.tsx"
click node_fe_auth "https://github.com/sebastianbo2/testem/blob/main/frontend/src/context/AuthContext.tsx"
click node_fe_guard "https://github.com/sebastianbo2/testem/blob/main/frontend/src/components/ProtectedRoutes.tsx"
click node_fe_dashboard "https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/Dashboard.tsx"
click node_fe_docs "https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/DocumentManagement.tsx"
click node_fe_exam "https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/ActiveExam.tsx"
click node_fe_results "https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/Results.tsx"
click node_fe_history "https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/History.tsx"
click node_fe_onboard "https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/Onboarding.tsx"
click node_fe_examhook "https://github.com/sebastianbo2/testem/blob/main/frontend/src/hooks/useExamSession.ts"
click node_fe_ui "https://github.com/sebastianbo2/testem/blob/main/frontend/src/components/ui/button.tsx"
click node_fe_featdocs "https://github.com/sebastianbo2/testem/blob/main/frontend/src/components/documents/DocumentCard.tsx"
click node_fe_featexam "https://github.com/sebastianbo2/testem/blob/main/frontend/src/components/exam/QuestionCard.tsx"
click node_fe_load "https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/loading/LoadingScreen.tsx"
click node_fe_mock "https://github.com/sebastianbo2/testem/blob/main/frontend/src/lib/mockApi.ts"
click node_fe_supabase "https://github.com/sebastianbo2/testem/blob/main/frontend/src/config/supabaseClient.ts"
click node_be_entry "https://github.com/sebastianbo2/testem/blob/main/backend/index.js"
click node_be_board "https://github.com/sebastianbo2/testem/blob/main/backend/src/backboard/assistant.js"
click node_be_prompts "https://github.com/sebastianbo2/testem/blob/main/backend/src/backboard/prompts.js"
click node_be_db "https://github.com/sebastianbo2/testem/blob/main/backend/src/lib/db_requests.js"
click node_be_supabase "https://github.com/sebastianbo2/testem/blob/main/backend/src/config/supabaseClient.js"

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_fe_main,node_fe_routes,node_fe_auth,node_fe_guard,node_fe_dashboard,node_fe_docs,node_fe_exam,node_fe_results,node_fe_history,node_fe_onboard,node_fe_examhook,node_fe_ui,node_fe_featdocs,node_fe_featexam,node_fe_load,node_fe_mock,node_fe_supabase toneBlue
class node_be_entry,node_be_board,node_be_prompts,node_be_db,node_be_supabase toneAmber
```

## Components

### Frontend

React/Vite SPA for the learning workflow

- [App shell](https://github.com/sebastianbo2/testem/blob/main/frontend/src/main.tsx): React/Vite entry · Bootstraps the SPA and top-level providers · `frontend/src/main.tsx`
- [Pages](https://github.com/sebastianbo2/testem/blob/main/frontend/src/App.tsx): Route layer · Maps the app into dashboard, auth, exam, results, and history screens · `frontend/src/App.tsx`
- [Auth context](https://github.com/sebastianbo2/testem/blob/main/frontend/src/context/AuthContext.tsx): Session state · Holds signed-in user state and auth helpers · `frontend/src/context/AuthContext.tsx`
- [Protected routes](https://github.com/sebastianbo2/testem/blob/main/frontend/src/components/ProtectedRoutes.tsx): Route guard · Blocks protected pages until authentication is available · `frontend/src/components/ProtectedRoutes.tsx`
- [Dashboard](https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/Dashboard.tsx): Workspace page · Main hub for moving into document and exam workflows · `frontend/src/pages/Dashboard.tsx`
- [Documents](https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/DocumentManagement.tsx): Doc workflow · Folder-based file selection and source material management · `frontend/src/pages/DocumentManagement.tsx`
- [Active exam](https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/ActiveExam.tsx): Exam session · Runs question navigation, answer entry, and progress tracking · `frontend/src/pages/ActiveExam.tsx`
- [Results](https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/Results.tsx): Review page · Shows post-submission feedback and answer comparison · `frontend/src/pages/Results.tsx`
- [History](https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/History.tsx): Attempts view · Browses prior exams and summary stats · `frontend/src/pages/History.tsx`
- [Onboarding](https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/Onboarding.tsx): Intro flow · Explains the product cycle for new users · `frontend/src/pages/Onboarding.tsx`
- [Exam session hook](https://github.com/sebastianbo2/testem/blob/main/frontend/src/hooks/useExamSession.ts): Client state · Coordinates question state, navigation, and session progress · `frontend/src/hooks/useExamSession.ts`
- [UI kit](https://github.com/sebastianbo2/testem/blob/main/frontend/src/components/ui/button.tsx): Shared primitives · Reusable shadcn/Radix components used across feature areas · `frontend/src/components/ui/button.tsx`
- [Doc components](https://github.com/sebastianbo2/testem/blob/main/frontend/src/components/documents/DocumentCard.tsx): Feature UI · Cards, action bars, and other document-management widgets · `frontend/src/components/documents/DocumentCard.tsx`
- [Exam components](https://github.com/sebastianbo2/testem/blob/main/frontend/src/components/exam/QuestionCard.tsx): Feature UI · Question cards and exam navigation widgets · `frontend/src/components/exam/QuestionCard.tsx`
- [Loading states](https://github.com/sebastianbo2/testem/blob/main/frontend/src/pages/loading/LoadingScreen.tsx): UX states · Dedicated screens for generation, grading, and loading transitions · `frontend/src/pages/loading/LoadingScreen.tsx`
- [Mock API](https://github.com/sebastianbo2/testem/blob/main/frontend/src/lib/mockApi.ts): Stub layer · Simulated backend responses for local or deterministic UI flows · `frontend/src/lib/mockApi.ts`
- [Supabase client](https://github.com/sebastianbo2/testem/blob/main/frontend/src/config/supabaseClient.ts): Client data · Frontend persistence/auth boundary shared with the backend · `frontend/src/config/supabaseClient.ts`

### Backend

Node/Express orchestration and data access layer

- [Server entry](https://github.com/sebastianbo2/testem/blob/main/backend/index.js): Express app · Backend process entrypoint and API host · `backend/index.js`
- [Backboard pipeline](https://github.com/sebastianbo2/testem/blob/main/backend/src/backboard/assistant.js): AI orchestration · Uploads documents and drives threaded prompt generation · `backend/src/backboard/assistant.js`
- [Prompts](https://github.com/sebastianbo2/testem/blob/main/backend/src/backboard/prompts.js): Prompt shaping · Defines the structured instructions used for exam generation · `backend/src/backboard/prompts.js`
- [DB requests](https://github.com/sebastianbo2/testem/blob/main/backend/src/lib/db_requests.js): Data access · Fetches questions, answers, and related records through small request helpers · `backend/src/lib/db_requests.js`
- [Supabase client](https://github.com/sebastianbo2/testem/blob/main/backend/src/config/supabaseClient.js): Server data · Backend persistence/auth boundary shared with the frontend · `backend/src/config/supabaseClient.js`

## Connections

- App shell → Pages: renders · Entry point mounts the route tree
- App shell → Auth context: provides · Top-level auth state is available to the app
- Pages → Protected routes: wraps · Protected screens are guarded before render
- Protected routes → Dashboard: unlocks · Authenticated users reach the workspace hub
- Protected routes → Documents: unlocks · Authenticated users manage source documents
- Protected routes → Active exam: unlocks · Authenticated users run an active exam session
- Protected routes → Results: unlocks · Authenticated users review submitted results
- Protected routes → History: unlocks · Authenticated users inspect attempt history
- Protected routes → Onboarding: unlocks · Authenticated users can view onboarding flow
- Active exam → Exam session hook: uses · The exam page delegates session state to the hook
- Pages → Loading states: shows · Long-running generation and grading states are surfaced explicitly
- Documents → Doc components: composes · Document management is built from feature-specific widgets
- Active exam → Exam components: composes · The active exam page is assembled from question UI pieces
- Dashboard → Documents: navigates · Workspace routes into document organization
- Dashboard → Active exam: starts · Workspace routes into exam creation and taking
- Results → History: feeds · Completed attempts are revisited through history
- UI kit → Doc components: supports · Shared primitives underpin document feature widgets
- UI kit → Exam components: supports · Shared primitives underpin exam feature widgets
- Mock API → Active exam: simulates · Stubbed responses can stand in for backend exam data
- Supabase client → Supabase client: shared boundary · Client and server both connect through Supabase
- Server entry → Backboard pipeline: orchestrates · API server delegates AI workflow to the Backboard pipeline
- Backboard pipeline → Prompts: builds from · Prompt templates shape generated exam content
- Server entry → DB requests: queries · Server handlers read and write persistence-backed records
- DB requests → Supabase client: uses · Database helpers access shared Supabase resources
- Backboard pipeline → Supabase client: stores · Generated or ingested data can be persisted through the shared backend boundary
- Backboard pipeline → Documents: serves · Document ingestion supports the frontend document workflow
