# judgepeach/math-question-bank architecture

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

- Interactive diagram: https://gitdiagram.com/judgepeach/math-question-bank
- Repository: https://github.com/judgepeach/math-question-bank

## Overview

MathBank is a local-first mathematics question bank and exam-preparation workspace. Teachers manage and classify questions, optionally use AI to select or explain them, assemble a paper, preview its A4 layout, and export PDF or editable Word. A second major workflow imports existing exams through format-specific parsing, image verification, and human review before questions enter the bank. The README documents these capabilities; the excerpts show selected storage, task, and PDF-figure internals, so links for unsampled subsystems rely on README statements rather than inspected call sites.

Main entry points: [`main.py`](https://github.com/judgepeach/math-question-bank/blob/main/main.py) (Question APIs), [`mathbank/paper_api.py`](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/paper_api.py) (Paper APIs), [`mathbank/database.py`](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/database.py) (Question database), [`static/js/workspace.js`](https://github.com/judgepeach/math-question-bank/blob/main/static/js/workspace.js) (Web workbench)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workspace["Teacher workspace"]
  node_web["Web workbench<br/>[workspace.js]"]
  node_editor["Question editor<br/>[editor.js]"]
  node_ocr["Single-question OCR<br/>[ocr.js]"]
end

subgraph group_bank["Question bank"]
  node_question_api["Question APIs<br/>[main.py]"]
  node_db[("Question database<br/>[database.py]")]
  node_curriculum["Curriculum catalog<br/>[curriculums.py]"]
  node_knowledge["Knowledge points"]
  node_search["Search and duplicates"]
  node_agent["Read-only agent API<br/>[agent_reads.py]"]
end

subgraph group_ingestion["Document ingestion"]
  node_import_ui["Import workspace"]
  node_project[("Document projects")]
  node_parse["Document parsing"]
  node_figure_pipeline["PDF figure pipeline"]
  node_figure_review["Figure verification"]
  node_review["Import review<br/>[import_review.py]"]
end

subgraph group_paper["Paper production"]
  node_paper_ui["Paper workbench<br/>[paper.js]"]
  node_paper_api["Paper APIs<br/>[paper_api.py]"]
  node_layout["A4 layout<br/>[paper_layout.py]"]
  node_word_export["Word export"]
end

subgraph group_runtime["Local runtime"]
  node_backup["Backup and restore<br/>[backup.py]"]
  node_storage[("Tiered asset storage<br/>[tiered_storage.py]")]
  node_tasks["Background tasks<br/>[task_manager.py]"]
  node_ai["AI providers<br/>[ai_providers.py]"]
end

node_teacher(("Teacher"))
node_ai_service(("AI service"))

node_teacher -->|"uses"| node_web
node_web -->|"opens"| node_editor
node_editor -->|"saves questions"| node_question_api
node_ocr -->|"submits reviewed result"| node_question_api
node_question_api -->|"reads and writes"| node_db
node_question_api -->|"classifies by"| node_curriculum
node_question_api -->|"applies tags"| node_knowledge
node_web -->|"searches bank"| node_search
node_teacher -->|"requests read access"| node_agent
node_agent -->|"reads questions"| node_db
node_teacher -->|"uploads exam"| node_import_ui
node_import_ui -->|"creates import project"| node_project
node_project -->|"runs parsing"| node_parse
node_parse -->|"assembles figures"| node_figure_pipeline
node_figure_pipeline -->|"requests verification"| node_figure_review
node_import_ui -->|"reviews parsed questions"| node_review
node_review -->|"imports accepted questions"| node_question_api
node_teacher -->|"assembles paper"| node_paper_ui
node_paper_ui -->|"configures paper"| node_paper_api
node_paper_api -->|"selects questions"| node_db
node_paper_api -->|"previews layout"| node_layout
node_paper_api -->|"exports Word"| node_word_export
node_paper_api -->|"requests AI selection"| node_ai
node_ai -->|"sends model request"| node_ai_service
node_project -->|"tracks processing"| node_tasks
node_backup -->|"backs up data"| node_db
node_backup -->|"handles assets"| node_storage

click node_web "https://github.com/judgepeach/math-question-bank/blob/main/static/js/workspace.js"
click node_editor "https://github.com/judgepeach/math-question-bank/blob/main/static/js/editor.js"
click node_ocr "https://github.com/judgepeach/math-question-bank/blob/main/static/js/ocr.js"
click node_question_api "https://github.com/judgepeach/math-question-bank/blob/main/main.py"
click node_db "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/database.py"
click node_curriculum "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/curriculums.py"
click node_knowledge "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/knowledge_points.py"
click node_search "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/question_duplicates.py"
click node_agent "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/agent_reads.py"
click node_import_ui "https://github.com/judgepeach/math-question-bank/blob/main/static/js/document-import-session.js"
click node_project "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/document_projects.py"
click node_parse "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/document_project_pipeline.py"
click node_figure_pipeline "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/pdf_figure_pipeline.py"
click node_figure_review "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/pdf_figure_review.py"
click node_review "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/import_review.py"
click node_paper_ui "https://github.com/judgepeach/math-question-bank/blob/main/static/js/paper.js"
click node_paper_api "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/paper_api.py"
click node_layout "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/paper_layout.py"
click node_word_export "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/word_export_helper.py"
click node_backup "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/backup.py"
click node_storage "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/tiered_storage.py"
click node_tasks "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/task_manager.py"
click node_ai "https://github.com/judgepeach/math-question-bank/blob/main/mathbank/ai_providers.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_web,node_editor,node_ocr toneBlue
class node_question_api,node_db,node_curriculum,node_knowledge,node_search,node_agent toneAmber
class node_import_ui,node_project,node_parse,node_figure_pipeline,node_figure_review,node_review toneMint
class node_paper_ui,node_paper_api,node_layout,node_word_export toneRose
class node_backup,node_storage,node_tasks,node_ai,node_teacher,node_ai_service toneIndigo
```

## Components

### Teacher workspace

- [Web workbench](https://github.com/judgepeach/math-question-bank/blob/main/static/js/workspace.js): `static/js/workspace.js`
- [Question editor](https://github.com/judgepeach/math-question-bank/blob/main/static/js/editor.js): `static/js/editor.js`
- [Single-question OCR](https://github.com/judgepeach/math-question-bank/blob/main/static/js/ocr.js): `static/js/ocr.js`

### Question bank

- [Question APIs](https://github.com/judgepeach/math-question-bank/blob/main/main.py): `main.py`
- [Question database](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/database.py): `mathbank/database.py`
- [Curriculum catalog](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/curriculums.py): `mathbank/curriculums.py`
- [Knowledge points](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/knowledge_points.py): `mathbank/knowledge_points.py`
- [Search and duplicates](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/question_duplicates.py): `mathbank/question_duplicates.py`
- [Read-only agent API](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/agent_reads.py): `mathbank/agent_reads.py`

### Document ingestion

- [Import workspace](https://github.com/judgepeach/math-question-bank/blob/main/static/js/document-import-session.js): `static/js/document-import-session.js`
- [Document projects](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/document_projects.py): `mathbank/document_projects.py`
- [Document parsing](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/document_project_pipeline.py): `mathbank/document_project_pipeline.py`
- [PDF figure pipeline](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/pdf_figure_pipeline.py): `mathbank/pdf_figure_pipeline.py`
- [Figure verification](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/pdf_figure_review.py): `mathbank/pdf_figure_review.py`
- [Import review](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/import_review.py): `mathbank/import_review.py`

### Paper production

- [Paper workbench](https://github.com/judgepeach/math-question-bank/blob/main/static/js/paper.js): `static/js/paper.js`
- [Paper APIs](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/paper_api.py): `mathbank/paper_api.py`
- [A4 layout](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/paper_layout.py): `mathbank/paper_layout.py`
- [Word export](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/word_export_helper.py): `mathbank/word_export_helper.py`

### Local runtime

- [Backup and restore](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/backup.py): `mathbank/backup.py`
- [Tiered asset storage](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/tiered_storage.py): `mathbank/tiered_storage.py`
- [Background tasks](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/task_manager.py): `mathbank/task_manager.py`
- [AI providers](https://github.com/judgepeach/math-question-bank/blob/main/mathbank/ai_providers.py): `mathbank/ai_providers.py`

### Other components

- **Teacher**
- **AI service**

## Connections

- Teacher → Web workbench: uses (evidence: `README.md`)
- Web workbench → Question editor: opens (evidence: `README.md`)
- Question editor → Question APIs: saves questions (evidence: `README.md`)
- Single-question OCR → Question APIs: submits reviewed result (evidence: `README.md`)
- Question APIs → Question database: reads and writes (evidence: `main.py`)
- Question APIs → Curriculum catalog: classifies by (evidence: `main.py`)
- Question APIs → Knowledge points: applies tags (evidence: `main.py`)
- Web workbench → Search and duplicates: searches bank (evidence: `README.md`)
- Teacher → Read-only agent API: requests read access (evidence: `README.md`)
- Read-only agent API → Question database: reads questions (evidence: `mathbank/agent_reads.py`)
- Teacher → Import workspace: uploads exam (evidence: `README.md`)
- Import workspace → Document projects: creates import project
- Document projects → Document parsing: runs parsing (evidence: `mathbank/document_project_pipeline.py`)
- Document parsing → PDF figure pipeline: assembles figures (evidence: `mathbank/pdf_figure_pipeline.py`)
- PDF figure pipeline → Figure verification: requests verification (evidence: `mathbank/pdf_figure_pipeline.py`)
- Import workspace → Import review: reviews parsed questions (evidence: `README.md`)
- Import review → Question APIs: imports accepted questions (evidence: `README.md`)
- Teacher → Paper workbench: assembles paper (evidence: `README.md`)
- Paper workbench → Paper APIs: configures paper (evidence: `README.md`)
- Paper APIs → Question database: selects questions (evidence: `README.md`)
- Paper APIs → A4 layout: previews layout (evidence: `README.md`)
- Paper APIs → Word export: exports Word (evidence: `README.md`)
- Paper APIs → AI providers: requests AI selection (evidence: `README.md`)
- AI providers → AI service: sends model request (evidence: `README.md`)
- Document projects → Background tasks: tracks processing (evidence: `mathbank/document_project_pipeline.py`)
- Backup and restore → Question database: backs up data (evidence: `mathbank/backup.py`)
- Backup and restore → Tiered asset storage: handles assets (evidence: `mathbank/backup.py`)
