# jashwanthreddi/ca-mentor-ai architecture

> Architecture diagram of the GitHub repository jashwanthreddi/ca-mentor-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jashwanthreddi/ca-mentor-ai
- Repository: https://github.com/jashwanthreddi/ca-mentor-ai

## Overview

CA Mentor AI is a study-question chat application backed by retrieval-augmented generation. The user-facing path runs from the chat UI through the API and chat service, which retrieves and reranks study chunks before generating an answer. A separate document-ingestion path turns PDFs into indexed chunks; retrieval/evaluation capabilities are represented where the source index documents them. Some stages and integrations are unsampled, so their links are omitted or marked unverified.

Main entry points: [`backend/app/services/chat_service.py`](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/services/chat_service.py) (Chat orchestration), [`backend/app/ingestion/pipeline.py`](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/pipeline.py) (Ingestion orchestration), [`backend/app/rag/run_retrieval_evaluation.py`](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/run_retrieval_evaluation.py) (Retrieval evaluation), [`frontend/src/App.jsx`](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/frontend/src/App.jsx) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat client"]
  node_chat_ui["Chat interface<br/>[App.jsx]"]
  node_chat_input["Question input<br/>[ChatInput.jsx]"]
  node_message_view["Message display<br/>[Message.jsx]"]
  node_welcome["Welcome prompts<br/>[Welcome.jsx]"]
  node_web_api["API client<br/>[api.js]"]
end

subgraph group_api["Application API"]
  node_http_api["Chat endpoint<br/>[chat.py]"]
  node_chat_schema["Chat schemas<br/>[chat.py]"]
  node_chat_service["Chat orchestration<br/>[chat_service.py]"]
  node_app_entry["Application setup<br/>[main.py]"]
end

subgraph group_retrieval["Knowledge retrieval"]
  node_corpus_loader["BM25 corpus loader<br/>[bm25_corpus.py]"]
  node_bm25["Lexical retrieval<br/>[bm25_retriever.py]"]
  node_dense["Dense retrieval<br/>[dense_retriever.py]"]
  node_hybrid["Hybrid fusion"]
  node_reranker["Evidence reranking<br/>[reranker.py]"]
  node_generator["Answer generation<br/>[generator.py]"]
  node_qdrant[("Qdrant index")]
end

subgraph group_ingestion["Document ingestion"]
  node_ingestion_pipeline["Ingestion orchestration<br/>[pipeline.py]"]
  node_extractor["PDF extraction<br/>[extractor.py]"]
  node_raw_document["Raw document model<br/>[raw_document.py]"]
  node_classifier["Content classification<br/>[classifier.py]"]
  node_parser["Knowledge-unit parsing<br/>[parser.py]"]
  node_domain_models["Ingestion domain models<br/>[models.py]"]
  node_chunker["Semantic chunking<br/>[chunker.py]"]
  node_embedder["Text embedding<br/>[embedder.py]"]
  node_ingestion_support["Validation and upload"]
end

subgraph group_evaluation["Evaluation"]
  node_retrieval_eval["Retrieval evaluation"]
  node_evaluation_data["Evaluation datasets"]
  node_generation_eval["Generation evaluation<br/>[runner.py]"]
end

node_student(("Student"))
node_pdf_source["Study PDF"]

node_student -->|"asks question"| node_chat_ui
node_chat_ui -->|"renders"| node_chat_input
node_chat_ui -->|"renders"| node_welcome
node_chat_ui -->|"renders"| node_message_view
node_chat_ui -->|"sends question"| node_web_api
node_web_api -.->|"HTTP request"| node_http_api
node_app_entry -->|"mounts routes"| node_http_api
node_http_api -->|"calls"| node_chat_service
node_http_api -->|"uses schemas"| node_chat_schema
node_chat_service -->|"loads corpus"| node_corpus_loader
node_chat_service -->|"initializes"| node_bm25
node_chat_service -->|"initializes"| node_dense
node_chat_service -->|"initializes"| node_hybrid
node_chat_service -->|"retrieves candidates"| node_hybrid
node_hybrid -->|"retrieves densely"| node_dense
node_hybrid -->|"retrieves lexically"| node_bm25
node_chat_service -->|"reranks candidates"| node_reranker
node_chat_service -->|"generates answer"| node_generator
node_dense -->|"searches index"| node_qdrant
node_corpus_loader -.->|"loads chunks"| node_qdrant
node_pdf_source -.->|"provides PDF"| node_ingestion_pipeline
node_ingestion_pipeline -->|"extracts pages"| node_extractor
node_extractor -.->|"produces"| node_raw_document
node_ingestion_pipeline -->|"classifies document"| node_classifier
node_classifier -.->|"reads blocks"| node_raw_document
node_ingestion_pipeline -.->|"parses elements"| node_parser
node_ingestion_pipeline -->|"chunks units"| node_chunker
node_ingestion_pipeline -.->|"validates and uploads"| node_ingestion_support
node_ingestion_pipeline -.->|"embeds chunks"| node_embedder
node_ingestion_pipeline -->|"uses domain types"| node_domain_models
node_retrieval_eval -->|"evaluates retrieval"| node_dense
node_retrieval_eval -->|"builds corpus"| node_corpus_loader
node_retrieval_eval -->|"evaluates retrieval"| node_bm25
node_retrieval_eval -->|"evaluates fusion"| node_hybrid
node_retrieval_eval -->|"evaluates ranking"| node_reranker
node_retrieval_eval -->|"loads questions"| node_evaluation_data
node_generation_eval -.->|"evaluates generation"| node_generator

