# bodhiai-prod/bodha-gcp architecture

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

- Interactive diagram: https://gitdiagram.com/bodhiai-prod/bodha-gcp
- Repository: https://github.com/bodhiai-prod/bodha-gcp

## Overview

Bodha AI is an AI question-paper platform for teachers and students. Teachers configure papers from textbook topics or competitive-exam material; backend routes dispatch generation work, which applies instruction and section constraints, calls language-model services, and stores results. Students can create timed mock tests from shared textbooks, answer them, and review results. The graph also includes authentication, administration, and supporting generation stages. Frontend-to-backend wiring is not visible in the sampled excerpts, so those links are omitted; unsampled subsystem details are represented only where the file tree or source index supports them.

Main entry points: [`backend/workers.py`](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/workers.py) (Generation workers), [`backend/server.py`](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/server.py) (API server), [`backend/competitive_routes.py`](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/competitive_routes.py) (Competitive exams), [`backend/student_routes.py`](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/student_routes.py) (Student endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_paper_ui["Paper studio<br/>[NewPaper.jsx]"]
  node_paper_view["Paper views<br/>[PaperView.jsx]"]
  node_mock_ui["Mock test UI<br/>[MockTestExam.jsx]"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_api["API and access"]
  node_server["API server<br/>[server.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_admin["Admin endpoints<br/>[admin_routes.py]"]
end

subgraph group_paper["Paper generation"]
  node_workers["Generation workers<br/>[workers.py]"]
  node_instruction["Instruction parsing"]
  node_blueprints["Section blueprints"]
  node_requirements["Generation constraints"]
  node_prompts["Prompt builders<br/>[prompts.py]"]
  node_repair["Question repair<br/>[question_repair.py]"]
  node_dedupe["Question dedupe<br/>[question_dedupe.py]"]
  node_latex["LaTeX repair<br/>[latex_repair.py]"]
  node_diagrams["Diagram policy<br/>[diagram_policy.py]"]
  node_topic_balance["Topic balancing<br/>[topic_balance.py]"]
end

subgraph group_learning["Learning workflows"]
  node_student_routes["Student endpoints<br/>[student_routes.py]"]
  node_competitive["Competitive exams"]
  node_pdf["PDF utilities<br/>[pdf_utils.py]"]
  node_rag["Exam retrieval<br/>[rag.py]"]
end

subgraph group_services["Platform services"]
  node_llm["Language models<br/>[llm_adapter.py]"]
  node_usage["Token accounting<br/>[token_usage.py]"]
  node_deps["Shared app and DB<br/>[deps.py]"]
  node_database[("Firestore")]
  node_storage[("Object storage<br/>[storage.py]")]
end

node_teacher(("Teacher"))
node_student(("Student"))

node_teacher -.->|"configures"| node_paper_ui
node_student -.->|"takes test"| node_mock_ui
node_server -->|"uses"| node_auth
node_server -->|"registers"| node_student_routes
node_server -->|"registers"| node_competitive
node_server -->|"registers"| node_admin
node_server -->|"dispatches"| node_workers
node_student_routes -->|"starts generation"| node_workers
node_competitive -->|"generates batches"| node_workers
node_workers -->|"parses instructions"| node_instruction
node_workers -->|"applies blueprint"| node_blueprints
node_workers -->|"compiles constraints"| node_requirements
node_workers -->|"builds prompts"| node_prompts
node_workers -->|"requests generation"| node_llm
node_workers -->|"repairs questions"| node_repair
node_workers -->|"checks duplicates"| node_dedupe
node_workers -->|"repairs markup"| node_latex
node_workers -->|"checks diagrams"| node_diagrams
node_workers -->|"balances topics"| node_topic_balance
node_competitive -->|"retrieves examples"| node_rag
node_competitive -->|"processes papers"| node_pdf
node_server -->|"processes textbooks"| node_pdf
node_llm -->|"records usage"| node_usage
node_server -->|"uses shared app"| node_deps
node_deps -->|"initializes"| node_database
node_student_routes -->|"reads and writes"| node_database
node_competitive -->|"reads and writes"| node_database
node_admin -->|"reads and writes"| node_database
node_server -->|"reads and writes"| node_database
node_workers -->|"stores results"| node_database
node_competitive -.->|"stores paper files"| node_storage
node_paper_ui -.->|"submits settings"| node_api_client
node_paper_view -.->|"loads papers"| node_api_client
node_mock_ui -.->|"submits answers"| node_api_client

click node_paper_ui "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/frontend/src/pages/NewPaper.jsx"
click node_paper_view "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/frontend/src/pages/PaperView.jsx"
click node_mock_ui "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/frontend/src/pages/student/MockTestExam.jsx"
click node_api_client "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/frontend/src/lib/api.js"
click node_server "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/server.py"
click node_auth "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/auth.py"
click node_admin "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/admin_routes.py"
click node_student_routes "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/student_routes.py"
click node_competitive "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/competitive_routes.py"
click node_workers "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/workers.py"
click node_instruction "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/instruction_spec.py"
click node_blueprints "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/section_blueprints.py"
click node_requirements "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/generation_requirements.py"
click node_prompts "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/prompts.py"
click node_llm "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/llm_adapter.py"
click node_repair "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/question_repair.py"
click node_dedupe "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/question_dedupe.py"
click node_latex "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/latex_repair.py"
click node_diagrams "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/diagram_policy.py"
click node_pdf "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/pdf_utils.py"
click node_rag "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/rag.py"
click node_topic_balance "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/topic_balance.py"
click node_usage "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/token_usage.py"
click node_deps "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/deps.py"
click node_storage "https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/storage.py"

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_paper_ui,node_paper_view,node_mock_ui,node_api_client toneBlue
class node_server,node_auth,node_admin toneAmber
class node_workers,node_instruction,node_blueprints,node_requirements,node_prompts,node_repair,node_dedupe,node_latex,node_diagrams,node_topic_balance toneMint
class node_student_routes,node_competitive,node_pdf,node_rag toneRose
class node_llm,node_usage,node_deps,node_database,node_storage,node_teacher,node_student toneIndigo
```

## Components

### Web application

- [Paper studio](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/frontend/src/pages/NewPaper.jsx): `frontend/src/pages/NewPaper.jsx`
- [Paper views](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/frontend/src/pages/PaperView.jsx): `frontend/src/pages/PaperView.jsx`
- [Mock test UI](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/frontend/src/pages/student/MockTestExam.jsx): `frontend/src/pages/student/MockTestExam.jsx`
- [API client](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/frontend/src/lib/api.js): `frontend/src/lib/api.js`

### API and access

- [API server](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/server.py): `backend/server.py`
- [Authentication](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/auth.py): `backend/auth.py`
- [Admin endpoints](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/admin_routes.py): `backend/admin_routes.py`

### Paper generation

- [Generation workers](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/workers.py): `backend/workers.py`
- [Instruction parsing](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/instruction_spec.py): `backend/instruction_spec.py`
- [Section blueprints](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/section_blueprints.py): `backend/section_blueprints.py`
- [Generation constraints](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/generation_requirements.py): `backend/generation_requirements.py`
- [Prompt builders](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/prompts.py): `backend/prompts.py`
- [Question repair](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/question_repair.py): `backend/question_repair.py`
- [Question dedupe](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/question_dedupe.py): `backend/question_dedupe.py`
- [LaTeX repair](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/latex_repair.py): `backend/latex_repair.py`
- [Diagram policy](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/diagram_policy.py): `backend/diagram_policy.py`
- [Topic balancing](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/topic_balance.py): `backend/topic_balance.py`

### Learning workflows

- [Student endpoints](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/student_routes.py): `backend/student_routes.py`
- [Competitive exams](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/competitive_routes.py): `backend/competitive_routes.py`
- [PDF utilities](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/pdf_utils.py): `backend/pdf_utils.py`
- [Exam retrieval](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/rag.py): `backend/rag.py`

### Platform services

- [Language models](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/llm_adapter.py): `backend/llm_adapter.py`
- [Token accounting](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/token_usage.py): `backend/token_usage.py`
- [Shared app and DB](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/deps.py): `backend/deps.py`
- **Firestore**
- [Object storage](https://github.com/bodhiai-prod/bodha-gcp/blob/codex/gcp-migration/backend/storage.py): `backend/storage.py`

### Other components

- **Teacher**
- **Student**

## Connections

- Teacher → Paper studio: configures
- Student → Mock test UI: takes test
- API server → Authentication: uses (evidence: `backend/server.py`)
- API server → Student endpoints: registers (evidence: `backend/server.py`)
- API server → Competitive exams: registers (evidence: `backend/server.py`)
- API server → Admin endpoints: registers (evidence: `backend/server.py`)
- API server → Generation workers: dispatches (evidence: `backend/server.py`)
- Student endpoints → Generation workers: starts generation (evidence: `backend/student_routes.py`)
- Competitive exams → Generation workers: generates batches (evidence: `backend/competitive_routes.py`)
- Generation workers → Instruction parsing: parses instructions (evidence: `backend/workers.py`)
- Generation workers → Section blueprints: applies blueprint (evidence: `backend/workers.py`)
- Generation workers → Generation constraints: compiles constraints (evidence: `backend/workers.py`)
- Generation workers → Prompt builders: builds prompts (evidence: `backend/workers.py`)
- Generation workers → Language models: requests generation (evidence: `backend/workers.py`)
- Generation workers → Question repair: repairs questions (evidence: `backend/workers.py`)
- Generation workers → Question dedupe: checks duplicates (evidence: `backend/workers.py`)
- Generation workers → LaTeX repair: repairs markup (evidence: `backend/workers.py`)
- Generation workers → Diagram policy: checks diagrams (evidence: `backend/workers.py`)
- Generation workers → Topic balancing: balances topics (evidence: `backend/workers.py`)
- Competitive exams → Exam retrieval: retrieves examples (evidence: `backend/competitive_routes.py`)
- Competitive exams → PDF utilities: processes papers (evidence: `backend/competitive_routes.py`)
- API server → PDF utilities: processes textbooks (evidence: `backend/server.py`)
- Language models → Token accounting: records usage (evidence: `backend/llm_adapter.py`)
- API server → Shared app and DB: uses shared app (evidence: `backend/server.py`)
- Shared app and DB → Firestore: initializes (evidence: `backend/deps.py`)
- Student endpoints → Firestore: reads and writes (evidence: `backend/student_routes.py`)
- Competitive exams → Firestore: reads and writes (evidence: `backend/competitive_routes.py`)
- Admin endpoints → Firestore: reads and writes (evidence: `backend/admin_routes.py`)
- API server → Firestore: reads and writes (evidence: `backend/server.py`)
- Generation workers → Firestore: stores results (evidence: `backend/workers.py`)
- Competitive exams → Object storage: stores paper files (evidence: `backend/competitive_routes.py`)
- Paper studio → API client: submits settings
- Paper views → API client: loads papers
- Mock test UI → API client: submits answers
