# 098765d/ai_tutor architecture

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

- Interactive diagram: https://gitdiagram.com/098765d/ai_tutor
- Repository: https://github.com/098765d/ai_tutor

## Overview

KG-RAG AI Tutor is a Streamlit course-question-answering application. Students can upload course PDFs and build an index; for each question, the tutor first checks for a reusable similar answer, then retrieves course chunks and—when KG-RAG mode is selected—expands context through a course knowledge graph before synthesizing an answer. Standard RAG skips graph expansion. The graph also includes configuration, embedding, persistence, and chat export responsibilities. Relationships are grounded in the README or shown source; the data directory is generated at runtime and is not in the supplied tree.

Main entry points: [`src/tutor.py`](https://github.com/098765d/ai_tutor/blob/main/src/tutor.py) (Tutor Orchestrator), [`app.py`](https://github.com/098765d/ai_tutor/blob/main/app.py) (Streamlit App), [`src/embeddings.py`](https://github.com/098765d/ai_tutor/blob/main/src/embeddings.py) (Embedding Client), [`src/knowledge_graph.py`](https://github.com/098765d/ai_tutor/blob/main/src/knowledge_graph.py) (Knowledge Graph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Student Interface"]
  node_app["Streamlit App<br/>[app.py]"]
  node_chat_export["Chat Export<br/>[export.py]"]
end

subgraph group_orchestration["Tutoring Workflow"]
  node_config["Configuration<br/>[config.py]"]
  node_tutor["Tutor Orchestrator<br/>[tutor.py]"]
end

subgraph group_retrieval["Course Retrieval"]
  node_course_pdfs["Course PDFs"]
  node_document_chunks["PDF Chunking<br/>[documents.py]"]
  node_vector_store[("Vector Retrieval<br/>[vector_store.py]")]
  node_knowledge_graph[("Knowledge Graph<br/>[knowledge_graph.py]")]
  node_chat_history[("Answer Reuse<br/>[chat_history.py]")]
end

subgraph group_services["Model Services"]
  node_embeddings["Embedding Client<br/>[embeddings.py]"]
  node_llm_client["LLM Client<br/>[llm.py]"]
end

node_student(("Student"))
node_deepseek["DeepSeek API"]
node_dashscope["DashScope Embeddings"]
node_minilm["Local MiniLM"]

node_student -->|"asks questions"| node_app
node_app -->|"loads settings"| node_config
node_app -->|"builds or queries"| node_tutor
node_app -->|"exports messages"| node_chat_export
node_app -->|"saves uploads"| node_course_pdfs
node_tutor -->|"uses settings"| node_config
node_tutor -->|"indexes materials"| node_course_pdfs
node_tutor -->|"builds chunks"| node_document_chunks
node_tutor -->|"builds and searches"| node_vector_store
node_tutor -->|"builds and retrieves"| node_knowledge_graph
node_tutor -->|"checks and saves"| node_chat_history
node_tutor -->|"synthesizes answers"| node_llm_client
node_vector_store -->|"embeds queries and chunks"| node_embeddings
node_knowledge_graph -->|"embeds graph nodes"| node_embeddings
node_knowledge_graph -->|"extracts triples"| node_llm_client
node_chat_history -->|"embeds questions"| node_embeddings
node_embeddings -.->|"requests embeddings"| node_dashscope
node_embeddings -.->|"embeds locally"| node_minilm
node_llm_client -->|"requests completions"| node_deepseek

click node_app "https://github.com/098765d/ai_tutor/blob/main/app.py"
click node_chat_export "https://github.com/098765d/ai_tutor/blob/main/src/export.py"
click node_config "https://github.com/098765d/ai_tutor/blob/main/src/config.py"
click node_tutor "https://github.com/098765d/ai_tutor/blob/main/src/tutor.py"
click node_course_pdfs "https://github.com/098765d/ai_tutor/tree/main/pdf"
click node_document_chunks "https://github.com/098765d/ai_tutor/blob/main/src/documents.py"
click node_vector_store "https://github.com/098765d/ai_tutor/blob/main/src/vector_store.py"
click node_knowledge_graph "https://github.com/098765d/ai_tutor/blob/main/src/knowledge_graph.py"
click node_chat_history "https://github.com/098765d/ai_tutor/blob/main/src/chat_history.py"
click node_embeddings "https://github.com/098765d/ai_tutor/blob/main/src/embeddings.py"
click node_llm_client "https://github.com/098765d/ai_tutor/blob/main/src/llm.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_app,node_chat_export toneBlue
class node_config,node_tutor toneAmber
class node_course_pdfs,node_document_chunks,node_vector_store,node_knowledge_graph,node_chat_history,node_deepseek toneMint
class node_embeddings,node_llm_client toneRose
class node_student,node_dashscope,node_minilm toneIndigo
```

## Components

### Student Interface

- [Streamlit App](https://github.com/098765d/ai_tutor/blob/main/app.py): `app.py`
- [Chat Export](https://github.com/098765d/ai_tutor/blob/main/src/export.py): `src/export.py`

### Tutoring Workflow

- [Configuration](https://github.com/098765d/ai_tutor/blob/main/src/config.py): `src/config.py`
- [Tutor Orchestrator](https://github.com/098765d/ai_tutor/blob/main/src/tutor.py): `src/tutor.py`

### Course Retrieval

- [Course PDFs](https://github.com/098765d/ai_tutor/tree/main/pdf): `pdf`
- [PDF Chunking](https://github.com/098765d/ai_tutor/blob/main/src/documents.py): `src/documents.py`
- [Vector Retrieval](https://github.com/098765d/ai_tutor/blob/main/src/vector_store.py): `src/vector_store.py`
- [Knowledge Graph](https://github.com/098765d/ai_tutor/blob/main/src/knowledge_graph.py): `src/knowledge_graph.py`
- [Answer Reuse](https://github.com/098765d/ai_tutor/blob/main/src/chat_history.py): `src/chat_history.py`

### Model Services

- [Embedding Client](https://github.com/098765d/ai_tutor/blob/main/src/embeddings.py): `src/embeddings.py`
- [LLM Client](https://github.com/098765d/ai_tutor/blob/main/src/llm.py): `src/llm.py`

### Other components

- **Student**
- **DeepSeek API**
- **DashScope Embeddings**
- **Local MiniLM**

## Connections

- Student → Streamlit App: asks questions (evidence: `README.md`)
- Streamlit App → Configuration: loads settings (evidence: `app.py`)
- Streamlit App → Tutor Orchestrator: builds or queries (evidence: `app.py`)
- Streamlit App → Chat Export: exports messages (evidence: `app.py`)
- Streamlit App → Course PDFs: saves uploads (evidence: `app.py`)
- Tutor Orchestrator → Configuration: uses settings (evidence: `src/tutor.py`)
- Tutor Orchestrator → Course PDFs: indexes materials (evidence: `README.md`)
- Tutor Orchestrator → PDF Chunking: builds chunks (evidence: `src/tutor.py`)
- Tutor Orchestrator → Vector Retrieval: builds and searches (evidence: `src/tutor.py`)
- Tutor Orchestrator → Knowledge Graph: builds and retrieves (evidence: `src/tutor.py`)
- Tutor Orchestrator → Answer Reuse: checks and saves (evidence: `src/tutor.py`)
- Tutor Orchestrator → LLM Client: synthesizes answers (evidence: `src/tutor.py`)
- Vector Retrieval → Embedding Client: embeds queries and chunks (evidence: `src/vector_store.py`)
- Knowledge Graph → Embedding Client: embeds graph nodes (evidence: `src/knowledge_graph.py`)
- Knowledge Graph → LLM Client: extracts triples (evidence: `src/knowledge_graph.py`)
- Answer Reuse → Embedding Client: embeds questions (evidence: `src/chat_history.py`)
- Embedding Client → DashScope Embeddings: requests embeddings (evidence: `src/embeddings.py`)
- Embedding Client → Local MiniLM: embeds locally (evidence: `README.md`)
- LLM Client → DeepSeek API: requests completions (evidence: `src/llm.py`)