click node_chat_ui "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/frontend/src/App.jsx"
click node_chat_input "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/frontend/src/components/ChatInput.jsx"
click node_message_view "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/frontend/src/components/Message.jsx"
click node_welcome "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/frontend/src/components/Welcome.jsx"
click node_web_api "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/frontend/src/services/api.js"
click node_http_api "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/api/v1/endpoints/chat.py"
click node_chat_schema "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/schemas/chat.py"
click node_chat_service "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/services/chat_service.py"
click node_app_entry "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/main.py"
click node_corpus_loader "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/bm25_corpus.py"
click node_bm25 "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/bm25_retriever.py"
click node_dense "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/dense_retriever.py"
click node_hybrid "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/hybrid_retriever.py"
click node_reranker "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/reranker.py"
click node_generator "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/generator.py"
click node_ingestion_pipeline "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/pipeline.py"
click node_extractor "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/extractor.py"
click node_raw_document "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/raw_document.py"
click node_classifier "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/classifier.py"
click node_parser "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/parser.py"
click node_domain_models "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/models.py"
click node_chunker "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/chunker.py"
click node_embedder "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/embedder.py"
click node_ingestion_support "https://github.com/jashwanthreddi/ca-mentor-ai/tree/main/backend/app/ingestion"
click node_retrieval_eval "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/run_retrieval_evaluation.py"
click node_evaluation_data "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/evaluation_dataset.py"
click node_generation_eval "https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/evaluation/generation/runner.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_chat_ui,node_chat_input,node_message_view,node_welcome,node_web_api toneBlue
class node_http_api,node_chat_schema,node_chat_service,node_app_entry toneAmber
class node_corpus_loader,node_bm25,node_dense,node_hybrid,node_reranker,node_generator,node_qdrant toneMint
class node_ingestion_pipeline,node_extractor,node_raw_document,node_classifier,node_parser,node_domain_models,node_chunker,node_embedder,node_ingestion_support toneRose
class node_retrieval_eval,node_evaluation_data,node_generation_eval,node_student,node_pdf_source toneIndigo
```

## Components

### Chat client

- [Chat interface](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Question input](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/frontend/src/components/ChatInput.jsx): `frontend/src/components/ChatInput.jsx`
- [Message display](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/frontend/src/components/Message.jsx): `frontend/src/components/Message.jsx`
- [Welcome prompts](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/frontend/src/components/Welcome.jsx): `frontend/src/components/Welcome.jsx`
- [API client](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### Application API

- [Chat endpoint](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/api/v1/endpoints/chat.py): `backend/app/api/v1/endpoints/chat.py`
- [Chat schemas](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/schemas/chat.py): `backend/app/schemas/chat.py`
- [Chat orchestration](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/services/chat_service.py): `backend/app/services/chat_service.py`
- [Application setup](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/main.py): `backend/app/main.py`

### Knowledge retrieval

- [BM25 corpus loader](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/bm25_corpus.py): `backend/app/rag/bm25_corpus.py`
- [Lexical retrieval](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/bm25_retriever.py): `backend/app/rag/bm25_retriever.py`
- [Dense retrieval](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/dense_retriever.py): `backend/app/rag/dense_retriever.py`
- [Hybrid fusion](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/hybrid_retriever.py): `backend/app/rag/hybrid_retriever.py`
- [Evidence reranking](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/reranker.py): `backend/app/rag/reranker.py`
- [Answer generation](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/generator.py): `backend/app/rag/generator.py`
- **Qdrant index**

### Document ingestion

- [Ingestion orchestration](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/pipeline.py): `backend/app/ingestion/pipeline.py`
- [PDF extraction](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/extractor.py): `backend/app/ingestion/extractor.py`
- [Raw document model](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/raw_document.py): `backend/app/ingestion/raw_document.py`
- [Content classification](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/classifier.py): `backend/app/ingestion/classifier.py`
- [Knowledge-unit parsing](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/parser.py): `backend/app/ingestion/parser.py`
- [Ingestion domain models](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/models.py): `backend/app/ingestion/models.py`
- [Semantic chunking](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/chunker.py): `backend/app/ingestion/chunker.py`
- [Text embedding](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/ingestion/embedder.py): `backend/app/ingestion/embedder.py`
- [Validation and upload](https://github.com/jashwanthreddi/ca-mentor-ai/tree/main/backend/app/ingestion): `backend/app/ingestion`

### Evaluation

- [Retrieval evaluation](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/run_retrieval_evaluation.py): `backend/app/rag/run_retrieval_evaluation.py`
- [Evaluation datasets](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/rag/evaluation_dataset.py): `backend/app/rag/evaluation_dataset.py`
- [Generation evaluation](https://github.com/jashwanthreddi/ca-mentor-ai/blob/main/backend/app/evaluation/generation/runner.py): `backend/app/evaluation/generation/runner.py`

### Other components

- **Student**
- **Study PDF**

## Connections

- Student → Chat interface: asks question (evidence: `frontend/src/App.jsx`)
- Chat interface → Question input: renders (evidence: `frontend/src/App.jsx`)
- Chat interface → Welcome prompts: renders (evidence: `frontend/src/App.jsx`)
- Chat interface → Message display: renders (evidence: `frontend/src/App.jsx`)
- Chat interface → API client: sends question (evidence: `frontend/src/App.jsx`)
- API client → Chat endpoint: HTTP request
- Application setup → Chat endpoint: mounts routes (evidence: `backend/app/main.py`)
- Chat endpoint → Chat orchestration: calls (evidence: `backend/app/api/v1/endpoints/chat.py`)
- Chat endpoint → Chat schemas: uses schemas (evidence: `backend/app/api/v1/endpoints/chat.py`)
- Chat orchestration → BM25 corpus loader: loads corpus (evidence: `backend/app/services/chat_service.py`)
- Chat orchestration → Lexical retrieval: initializes (evidence: `backend/app/services/chat_service.py`)
- Chat orchestration → Dense retrieval: initializes (evidence: `backend/app/services/chat_service.py`)
- Chat orchestration → Hybrid fusion: initializes (evidence: `backend/app/services/chat_service.py`)
- Chat orchestration → Hybrid fusion: retrieves candidates (evidence: `backend/app/services/chat_service.py`)
- Hybrid fusion → Dense retrieval: retrieves densely (evidence: `backend/app/rag/hybrid_retriever.py`)
- Hybrid fusion → Lexical retrieval: retrieves lexically (evidence: `backend/app/rag/hybrid_retriever.py`)
- Chat orchestration → Evidence reranking: reranks candidates (evidence: `backend/app/services/chat_service.py`)
- Chat orchestration → Answer generation: generates answer (evidence: `backend/app/services/chat_service.py`)
- Dense retrieval → Qdrant index: searches index (evidence: `backend/app/rag/dense_retriever.py`)
- BM25 corpus loader → Qdrant index: loads chunks
- Study PDF → Ingestion orchestration: provides PDF
- Ingestion orchestration → PDF extraction: extracts pages (evidence: `backend/app/ingestion/pipeline.py`)
- PDF extraction → Raw document model: produces (evidence: `backend/app/ingestion/extractor.py`)
- Ingestion orchestration → Content classification: classifies document (evidence: `backend/app/ingestion/pipeline.py`)
- Content classification → Raw document model: reads blocks (evidence: `backend/app/ingestion/classifier.py`)
- Ingestion orchestration → Knowledge-unit parsing: parses elements (evidence: `backend/app/ingestion/pipeline.py`)
- Ingestion orchestration → Semantic chunking: chunks units (evidence: `backend/app/ingestion/pipeline.py`)
- Ingestion orchestration → Validation and upload: validates and uploads (evidence: `backend/app/ingestion/pipeline.py`)
- Ingestion orchestration → Text embedding: embeds chunks (evidence: `backend/app/ingestion/pipeline.py`)
- Ingestion orchestration → Ingestion domain models: uses domain types (evidence: `backend/app/ingestion/pipeline.py`)
- Retrieval evaluation → Dense retrieval: evaluates retrieval (evidence: `backend/app/rag/run_retrieval_evaluation.py`)
- Retrieval evaluation → BM25 corpus loader: builds corpus (evidence: `backend/app/rag/run_retrieval_evaluation.py`)
- Retrieval evaluation → Lexical retrieval: evaluates retrieval (evidence: `backend/app/rag/run_retrieval_evaluation.py`)
- Retrieval evaluation → Hybrid fusion: evaluates fusion (evidence: `backend/app/rag/run_retrieval_evaluation.py`)
- Retrieval evaluation → Evidence reranking: evaluates ranking (evidence: `backend/app/rag/run_retrieval_evaluation.py`)
- Retrieval evaluation → Evaluation datasets: loads questions (evidence: `backend/app/rag/run_retrieval_evaluation.py`)
- Generation evaluation → Answer generation: evaluates generation
