# santosh-sankranthi/study-buddy architecture

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

- Interactive diagram: https://gitdiagram.com/santosh-sankranthi/study-buddy
- Repository: https://github.com/santosh-sankranthi/study-buddy

## Overview

Study Buddy is the small AI-tutor product inside a teaching workshop repository; the numbered phases and archived material teach how it evolves, rather than forming runtime product subsystems. The user-facing flow is a chat request to the FastAPI backend, which can apply safety checks, assemble prompts and session context, call an LLM or agent tools, then return an answer. The README also documents structured study endpoints, persistent notes, MCP tools, and evaluation reports. Some integration links below are documented capabilities rather than inspected call sites.

Main entry points: [`app/main.py`](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/main.py) (Tutor API), [`common/llm.py`](https://github.com/santosh-sankranthi/study-buddy/blob/main/common/llm.py) (LLM Client), [`app/agent.py`](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/agent.py) (Agent Loop), [`app/memory.py`](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/memory.py) (Session Memory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Tutor API"]
  node_api["Tutor API<br/>[main.py]"]
  node_prompts["Prompt Builder<br/>[prompts.py]"]
  node_schemas["Output Schemas<br/>[schemas.py]"]
  node_safety["Safety Filters<br/>[security.py]"]
  node_evaluation["Evaluation Reports<br/>[judge.py]"]
  node_v3["Milestone v3<br/>[main.py]"]
  node_v4["Milestone v4<br/>[main.py]"]
  node_v5["Milestone v5<br/>[main.py]"]
  node_v6["Milestone v6<br/>[main.py]"]
end

subgraph group_conversation["Conversation Context"]
  node_context["Context Budget<br/>[context.py]"]
  node_memory["Session Memory<br/>[memory.py]"]
  node_tokens["Token Counting<br/>[tokens.py]"]
end

subgraph group_agent["Agent Tools"]
  node_agent["Agent Loop<br/>[agent.py]"]
  node_tools["Study Tools<br/>[tools.py]"]
  node_notes[("Persistent Notes<br/>[notes_store.py]")]
  node_mcpserver["MCP Server<br/>[server.py]"]
end

subgraph group_integrations["Model Integrations"]
  node_llm["LLM Client<br/>[llm.py]"]
  node_mcpclient["MCP Client<br/>[mcp_client.py]"]
end

node_student(("Student"))
node_providers{{"LLM Providers"}}
node_externalmcp{{"External MCP Server"}}

node_student -->|"sends chat"| node_api
node_api -->|"sanitizes input"| node_safety
node_api -->|"builds prompts"| node_prompts
node_api -->|"validates output"| node_schemas
node_api -->|"checks budget"| node_context
node_api -->|"loads and saves"| node_memory
node_api -->|"runs agent"| node_agent
node_api -->|"uses MCP"| node_mcpclient
node_api -->|"requests completion"| node_llm
node_api -.->|"reports evaluations"| node_evaluation
node_context -->|"counts tokens"| node_tokens
node_memory -->|"budgets history"| node_tokens
node_memory -->|"summarizes history"| node_llm
node_agent -->|"requests tool calls"| node_llm
node_agent -->|"executes calls"| node_tools
node_tools -->|"reads and writes"| node_notes
node_mcpserver -.->|"exposes tools"| node_tools
node_mcpserver -.->|"uses notes"| node_notes
node_safety -->|"moderates output"| node_llm
node_llm -.->|"calls provider"| node_providers
node_mcpclient -.->|"connects to server"| node_externalmcp
node_v3 -.->|"adds agent support"| node_agent
node_v4 -.->|"adds MCP support"| node_mcpclient
node_v5 -.->|"adds safety"| node_safety
node_v6 -.->|"is live milestone"| node_api

click node_api "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/main.py"
click node_prompts "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/prompts.py"
click node_schemas "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/schemas.py"
click node_safety "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/security.py"
click node_evaluation "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/evals/judge.py"
click node_context "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/context.py"
click node_memory "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/memory.py"
click node_tokens "https://github.com/santosh-sankranthi/study-buddy/blob/main/common/tokens.py"
click node_agent "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/agent.py"
click node_tools "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/tools.py"
click node_notes "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/notes_store.py"
click node_mcpserver "https://github.com/santosh-sankranthi/study-buddy/blob/main/mcp_server/server.py"
click node_llm "https://github.com/santosh-sankranthi/study-buddy/blob/main/common/llm.py"
click node_mcpclient "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/mcp_client.py"
click node_v3 "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/versions/v3/main.py"
click node_v4 "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/versions/v4/main.py"
click node_v5 "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/versions/v5/main.py"
click node_v6 "https://github.com/santosh-sankranthi/study-buddy/blob/main/app/versions/v6/main.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_api,node_prompts,node_schemas,node_safety,node_evaluation,node_v3,node_v4,node_v5,node_v6 toneBlue
class node_context,node_memory,node_tokens toneAmber
class node_agent,node_tools,node_notes,node_mcpserver,node_externalmcp toneMint
class node_llm,node_mcpclient toneRose
class node_student,node_providers toneIndigo
```

## Components

### Tutor API

- [Tutor API](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/main.py): `app/main.py`
- [Prompt Builder](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/prompts.py): `app/prompts.py`
- [Output Schemas](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/schemas.py): `app/schemas.py`
- [Safety Filters](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/security.py): `app/security.py`
- [Evaluation Reports](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/evals/judge.py): `app/evals/judge.py`
- [Milestone v3](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/versions/v3/main.py): `app/versions/v3/main.py`
- [Milestone v4](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/versions/v4/main.py): `app/versions/v4/main.py`
- [Milestone v5](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/versions/v5/main.py): `app/versions/v5/main.py`
- [Milestone v6](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/versions/v6/main.py): `app/versions/v6/main.py`

### Conversation Context

- [Context Budget](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/context.py): `app/context.py`
- [Session Memory](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/memory.py): `app/memory.py`
- [Token Counting](https://github.com/santosh-sankranthi/study-buddy/blob/main/common/tokens.py): `common/tokens.py`

### Agent Tools

- [Agent Loop](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/agent.py): `app/agent.py`
- [Study Tools](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/tools.py): `app/tools.py`
- [Persistent Notes](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/notes_store.py): `app/notes_store.py`
- [MCP Server](https://github.com/santosh-sankranthi/study-buddy/blob/main/mcp_server/server.py): `mcp_server/server.py`

### Model Integrations

- [LLM Client](https://github.com/santosh-sankranthi/study-buddy/blob/main/common/llm.py): `common/llm.py`
- [MCP Client](https://github.com/santosh-sankranthi/study-buddy/blob/main/app/mcp_client.py): `app/mcp_client.py`

### Other components

- **Student**
- **LLM Providers**
- **External MCP Server**

## Connections

- Student → Tutor API: sends chat
- Tutor API → Safety Filters: sanitizes input (evidence: `app/main.py`)
- Tutor API → Prompt Builder: builds prompts (evidence: `app/main.py`)
- Tutor API → Output Schemas: validates output (evidence: `app/main.py`)
- Tutor API → Context Budget: checks budget (evidence: `app/main.py`)
- Tutor API → Session Memory: loads and saves (evidence: `app/main.py`)
- Tutor API → Agent Loop: runs agent (evidence: `app/main.py`)
- Tutor API → MCP Client: uses MCP (evidence: `app/main.py`)
- Tutor API → LLM Client: requests completion (evidence: `app/main.py`)
- Tutor API → Evaluation Reports: reports evaluations
- Context Budget → Token Counting: counts tokens (evidence: `app/context.py`)
- Session Memory → Token Counting: budgets history (evidence: `app/memory.py`)
- Session Memory → LLM Client: summarizes history (evidence: `app/memory.py`)
- Agent Loop → LLM Client: requests tool calls (evidence: `app/agent.py`)
- Agent Loop → Study Tools: executes calls (evidence: `app/agent.py`)
- Study Tools → Persistent Notes: reads and writes (evidence: `app/tools.py`)
- MCP Server → Study Tools: exposes tools (evidence: `mcp_server/server.py`)
- MCP Server → Persistent Notes: uses notes (evidence: `mcp_server/server.py`)
- Safety Filters → LLM Client: moderates output (evidence: `app/security.py`)
- LLM Client → LLM Providers: calls provider
- MCP Client → External MCP Server: connects to server
- Milestone v3 → Agent Loop: adds agent support (evidence: `app/versions/v3/main.py`)
- Milestone v4 → MCP Client: adds MCP support (evidence: `app/versions/v4/main.py`)
- Milestone v5 → Safety Filters: adds safety (evidence: `app/versions/v5/main.py`)
- Milestone v6 → Tutor API: is live milestone
