# itiyashah/ai-teaching-assistant architecture

> Architecture diagram of the GitHub repository itiyashah/ai-teaching-assistant, 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/itiyashah/ai-teaching-assistant
- Repository: https://github.com/itiyashah/ai-teaching-assistant

## Overview

The product is a Streamlit study assistant: students manage chat sessions, ask questions, and receive AI explanations that are saved to chat history. The assistant graph retrieves textbook context, generates an answer, critiques it, and updates weak-topic state; users can also pin questions for later review. The UI persists users, conversations, messages, and weak topics through SQLAlchemy. The README documents PDF RAG and cloud persistence; the excerpts show the RAG and database implementations, but not all UI wiring to them, so uncertain links are dashed.

Main entry points: [`app.py`](https://github.com/itiyashah/ai-teaching-assistant/blob/main/app.py) (Streamlit interface), [`agent.py`](https://github.com/itiyashah/ai-teaching-assistant/blob/main/agent.py) (Answer critique), [`database.py`](https://github.com/itiyashah/ai-teaching-assistant/blob/main/database.py) (SQLAlchemy models), [`rag.py`](https://github.com/itiyashah/ai-teaching-assistant/blob/main/rag.py) (PDF ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Study interface"]
  node_ui["Streamlit interface<br/>[app.py]"]
  node_chat["Chat sessions<br/>[app.py]"]
  node_weak_ui["Weak topics UI<br/>[app.py]"]
  node_math["Math formatting<br/>[app.py]"]
end

subgraph group_persistence["Study persistence"]
  node_db_access["SQLAlchemy models<br/>[database.py]"]
  node_store[("PostgreSQL / SQLite")]
end

subgraph group_learning["Answer workflow"]
  node_agent["Assistant graph<br/>[agent.py]"]
  node_retrieval["Context retrieval<br/>[agent.py]"]
  node_generation["Answer generation<br/>[agent.py]"]
  node_reflection["Answer critique<br/>[agent.py]"]
  node_memory_update["Weak-topic update<br/>[agent.py]"]
end

subgraph group_documents["PDF learning"]
  node_pdf_ingest["PDF ingestion<br/>[rag.py]"]
  node_vector_store[("Chroma retriever<br/>[rag.py]")]
end

node_student(("Student"))
node_groq["Groq model API"]
node_huggingface["Hugging Face embeddings"]

node_student -->|"asks questions"| node_ui
node_ui -->|"manages chats"| node_chat
node_ui -->|"reads and writes"| node_db_access
node_chat -->|"loads history"| node_db_access
node_weak_ui -->|"saves topics"| node_db_access
node_ui -->|"invokes graph"| node_agent
node_agent -->|"dispatches"| node_retrieval
node_retrieval -->|"passes context"| node_generation
node_generation -->|"reviews answer"| node_reflection
node_reflection -->|"requests revision"| node_generation
node_reflection -->|"proceeds"| node_memory_update
node_generation -->|"requests completion"| node_groq
node_reflection -->|"requests critique"| node_groq
node_db_access -->|"persists records"| node_store
node_ui -->|"formats responses"| node_math
node_ui -.->|"offers PDF learning"| node_pdf_ingest
node_pdf_ingest -->|"embeds chunks"| node_huggingface
node_pdf_ingest -->|"builds retriever"| node_vector_store
node_retrieval -.->|"queries retriever"| node_vector_store

click node_ui "https://github.com/itiyashah/ai-teaching-assistant/blob/main/app.py"
click node_chat "https://github.com/itiyashah/ai-teaching-assistant/blob/main/app.py"
click node_weak_ui "https://github.com/itiyashah/ai-teaching-assistant/blob/main/app.py"
click node_math "https://github.com/itiyashah/ai-teaching-assistant/blob/main/app.py"
click node_db_access "https://github.com/itiyashah/ai-teaching-assistant/blob/main/database.py"
click node_agent "https://github.com/itiyashah/ai-teaching-assistant/blob/main/agent.py"
click node_retrieval "https://github.com/itiyashah/ai-teaching-assistant/blob/main/agent.py"
click node_generation "https://github.com/itiyashah/ai-teaching-assistant/blob/main/agent.py"
click node_reflection "https://github.com/itiyashah/ai-teaching-assistant/blob/main/agent.py"
click node_memory_update "https://github.com/itiyashah/ai-teaching-assistant/blob/main/agent.py"
click node_pdf_ingest "https://github.com/itiyashah/ai-teaching-assistant/blob/main/rag.py"
click node_vector_store "https://github.com/itiyashah/ai-teaching-assistant/blob/main/rag.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_ui,node_chat,node_weak_ui,node_math toneBlue
class node_db_access,node_store toneAmber
class node_agent,node_retrieval,node_generation,node_reflection,node_memory_update,node_groq toneMint
class node_pdf_ingest,node_vector_store toneRose
class node_student,node_huggingface toneIndigo
```

## Components

### Study interface

- [Streamlit interface](https://github.com/itiyashah/ai-teaching-assistant/blob/main/app.py): `app.py`
- [Chat sessions](https://github.com/itiyashah/ai-teaching-assistant/blob/main/app.py): `app.py`
- [Weak topics UI](https://github.com/itiyashah/ai-teaching-assistant/blob/main/app.py): `app.py`
- [Math formatting](https://github.com/itiyashah/ai-teaching-assistant/blob/main/app.py): `app.py`

### Study persistence

- [SQLAlchemy models](https://github.com/itiyashah/ai-teaching-assistant/blob/main/database.py): `database.py`
- **PostgreSQL / SQLite**

### Answer workflow

- [Assistant graph](https://github.com/itiyashah/ai-teaching-assistant/blob/main/agent.py): `agent.py`
- [Context retrieval](https://github.com/itiyashah/ai-teaching-assistant/blob/main/agent.py): `agent.py`
- [Answer generation](https://github.com/itiyashah/ai-teaching-assistant/blob/main/agent.py): `agent.py`
- [Answer critique](https://github.com/itiyashah/ai-teaching-assistant/blob/main/agent.py): `agent.py`
- [Weak-topic update](https://github.com/itiyashah/ai-teaching-assistant/blob/main/agent.py): `agent.py`

### PDF learning

- [PDF ingestion](https://github.com/itiyashah/ai-teaching-assistant/blob/main/rag.py): `rag.py`
- [Chroma retriever](https://github.com/itiyashah/ai-teaching-assistant/blob/main/rag.py): `rag.py`

### Other components

- **Student**
- **Groq model API**
- **Hugging Face embeddings**

## Connections

- Student → Streamlit interface: asks questions (evidence: `README.md`)
- Streamlit interface → Chat sessions: manages chats (evidence: `app.py`)
- Streamlit interface → SQLAlchemy models: reads and writes (evidence: `app.py`)
- Chat sessions → SQLAlchemy models: loads history (evidence: `app.py`)
- Weak topics UI → SQLAlchemy models: saves topics (evidence: `app.py`)
- Streamlit interface → Assistant graph: invokes graph (evidence: `app.py`)
- Assistant graph → Context retrieval: dispatches (evidence: `agent.py`)
- Context retrieval → Answer generation: passes context (evidence: `agent.py`)
- Answer generation → Answer critique: reviews answer (evidence: `agent.py`)
- Answer critique → Answer generation: requests revision (evidence: `agent.py`)
- Answer critique → Weak-topic update: proceeds (evidence: `agent.py`)
- Answer generation → Groq model API: requests completion (evidence: `agent.py`)
- Answer critique → Groq model API: requests critique (evidence: `agent.py`)
- SQLAlchemy models → PostgreSQL / SQLite: persists records (evidence: `database.py`)
- Streamlit interface → Math formatting: formats responses (evidence: `app.py`)
- Streamlit interface → PDF ingestion: offers PDF learning (evidence: `app.py`)
- PDF ingestion → Hugging Face embeddings: embeds chunks (evidence: `rag.py`)
- PDF ingestion → Chroma retriever: builds retriever (evidence: `rag.py`)
- Context retrieval → Chroma retriever: queries retriever
