# vinayak28x/aqpg architecture

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

- Interactive diagram: https://gitdiagram.com/vinayak28x/aqpg
- Repository: https://github.com/vinayak28x/aqpg

## Overview

1. **Overall shape**
   AQPG is a two-tier, fully local application: a React frontend for the workflow UI and a FastAPI backend that owns all document processing, semantic matching, and question generation. There is no separate cloud service layer; the backend is the system of record for the generated exam pipeline.

2. **User workflow boundary**
   The architecture is organized around a linear exam-authoring flow: upload syllabus PDF, upload textbook PDF, run semantic mapping, configure exam pattern, then generate questions. Each step is exposed in the UI as a separate stage and in the backend as a separate API responsibility.

3. **Frontend subsystem**
   The frontend lives in `frontend/src` and is composed of discrete UI components: `SyllabusUpload`, `TextbookUpload`, `SemanticMapping`, `PatternConfig`, `GeneratedQuestions`, and a `Stepper` for orchestration. This suggests a stateful wizard-style interface rather than a general-purpose single-page app.

4. **Backend application structure**
   The backend is a modular FastAPI app under `backend/app`, with `factory.py` for app construction and `main.py` as the server entry point. The structure is split into API routers, services, models, core config, and utility modules, which keeps request handling separate from business logic.

5. **API layer**
   The `backend/app/api` package contains endpoint groups for `syllabus`, `textbook`, `mapping`, and `questions`. This indicates four main API domains: ingest syllabus files, ingest textbook files, compute mappings, and generate the final question paper.

6. **Ingestion and document preprocessing**
   The ingestion path is handled by `ingestion_service.py` plus PDF/image utilities. `pdf_utils.py` and `image_utils.py` imply the backend can extract text and likely handle scanned or image-based PDF content as part of preprocessing before any AI work begins.

7. **Text normalization and chunking**
   `chunking_service.py` is a distinct layer between raw textbook extraction and semantic analysis. Its role is to break large textbook content into context-preserving chunks so downstream embedding and retrieval work on manageable units instead of whole documents.

8. **Syllabus parsing and topic model**
   `syllabus_service.py` and the Pydantic schemas in `models/schemas.py` define the structured representation of syllabus modules, headings, or topics. This is the canonical syllabus object used later for mapping and question generation.

9. **Semantic mapping subsystem**
   `mapping_service.py` uses local sentence embeddings via `sentence-transformers/all-MiniLM-L6-v2` to compare syllabus topics against textbook chunks. The output is a relevance mapping that links each syllabus item to the most applicable textbook context, forming the bridge between curriculum and source material.

10. **Question generation subsystem**
    `question_service.py` and `bloom_service.py` coordinate question synthesis using the mapped textbook context, the selected marks pattern, and a Bloom’s Taxonomy target level. The README indicates the generator is a local `google/flan-t5-base` model, so question creation is an offline LLM step constrained by exam structure.

11. **Configuration and model boundaries**
    `backend/app/core/config.py` centralizes runtime settings such as model paths and environment-specific configuration. This is important because the system can run either with automatic Hugging Face downloads or with manually placed local model files for offline deployment.

12. **Data flow end-to-end**
    The core backend flow is: PDF upload → extraction/chunking → syllabus structuring → semantic similarity mapping → exam pattern definition → prompt/context assembly → question generation → response back to the UI. The major architectural boundary is that all sensitive content stays inside the local backend and never leaves the machine.

13. **Deployment/runtime profile**
    The backend runs as Uvicorn-hosted FastAPI on Python 3.9+, while the frontend runs with the React development server on Node 18+. Heavy ML dependencies are isolated in a Python virtual environment, reflecting that inference and document processing are intentionally separated from the browser layer.

14. **Repository emphasis**
    The large documentation set under `docs/` suggests the project is heavily oriented around explaining models, prompts, and generated outputs rather than integrating external systems. Architecturally, this is a local AI pipeline with a thin UI wrapper, not an enterprise multi-service platform.

