# hungcb123/ctu-chat_bot architecture

> Architecture diagram of the GitHub repository hungcb123/ctu-chat_bot, 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/hungcb123/ctu-chat_bot
- Repository: https://github.com/hungcb123/ctu-chat_bot

## Overview

CTU Academic Chatbot is a Vietnamese university-support chatbot combining supervisor-routed agents, hybrid RAG, and Neo4j academic and tuition tools. The main workflow is user question → supervisor rewrite and intent routing → academic graph tools or retrieval and a specialist agent → answer. Separate capabilities include account/chat history and administrator document upload with OCR and indexing. Relationships follow the README and shown imports; detailed wiring inside unsampled modules is not assumed.

Main entry points: [`app/agents/graph.py`](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/agents/graph.py) (Supervisor and agents), [`app/services/rag_engine.py`](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/rag_engine.py) (Hybrid RAG engine), [`app/main.py`](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/main.py) (Application startup), [`app/api/chat.py`](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/api/chat.py) (Chat API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and sessions"]
  node_main["Application startup<br/>[main.py]"]
  node_chat["Chat API<br/>[chat.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_history["Chat history API<br/>[history.py]"]
  node_document_api["Document upload API<br/>[document.py]"]
end

subgraph group_agent["Agent routing"]
  node_agent_graph["Supervisor and agents<br/>[graph.py]"]
  node_prompts["Agent prompts<br/>[prompts.py]"]
  node_intent["Intent routing<br/>[query_intent.py]"]
end

subgraph group_retrieval["RAG and documents"]
  node_rag["Hybrid RAG engine<br/>[rag_engine.py]"]
  node_bm25["BM25 search<br/>[bm25_service.py]"]
  node_reranker["Remote reranker<br/>[remote_reranker.py]"]
  node_metadata["Document metadata"]
  node_ocr["PDF OCR<br/>[ocr_service.py]"]
end

subgraph group_domain["Academic and finance"]
  node_graph_service["Academic graph service<br/>[graph_service.py]"]
  node_academic_tools["Academic tools"]
  node_tuition_tools["Tuition graph tools<br/>[tuition_graph.py]"]
  node_tuition_catalog["Tuition catalog<br/>[tuition_catalog.py]"]
  node_scholarship["Scholarship tools<br/>[scholarship.py]"]
  node_tuition["Tuition calculator<br/>[tuition.py]"]
  node_academic_ingest["Curriculum graph ingest<br/>[ingest.py]"]
  node_tuition_ingest["Tuition graph ingest<br/>[ingest_tuition.py]"]
end

subgraph group_stores["Data stores"]
  node_postgres[("PostgreSQL<br/>[database.py]")]
  node_neo4j[("Neo4j")]
  node_qdrant[("Qdrant")]
  node_redis[("Redis")]
end

node_user(("Chat user"))
node_llm{{"Gemini LLM"}}
node_rerank_service{{"Reranking service"}}

node_user -->|"asks"| node_chat
node_main -->|"registers"| node_chat
node_main -->|"builds"| node_agent_graph
node_main -->|"initializes"| node_rag
node_chat -->|"routes question"| node_agent_graph
node_agent_graph -->|"classifies intent"| node_intent
node_agent_graph -->|"uses prompts"| node_prompts
node_agent_graph -->|"requests retrieval"| node_rag
node_agent_graph -->|"dispatches academic"| node_academic_tools
node_agent_graph -->|"dispatches finance"| node_tuition_tools
node_agent_graph -->|"dispatches scholarship"| node_scholarship
node_agent_graph -->|"uses calculator"| node_tuition
node_rag -->|"uses lexical search"| node_bm25
node_rag -->|"uses reranking"| node_reranker
node_rag -->|"filters documents"| node_metadata
node_rag -->|"vector search"| node_qdrant
node_rag -->|"reranks results"| node_rerank_service
node_rag -->|"embeds queries"| node_llm
node_document_api -->|"extracts PDF"| node_ocr
node_document_api -->|"updates metadata"| node_metadata
node_academic_tools -->|"calls queries"| node_graph_service
node_tuition_tools -->|"calls queries"| node_graph_service
node_tuition_tools -->|"fallback lookup"| node_tuition_catalog
node_graph_service -->|"queries graph"| node_neo4j
node_academic_ingest -->|"loads curriculum"| node_neo4j
node_tuition_ingest -->|"loads tuition"| node_neo4j
node_main -->|"initializes service"| node_graph_service
node_main -->|"connects"| node_redis
node_chat -->|"requires identity"| node_auth
node_history -->|"requires identity"| node_auth
node_auth -->|"reads users"| node_postgres
node_history -->|"reads history"| node_postgres
node_chat -->|"stores messages"| node_postgres

click node_main "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/main.py"
click node_chat "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/api/chat.py"
click node_auth "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/api/auth.py"
click node_history "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/api/history.py"
click node_document_api "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/api/document.py"
click node_agent_graph "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/agents/graph.py"
click node_prompts "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/agents/prompts.py"
click node_intent "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/query_intent.py"
click node_rag "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/rag_engine.py"
click node_bm25 "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/bm25_service.py"
click node_reranker "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/remote_reranker.py"
click node_metadata "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/document_metadata.py"
click node_ocr "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/ocr_service.py"
click node_graph_service "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/graph_service.py"
click node_academic_tools "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/tools/academic_program.py"
click node_tuition_tools "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/tools/tuition_graph.py"
click node_tuition_catalog "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/tuition_catalog.py"
click node_scholarship "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/tools/scholarship.py"
click node_tuition "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/tools/tuition.py"
click node_academic_ingest "https://github.com/hungcb123/ctu-chat_bot/blob/main/Graph_DB/app/ingest.py"
click node_tuition_ingest "https://github.com/hungcb123/ctu-chat_bot/blob/main/Graph_DB/app/ingest_tuition.py"
click node_postgres "https://github.com/hungcb123/ctu-chat_bot/blob/main/app/core/database.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_main,node_chat,node_auth,node_history,node_document_api,node_user toneBlue
class node_agent_graph,node_prompts,node_intent toneAmber
class node_rag,node_bm25,node_reranker,node_metadata,node_ocr toneMint
class node_graph_service,node_academic_tools,node_tuition_tools,node_tuition_catalog,node_scholarship,node_tuition,node_academic_ingest,node_tuition_ingest toneRose
class node_postgres,node_neo4j,node_qdrant,node_redis,node_llm,node_rerank_service toneIndigo
```

## Components

### API and sessions

- [Application startup](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/main.py): `app/main.py`
- [Chat API](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/api/chat.py): `app/api/chat.py`
- [Authentication](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/api/auth.py): `app/api/auth.py`
- [Chat history API](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/api/history.py): `app/api/history.py`
- [Document upload API](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/api/document.py): `app/api/document.py`

### Agent routing

- [Supervisor and agents](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/agents/graph.py): `app/agents/graph.py`
- [Agent prompts](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/agents/prompts.py): `app/agents/prompts.py`
- [Intent routing](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/query_intent.py): `app/services/query_intent.py`

### RAG and documents

- [Hybrid RAG engine](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/rag_engine.py): `app/services/rag_engine.py`
- [BM25 search](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/bm25_service.py): `app/services/bm25_service.py`
- [Remote reranker](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/remote_reranker.py): `app/services/remote_reranker.py`
- [Document metadata](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/document_metadata.py): `app/services/document_metadata.py`
- [PDF OCR](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/ocr_service.py): `app/services/ocr_service.py`

### Academic and finance

- [Academic graph service](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/graph_service.py): `app/services/graph_service.py`
- [Academic tools](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/tools/academic_program.py): `app/tools/academic_program.py`
- [Tuition graph tools](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/tools/tuition_graph.py): `app/tools/tuition_graph.py`
- [Tuition catalog](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/services/tuition_catalog.py): `app/services/tuition_catalog.py`
- [Scholarship tools](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/tools/scholarship.py): `app/tools/scholarship.py`
- [Tuition calculator](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/tools/tuition.py): `app/tools/tuition.py`
- [Curriculum graph ingest](https://github.com/hungcb123/ctu-chat_bot/blob/main/Graph_DB/app/ingest.py): `Graph_DB/app/ingest.py`
- [Tuition graph ingest](https://github.com/hungcb123/ctu-chat_bot/blob/main/Graph_DB/app/ingest_tuition.py): `Graph_DB/app/ingest_tuition.py`

### Data stores

- [PostgreSQL](https://github.com/hungcb123/ctu-chat_bot/blob/main/app/core/database.py): `app/core/database.py`
- **Neo4j**
- **Qdrant**
- **Redis**

### Other components

- **Chat user**
- **Gemini LLM**
- **Reranking service**

## Connections

- Chat user → Chat API: asks (evidence: `README.md`)
- Application startup → Chat API: registers (evidence: `app/main.py`)
- Application startup → Supervisor and agents: builds (evidence: `app/main.py`)
- Application startup → Hybrid RAG engine: initializes (evidence: `app/main.py`)
- Chat API → Supervisor and agents: routes question (evidence: `README.md`)
- Supervisor and agents → Intent routing: classifies intent (evidence: `app/agents/graph.py`)
- Supervisor and agents → Agent prompts: uses prompts (evidence: `app/agents/graph.py`)
- Supervisor and agents → Hybrid RAG engine: requests retrieval (evidence: `README.md`)
- Supervisor and agents → Academic tools: dispatches academic (evidence: `README.md`)
- Supervisor and agents → Tuition graph tools: dispatches finance (evidence: `README.md`)
- Supervisor and agents → Scholarship tools: dispatches scholarship (evidence: `README.md`)
- Supervisor and agents → Tuition calculator: uses calculator (evidence: `README.md`)
- Hybrid RAG engine → BM25 search: uses lexical search (evidence: `app/services/rag_engine.py`)
- Hybrid RAG engine → Remote reranker: uses reranking (evidence: `app/services/rag_engine.py`)
- Hybrid RAG engine → Document metadata: filters documents (evidence: `app/services/rag_engine.py`)
- Hybrid RAG engine → Qdrant: vector search (evidence: `README.md`)
- Hybrid RAG engine → Reranking service: reranks results (evidence: `README.md`)
- Hybrid RAG engine → Gemini LLM: embeds queries (evidence: `README.md`)
- Document upload API → PDF OCR: extracts PDF (evidence: `app/api/document.py`)
- Document upload API → Document metadata: updates metadata (evidence: `app/api/document.py`)
- Academic tools → Academic graph service: calls queries (evidence: `app/tools/academic_program.py`)
- Tuition graph tools → Academic graph service: calls queries (evidence: `app/tools/tuition_graph.py`)
- Tuition graph tools → Tuition catalog: fallback lookup (evidence: `app/tools/tuition_graph.py`)
- Academic graph service → Neo4j: queries graph (evidence: `README.md`)
- Curriculum graph ingest → Neo4j: loads curriculum (evidence: `Graph_DB/app/ingest.py`)
- Tuition graph ingest → Neo4j: loads tuition (evidence: `Graph_DB/app/ingest_tuition.py`)
- Application startup → Academic graph service: initializes service (evidence: `app/main.py`)
- Application startup → Redis: connects (evidence: `app/main.py`)
- Chat API → Authentication: requires identity (evidence: `app/api/chat.py`)
- Chat history API → Authentication: requires identity (evidence: `app/api/history.py`)
- Authentication → PostgreSQL: reads users (evidence: `app/api/auth.py`)
- Chat history API → PostgreSQL: reads history (evidence: `app/api/history.py`)
- Chat API → PostgreSQL: stores messages (evidence: `README.md`)
