# bhanavikochhar/llm-based-math-tutor architecture

> Architecture diagram of the GitHub repository bhanavikochhar/llm-based-math-tutor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bhanavikochhar/llm-based-math-tutor
- Repository: https://github.com/bhanavikochhar/llm-based-math-tutor

## Overview

TinyThinker is a Streamlit NCERT mathematics tutor: a student submits a question, the app resolves and checks it, retrieves curriculum context, computes trusted answers, chooses a tutoring action, generates and checks a reply, then records progress and renders the result. Separate evaluation tools score tutor and baseline transcripts. The main turn sequence is documented in the README; source excerpts confirm selected wiring. Evaluation relationships are limited to those shown in the SOURCE INDEX.

Main entry points: [`scripts/llm/pipeline.py`](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/pipeline.py) (Turn pipeline), [`frontend/views/main_page.py`](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/frontend/views/main_page.py) (Chat interface), [`frontend/episode.py`](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/frontend/episode.py) (Episode handler), [`eval/baseline_runner.py`](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/eval/baseline_runner.py) (Baseline runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Student experience"]
  node_app["App router<br/>[app.py]"]
  node_session["Session and profile<br/>[state.py]"]
  node_chat["Chat interface<br/>[main_page.py]"]
end

subgraph group_orchestration["Turn orchestration"]
  node_episode["Episode handler<br/>[episode.py]"]
  node_pipeline["Turn pipeline<br/>[pipeline.py]"]
  node_safety["Input and output safety<br/>[safety.py]"]
  node_scope["Syllabus scope gate<br/>[scope.py]"]
  node_resolver["Conversation resolver"]
  node_intent["Intent classifier<br/>[intent.py]"]
  node_controller["Tutoring state machine<br/>[controller.py]"]
  node_tracker[("Learner progress tracker<br/>[student_tracker.py]")]
  node_telemetry[("Interaction telemetry<br/>[telemetry.py]")]
end

subgraph group_grounding["Math and curriculum grounding"]
  node_retrieval["Hybrid curriculum retrieval<br/>[retrieval.py]"]
  node_verifier["Math verifier<br/>[verifier.py]"]
end

subgraph group_generation["Reply generation"]
  node_prompts["Prompt assembly<br/>[prompt_registry.py]"]
  node_llm["Streaming LLM client<br/>[llm_client.py]"]
  node_parser["Response parser<br/>[response_parser.py]"]
end

subgraph group_evaluation["Evaluation tools"]
  node_baseline["Baseline runner<br/>[baseline_runner.py]"]
  node_answer_extract["Answer extraction"]
  node_transcript_score["Transcript scorer"]
  node_rating["Rating agreement"]
  node_eval_results[("Evaluation artifacts<br/>[results.py]")]
end

node_student(("Student"))
node_providers{{"Groq and HF providers"}}

node_student -->|"submits question"| node_chat
node_app -->|"routes to"| node_chat
node_app -->|"initializes"| node_session
node_chat -->|"queues turn"| node_episode
node_episode -->|"processes turn"| node_pipeline
node_pipeline -->|"checks input"| node_safety
node_pipeline -->|"checks scope"| node_scope
node_pipeline -->|"resolves question"| node_resolver
node_pipeline -->|"retrieves context"| node_retrieval
node_pipeline -->|"computes answer"| node_verifier
node_pipeline -->|"classifies intent"| node_intent
node_pipeline -->|"selects action"| node_controller
node_pipeline -->|"builds prompt"| node_prompts
node_pipeline -->|"requests generation"| node_llm
node_llm -->|"streams from"| node_providers
node_pipeline -->|"cleans response"| node_parser
node_pipeline -->|"checks response"| node_verifier
node_pipeline -->|"records attempts"| node_tracker
node_pipeline -->|"logs interaction"| node_telemetry
node_episode -->|"returns reply"| node_chat
node_session -->|"reads learner profile"| node_tracker
node_baseline -->|"requests generation"| node_llm
node_baseline -->|"parses response"| node_parser
node_transcript_score -->|"extracts answers"| node_answer_extract
node_transcript_score -->|"scores checkpoints"| node_baseline
node_rating -->|"uses extraction"| node_answer_extract
node_rating -->|"uses scores"| node_transcript_score

click node_app "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/frontend/app.py"
click node_session "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/frontend/state.py"
click node_chat "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/frontend/views/main_page.py"
click node_episode "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/frontend/episode.py"
click node_pipeline "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/pipeline.py"
click node_safety "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/safety.py"
click node_scope "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/scope.py"
click node_resolver "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/conversation_resolver.py"
click node_intent "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/intent.py"
click node_controller "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/controller.py"
click node_retrieval "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/retrieval.py"
click node_verifier "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/verifier.py"
click node_prompts "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/prompt_registry.py"
click node_llm "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/llm_client.py"
click node_parser "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/response_parser.py"
click node_tracker "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/student_tracker.py"
click node_telemetry "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/telemetry.py"
click node_baseline "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/eval/baseline_runner.py"
click node_answer_extract "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/eval/answer_extraction.py"
click node_transcript_score "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/eval/score_transcripts.py"
click node_rating "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/eval/rating_agreement.py"
click node_eval_results "https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/eval/component_eval/results.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_session,node_chat toneBlue
class node_episode,node_pipeline,node_safety,node_scope,node_resolver,node_intent,node_controller,node_tracker,node_telemetry toneAmber
class node_retrieval,node_verifier toneMint
class node_prompts,node_llm,node_parser toneRose
class node_baseline,node_answer_extract,node_transcript_score,node_rating,node_eval_results,node_student,node_providers toneIndigo
```

## Components

### Student experience

- [App router](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/frontend/app.py): `frontend/app.py`
- [Session and profile](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/frontend/state.py): `frontend/state.py`
- [Chat interface](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/frontend/views/main_page.py): `frontend/views/main_page.py`

### Turn orchestration

- [Episode handler](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/frontend/episode.py): `frontend/episode.py`
- [Turn pipeline](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/pipeline.py): `scripts/llm/pipeline.py`
- [Input and output safety](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/safety.py): `scripts/llm/safety.py`
- [Syllabus scope gate](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/scope.py): `scripts/llm/scope.py`
- [Conversation resolver](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/conversation_resolver.py): `scripts/llm/conversation_resolver.py`
- [Intent classifier](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/intent.py): `scripts/llm/intent.py`
- [Tutoring state machine](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/controller.py): `scripts/llm/controller.py`
- [Learner progress tracker](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/student_tracker.py): `scripts/llm/student_tracker.py`
- [Interaction telemetry](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/telemetry.py): `scripts/llm/telemetry.py`

### Math and curriculum grounding

- [Hybrid curriculum retrieval](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/retrieval.py): `scripts/retrieval.py`
- [Math verifier](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/verifier.py): `scripts/llm/verifier.py`

### Reply generation

- [Prompt assembly](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/prompt_registry.py): `scripts/llm/prompt_registry.py`
- [Streaming LLM client](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/llm_client.py): `scripts/llm/llm_client.py`
- [Response parser](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/scripts/llm/response_parser.py): `scripts/llm/response_parser.py`

### Evaluation tools

- [Baseline runner](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/eval/baseline_runner.py): `eval/baseline_runner.py`
- [Answer extraction](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/eval/answer_extraction.py): `eval/answer_extraction.py`
- [Transcript scorer](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/eval/score_transcripts.py): `eval/score_transcripts.py`
- [Rating agreement](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/eval/rating_agreement.py): `eval/rating_agreement.py`
- [Evaluation artifacts](https://github.com/bhanavikochhar/llm-based-math-tutor/blob/main/eval/component_eval/results.py): `eval/component_eval/results.py`

### Other components

- **Student**
- **Groq and HF providers**

## Connections

- Student → Chat interface: submits question
- App router → Chat interface: routes to (evidence: `frontend/app.py`)
- App router → Session and profile: initializes (evidence: `frontend/app.py`)
- Chat interface → Episode handler: queues turn (evidence: `frontend/views/main_page.py`)
- Episode handler → Turn pipeline: processes turn (evidence: `frontend/episode.py`)
- Turn pipeline → Input and output safety: checks input
- Turn pipeline → Syllabus scope gate: checks scope
- Turn pipeline → Conversation resolver: resolves question (evidence: `scripts/llm/pipeline.py`)
- Turn pipeline → Hybrid curriculum retrieval: retrieves context (evidence: `scripts/llm/pipeline.py`)
- Turn pipeline → Math verifier: computes answer (evidence: `scripts/llm/pipeline.py`)
- Turn pipeline → Intent classifier: classifies intent
- Turn pipeline → Tutoring state machine: selects action (evidence: `scripts/llm/pipeline.py`)
- Turn pipeline → Prompt assembly: builds prompt (evidence: `scripts/llm/pipeline.py`)
- Turn pipeline → Streaming LLM client: requests generation (evidence: `scripts/llm/pipeline.py`)
- Streaming LLM client → Groq and HF providers: streams from (evidence: `scripts/llm/llm_client.py`)
- Turn pipeline → Response parser: cleans response (evidence: `scripts/llm/pipeline.py`)
- Turn pipeline → Math verifier: checks response (evidence: `scripts/llm/pipeline.py`)
- Turn pipeline → Learner progress tracker: records attempts (evidence: `scripts/llm/pipeline.py`)
- Turn pipeline → Interaction telemetry: logs interaction
- Episode handler → Chat interface: returns reply (evidence: `frontend/views/main_page.py`)
- Session and profile → Learner progress tracker: reads learner profile (evidence: `frontend/state.py`)
- Baseline runner → Streaming LLM client: requests generation (evidence: `eval/baseline_runner.py`)
- Baseline runner → Response parser: parses response (evidence: `eval/baseline_runner.py`)
- Transcript scorer → Answer extraction: extracts answers (evidence: `eval/score_transcripts.py`)
- Transcript scorer → Baseline runner: scores checkpoints (evidence: `eval/score_transcripts.py`)
- Rating agreement → Answer extraction: uses extraction (evidence: `eval/rating_agreement.py`)
- Rating agreement → Transcript scorer: uses scores (evidence: `eval/rating_agreement.py`)