Main entry points: [`frontend/src/components/Stepper.js`](https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/Stepper.js) (Stepper), [`backend/app/factory.py`](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/factory.py) (App factory), [`backend/app/services/ingestion_service.py`](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/ingestion_service.py) (Ingestion), [`backend/app/services/question_service.py`](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/question_service.py) (Question service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_index["Entry<br/>[index.js]"]
  node_frontend_app["App shell<br/>React shell<br/>[App.js]"]
  node_frontend_stepper["Stepper<br/>wizard flow<br/>[Stepper.js]"]
  node_frontend_syllabus["Syllabus upload<br/>upload UI<br/>[SyllabusUpload.js]"]
  node_frontend_textbook["Textbook upload<br/>upload UI<br/>[TextbookUpload.js]"]
  node_frontend_mapping["Semantic mapping<br/>results UI<br/>[SemanticMapping.js]"]
  node_frontend_pattern["Pattern config<br/>config UI<br/>[PatternConfig.js]"]
  node_frontend_questions["Generated questions<br/>results UI"]
end

subgraph group_backend["Backend"]
  node_backend_main["Server entry<br/>FastAPI entry<br/>[main.py]"]
  node_backend_factory["App factory<br/>FastAPI setup<br/>[factory.py]"]
  node_backend_config["Config<br/>[config.py]"]
  node_api_syllabus["Syllabus API<br/>endpoint group<br/>[syllabus.py]"]
  node_api_textbook["Textbook API<br/>endpoint group<br/>[textbook.py]"]
  node_api_mapping["Mapping API<br/>endpoint group<br/>[mapping.py]"]
  node_api_questions["Questions API<br/>endpoint group<br/>[questions.py]"]
  node_svc_ingestion["Ingestion<br/>document service"]
  node_svc_pdf["PDF utils<br/>extract utility<br/>[pdf_utils.py]"]
  node_svc_image["Image utils<br/>OCR utility<br/>[image_utils.py]"]
  node_svc_chunking["Chunking<br/>text service"]
  node_svc_syllabus["Syllabus service<br/>parse service"]
  node_models_schemas["Schemas<br/>Pydantic models<br/>[schemas.py]"]
  node_svc_mapping["Mapping service<br/>embedding match<br/>[mapping_service.py]"]
  node_svc_bloom["Bloom service<br/>taxonomy logic<br/>[bloom_service.py]"]
  node_svc_questions["Question service<br/>generation service"]
end

subgraph group_docs["Docs"]
  node_docs_bundle["Docs bundle<br/>documentation"]
end

node_frontend_index -->|"boots"| node_frontend_app
node_frontend_app -->|"orchestrates"| node_frontend_stepper
node_frontend_stepper -->|"stage 1"| node_frontend_syllabus
node_frontend_stepper -->|"stage 2"| node_frontend_textbook
node_frontend_stepper -->|"stage 3"| node_frontend_mapping
node_frontend_stepper -->|"stage 4"| node_frontend_pattern
node_frontend_stepper -->|"stage 5"| node_frontend_questions
node_backend_main -->|"boots"| node_backend_factory
node_backend_factory -->|"loads"| node_backend_config
node_backend_factory -->|"mounts"| node_api_syllabus
node_backend_factory -->|"mounts"| node_api_textbook
node_backend_factory -->|"mounts"| node_api_mapping
node_backend_factory -->|"mounts"| node_api_questions
node_api_syllabus -->|"uses"| node_svc_syllabus
node_api_textbook -->|"uses"| node_svc_ingestion
node_svc_ingestion -->|"extracts"| node_svc_pdf
node_svc_ingestion -->|"handles"| node_svc_image
node_svc_ingestion -->|"prepares"| node_svc_chunking
node_svc_syllabus -->|"structures"| node_models_schemas
node_api_mapping -->|"uses"| node_svc_mapping
node_svc_mapping -->|"consumes"| node_svc_chunking
node_svc_mapping -->|"emits"| node_models_schemas
node_api_questions -->|"uses"| node_svc_questions
node_svc_questions -->|"applies"| node_svc_bloom
node_svc_questions -->|"emits"| node_models_schemas
node_frontend_syllabus -->|"uploads to"| node_api_syllabus
node_frontend_textbook -->|"uploads to"| node_api_textbook
node_frontend_mapping -->|"requests"| node_api_mapping
node_frontend_questions -->|"requests"| node_api_questions
node_docs_bundle -.->|"documents"| node_backend_config
node_docs_bundle -.->|"documents"| node_svc_questions

click node_frontend_index "https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/index.js"
click node_frontend_app "https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/App.js"
click node_frontend_stepper "https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/Stepper.js"
click node_frontend_syllabus "https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/SyllabusUpload.js"
click node_frontend_textbook "https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/TextbookUpload.js"
click node_frontend_mapping "https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/SemanticMapping.js"
click node_frontend_pattern "https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/PatternConfig.js"
click node_frontend_questions "https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/GeneratedQuestions.js"
click node_backend_main "https://github.com/vinayak28x/aqpg/blob/dev/backend/main.py"
click node_backend_factory "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/factory.py"
click node_backend_config "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/core/config.py"
click node_api_syllabus "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/api/syllabus.py"
click node_api_textbook "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/api/textbook.py"
click node_api_mapping "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/api/mapping.py"
click node_api_questions "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/api/questions.py"
click node_svc_ingestion "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/ingestion_service.py"
click node_svc_pdf "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/utils/pdf_utils.py"
click node_svc_image "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/utils/image_utils.py"
click node_svc_chunking "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/chunking_service.py"
click node_svc_syllabus "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/syllabus_service.py"
click node_models_schemas "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/models/schemas.py"
click node_svc_mapping "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/mapping_service.py"
click node_svc_bloom "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/bloom_service.py"
click node_svc_questions "https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/question_service.py"
click node_docs_bundle "https://github.com/vinayak28x/aqpg/blob/dev/docs/README_DOCUMENTATION_INDEX.md"

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_frontend_index,node_frontend_app,node_frontend_stepper,node_frontend_syllabus,node_frontend_textbook,node_frontend_mapping,node_frontend_pattern,node_frontend_questions toneBlue
class node_backend_main,node_backend_factory,node_backend_config,node_api_syllabus,node_api_textbook,node_api_mapping,node_api_questions,node_svc_ingestion,node_svc_pdf,node_svc_image,node_svc_chunking,node_svc_syllabus,node_models_schemas,node_svc_mapping,node_svc_bloom,node_svc_questions toneAmber
class node_docs_bundle toneMint
```

## Components

### Frontend

React wizard UI for the linear exam-authoring flow

- [Entry](https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/index.js): React entry · Browser bootstrap for the frontend app · `frontend/src/index.js`
- [App shell](https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/App.js): React shell · Top-level frontend container and state orchestration · `frontend/src/App.js`
- [Stepper](https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/Stepper.js): wizard flow · Drives the sequential exam-authoring stages · `frontend/src/components/Stepper.js`
- [Syllabus upload](https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/SyllabusUpload.js): upload UI · Collects syllabus PDF input from the user · `frontend/src/components/SyllabusUpload.js`
- [Textbook upload](https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/TextbookUpload.js): upload UI · Collects textbook PDF input from the user · `frontend/src/components/TextbookUpload.js`
- [Semantic mapping](https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/SemanticMapping.js): results UI · Displays syllabus-to-textbook relevance output · `frontend/src/components/SemanticMapping.js`
- [Pattern config](https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/PatternConfig.js): config UI · Configures marks distribution and exam structure · `frontend/src/components/PatternConfig.js`
- [Generated questions](https://github.com/vinayak28x/aqpg/blob/dev/frontend/src/components/GeneratedQuestions.js): results UI · Shows the final generated question paper · `frontend/src/components/GeneratedQuestions.js`

### Backend

FastAPI application for ingestion, mapping, and question generation

- [Server entry](https://github.com/vinayak28x/aqpg/blob/dev/backend/main.py): FastAPI entry · Uvicorn-facing backend startup point · `backend/main.py`
- [App factory](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/factory.py): FastAPI setup · Constructs and wires the FastAPI application · `backend/app/factory.py`
- [Config](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/core/config.py): runtime config · Central runtime settings and model paths · `backend/app/core/config.py`
- [Syllabus API](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/api/syllabus.py): endpoint group · Routes for syllabus upload and parsing · `backend/app/api/syllabus.py`
- [Textbook API](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/api/textbook.py): endpoint group · Routes for textbook upload and preprocessing · `backend/app/api/textbook.py`
- [Mapping API](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/api/mapping.py): endpoint group · Routes for semantic matching · `backend/app/api/mapping.py`
- [Questions API](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/api/questions.py): endpoint group · Routes for exam generation · `backend/app/api/questions.py`
- [Ingestion](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/ingestion_service.py): document service · Coordinates document intake and extraction · `backend/app/services/ingestion_service.py`
- [PDF utils](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/utils/pdf_utils.py): extract utility · Extracts text and structure from PDF content · `backend/app/utils/pdf_utils.py`
- [Image utils](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/utils/image_utils.py): OCR utility · Handles scanned or image-based content preprocessing · `backend/app/utils/image_utils.py`
- [Chunking](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/chunking_service.py): text service · Breaks extracted textbook content into manageable chunks · `backend/app/services/chunking_service.py`
- [Syllabus service](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/syllabus_service.py): parse service · Structures syllabus topics and headings · `backend/app/services/syllabus_service.py`
- [Schemas](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/models/schemas.py): Pydantic models · Canonical data models for syllabus, mapping, and questions · `backend/app/models/schemas.py`
- [Mapping service](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/mapping_service.py): embedding match · Computes syllabus-to-textbook relevance with local sentence embeddings · `backend/app/services/mapping_service.py`
- [Bloom service](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/bloom_service.py): taxonomy logic · Applies Bloom’s taxonomy level selection and alignment · `backend/app/services/bloom_service.py`
- [Question service](https://github.com/vinayak28x/aqpg/blob/dev/backend/app/services/question_service.py): generation service · Assembles context and produces final exam questions · `backend/app/services/question_service.py`

### Docs

Repository documentation and model guides

- [Docs bundle](https://github.com/vinayak28x/aqpg/blob/dev/docs/README_DOCUMENTATION_INDEX.md): documentation · Guides, model notes, prompts, and reference material · `docs/README_DOCUMENTATION_INDEX.md`

## Connections

- Entry → App shell: boots · Browser entry mounts the app shell
- App shell → Stepper: orchestrates · Main UI coordinates the wizard stages
- Stepper → Syllabus upload: stage 1 · Syllabus upload is the first step
- Stepper → Textbook upload: stage 2 · Textbook upload follows syllabus intake
- Stepper → Semantic mapping: stage 3 · Mapping results appear after backend matching
- Stepper → Pattern config: stage 4 · Pattern configuration sets the exam structure
- Stepper → Generated questions: stage 5 · Generated questions are the final output
- Server entry → App factory: boots · Server entry creates the FastAPI app
- App factory → Config: loads · Application wiring reads runtime configuration
- App factory → Syllabus API: mounts · Registers syllabus endpoints
- App factory → Textbook API: mounts · Registers textbook endpoints
- App factory → Mapping API: mounts · Registers mapping endpoints
- App factory → Questions API: mounts · Registers question-generation endpoints
- Syllabus API → Syllabus service: uses · Routes call syllabus parsing logic
- Textbook API → Ingestion: uses · Routes delegate upload and extraction work
- Ingestion → PDF utils: extracts · PDF utility handles document text extraction
- Ingestion → Image utils: handles · Image utility supports scanned content preprocessing
- Ingestion → Chunking: prepares · Extracted textbook content is normalized into chunks
- Syllabus service → Schemas: structures · Parsed syllabus uses canonical schema objects
- Mapping API → Mapping service: uses · Routes invoke semantic matching service
- Mapping service → Chunking: consumes · Mapping compares syllabus topics to text chunks
- Mapping service → Schemas: emits · Mapping results use shared response models
- Questions API → Question service: uses · Routes invoke exam generation service
- Question service → Bloom service: applies · Question generation constrains output by Bloom level
- Question service → Schemas: emits · Generated question payloads use shared schemas
- Syllabus upload → Syllabus API: uploads to · UI sends syllabus data to backend endpoints
- Textbook upload → Textbook API: uploads to · UI sends textbook data to backend endpoints
- Semantic mapping → Mapping API: requests · UI requests semantic mapping results
- Generated questions → Questions API: requests · UI requests generated questions
- Docs bundle → Config: documents · Docs describe model and runtime configuration
- Docs bundle → Question service: documents · Docs explain question-generation behavior
