# xiaoxiaohexin/study-room architecture

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

- Interactive diagram: https://gitdiagram.com/xiaoxiaohexin/study-room
- Repository: https://github.com/xiaoxiaohexin/study-room

## Overview

Study Room is a local-first learning assistant, with a customized llama.cpp WebUI and a FastAPI backend. The main workflow is a learner asking a question, the backend coordinating an agent response using session history, learning intent, memory, and optional RAG context, then returning the result to the interface. Other documented capabilities include document ingestion, quizzes and spaced repetition, knowledge notes, and memory management. Some route and tool implementations were not sampled, so those links are omitted or marked unverified.

Main entry points: [`app/agent/loop.py`](https://github.com/xiaoxiaohexin/study-room/blob/main/app/agent/loop.py) (ReAct agent), [`app/rag/retriever.py`](https://github.com/xiaoxiaohexin/study-room/blob/main/app/rag/retriever.py) (RAG retrieval), [`app/main.py`](https://github.com/xiaoxiaohexin/study-room/blob/main/app/main.py) (FastAPI routes), [`app/context/builder.py`](https://github.com/xiaoxiaohexin/study-room/blob/main/app/context/builder.py) (Context builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_webui["Study WebUI<br/>[ChatScreen.svelte]"]
end

subgraph group_runtime["Agent runtime"]
  node_api["FastAPI routes<br/>[main.py]"]
  node_chat_routes["Chat and compat routes<br/>[chat.py]"]
  node_agent["ReAct agent<br/>[loop.py]"]
  node_context["Context builder<br/>[builder.py]"]
  node_llm["LLM client<br/>[base.py]"]
  node_session["Session state<br/>[state_manager.py]"]
  node_mcp["MCP tools<br/>[mcp_client.py]"]
end

subgraph group_learning["Learning and memory"]
  node_intent["Intent router<br/>[router.py]"]
  node_memory["Memory manager<br/>[manager.py]"]
  node_learning_tools["Learning tools<br/>[learning_tools.py]"]
  node_learning_store[("Learning store<br/>[store.py]")]
  node_memory_types[("Four-layer memory<br/>[working.py]")]
end

subgraph group_knowledge["Knowledge and storage"]
  node_rag_routes["RAG routes<br/>[rag.py]"]
  node_ingestion["Document ingestion<br/>[pipeline.py]"]
  node_retriever["RAG retrieval<br/>[retriever.py]"]
  node_embedder["Embedding provider<br/>[embedding.py]"]
  node_vector_store[("Vector store<br/>[vector.py]")]
  node_sqlite[("SQLite storage<br/>[sqlite.py]")]
  node_query_expander["Query expansion<br/>[expansion.py]"]
end

node_learner(("Learner"))

node_learner -->|"asks question"| node_webui
node_webui -.->|"sends requests"| node_api
node_api -->|"registers routes"| node_chat_routes
node_api -->|"registers routes"| node_rag_routes
node_chat_routes -.->|"dispatches chat"| node_agent
node_agent -->|"routes intent"| node_intent
node_agent -->|"builds context"| node_context
node_agent -->|"requests completion"| node_llm
node_agent -->|"loads history"| node_session
node_agent -->|"retrieves memories"| node_memory
node_agent -->|"expands queries"| node_query_expander
node_intent -->|"checks pending question"| node_learning_store
node_context -->|"uses retrieved docs"| node_retriever
node_context -->|"uses memory items"| node_memory_types
node_session -->|"reads and writes"| node_sqlite
node_retriever -->|"embeds queries"| node_embedder
node_retriever -->|"searches vectors"| node_vector_store
node_ingestion -->|"embeds chunks"| node_embedder
node_ingestion -->|"stores chunks"| node_vector_store
node_rag_routes -->|"imports documents"| node_ingestion
node_rag_routes -->|"runs searches"| node_retriever
node_agent -.->|"dispatches tools"| node_learning_tools
node_learning_tools -.->|"updates learning state"| node_learning_store
node_memory -.->|"retrieves and stores"| node_memory_types
node_agent -.->|"uses optional tools"| node_mcp

click node_webui "https://github.com/xiaoxiaohexin/study-room/blob/main/llama-webui/tools/ui/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte"
click node_api "https://github.com/xiaoxiaohexin/study-room/blob/main/app/main.py"
click node_chat_routes "https://github.com/xiaoxiaohexin/study-room/blob/main/app/api/routes/chat.py"
click node_agent "https://github.com/xiaoxiaohexin/study-room/blob/main/app/agent/loop.py"
click node_intent "https://github.com/xiaoxiaohexin/study-room/blob/main/app/learning/router.py"
click node_context "https://github.com/xiaoxiaohexin/study-room/blob/main/app/context/builder.py"
click node_llm "https://github.com/xiaoxiaohexin/study-room/blob/main/app/llm/base.py"
click node_session "https://github.com/xiaoxiaohexin/study-room/blob/main/app/session/state_manager.py"
click node_memory "https://github.com/xiaoxiaohexin/study-room/blob/main/app/memory/manager.py"
click node_learning_tools "https://github.com/xiaoxiaohexin/study-room/blob/main/app/tools/builtin/learning_tools.py"
click node_learning_store "https://github.com/xiaoxiaohexin/study-room/blob/main/app/learning/store.py"
click node_memory_types "https://github.com/xiaoxiaohexin/study-room/blob/main/app/memory/working.py"
click node_rag_routes "https://github.com/xiaoxiaohexin/study-room/blob/main/app/api/routes/rag.py"
click node_ingestion "https://github.com/xiaoxiaohexin/study-room/blob/main/app/rag/pipeline.py"
click node_retriever "https://github.com/xiaoxiaohexin/study-room/blob/main/app/rag/retriever.py"
click node_embedder "https://github.com/xiaoxiaohexin/study-room/blob/main/app/llm/embedding.py"
click node_vector_store "https://github.com/xiaoxiaohexin/study-room/blob/main/app/storage/vector.py"
click node_sqlite "https://github.com/xiaoxiaohexin/study-room/blob/main/app/storage/sqlite.py"
click node_query_expander "https://github.com/xiaoxiaohexin/study-room/blob/main/app/query/expansion.py"
click node_mcp "https://github.com/xiaoxiaohexin/study-room/blob/main/app/tools/protocols/mcp_client.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_webui toneBlue
class node_api,node_chat_routes,node_agent,node_context,node_llm,node_session,node_mcp toneAmber
class node_intent,node_memory,node_learning_tools,node_learning_store,node_memory_types toneMint
class node_rag_routes,node_ingestion,node_retriever,node_embedder,node_vector_store,node_sqlite,node_query_expander toneRose
class node_learner toneIndigo
```

## Components

### User interface

- [Study WebUI](https://github.com/xiaoxiaohexin/study-room/blob/main/llama-webui/tools/ui/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte): `llama-webui/tools/ui/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte`

### Agent runtime

- [FastAPI routes](https://github.com/xiaoxiaohexin/study-room/blob/main/app/main.py): `app/main.py`
- [Chat and compat routes](https://github.com/xiaoxiaohexin/study-room/blob/main/app/api/routes/chat.py): `app/api/routes/chat.py`
- [ReAct agent](https://github.com/xiaoxiaohexin/study-room/blob/main/app/agent/loop.py): `app/agent/loop.py`
- [Context builder](https://github.com/xiaoxiaohexin/study-room/blob/main/app/context/builder.py): `app/context/builder.py`
- [LLM client](https://github.com/xiaoxiaohexin/study-room/blob/main/app/llm/base.py): `app/llm/base.py`
- [Session state](https://github.com/xiaoxiaohexin/study-room/blob/main/app/session/state_manager.py): `app/session/state_manager.py`
- [MCP tools](https://github.com/xiaoxiaohexin/study-room/blob/main/app/tools/protocols/mcp_client.py): `app/tools/protocols/mcp_client.py`

### Learning and memory

- [Intent router](https://github.com/xiaoxiaohexin/study-room/blob/main/app/learning/router.py): `app/learning/router.py`
- [Memory manager](https://github.com/xiaoxiaohexin/study-room/blob/main/app/memory/manager.py): `app/memory/manager.py`
- [Learning tools](https://github.com/xiaoxiaohexin/study-room/blob/main/app/tools/builtin/learning_tools.py): `app/tools/builtin/learning_tools.py`
- [Learning store](https://github.com/xiaoxiaohexin/study-room/blob/main/app/learning/store.py): `app/learning/store.py`
- [Four-layer memory](https://github.com/xiaoxiaohexin/study-room/blob/main/app/memory/working.py): `app/memory/working.py`

### Knowledge and storage

- [RAG routes](https://github.com/xiaoxiaohexin/study-room/blob/main/app/api/routes/rag.py): `app/api/routes/rag.py`
- [Document ingestion](https://github.com/xiaoxiaohexin/study-room/blob/main/app/rag/pipeline.py): `app/rag/pipeline.py`
- [RAG retrieval](https://github.com/xiaoxiaohexin/study-room/blob/main/app/rag/retriever.py): `app/rag/retriever.py`
- [Embedding provider](https://github.com/xiaoxiaohexin/study-room/blob/main/app/llm/embedding.py): `app/llm/embedding.py`
- [Vector store](https://github.com/xiaoxiaohexin/study-room/blob/main/app/storage/vector.py): `app/storage/vector.py`
- [SQLite storage](https://github.com/xiaoxiaohexin/study-room/blob/main/app/storage/sqlite.py): `app/storage/sqlite.py`
- [Query expansion](https://github.com/xiaoxiaohexin/study-room/blob/main/app/query/expansion.py): `app/query/expansion.py`

### Other components

- **Learner**

## Connections

- Learner → Study WebUI: asks question (evidence: `README.md`)
- Study WebUI → FastAPI routes: sends requests (evidence: `README.md`)
- FastAPI routes → Chat and compat routes: registers routes (evidence: `app/main.py`)
- FastAPI routes → RAG routes: registers routes (evidence: `app/main.py`)
- Chat and compat routes → ReAct agent: dispatches chat
- ReAct agent → Intent router: routes intent (evidence: `app/agent/loop.py`)
- ReAct agent → Context builder: builds context (evidence: `app/agent/loop.py`)
- ReAct agent → LLM client: requests completion (evidence: `app/agent/loop.py`)
- ReAct agent → Session state: loads history (evidence: `app/agent/loop.py`)
- ReAct agent → Memory manager: retrieves memories (evidence: `app/agent/loop.py`)
- ReAct agent → Query expansion: expands queries (evidence: `app/agent/loop.py`)
- Intent router → Learning store: checks pending question (evidence: `app/learning/router.py`)
- Context builder → RAG retrieval: uses retrieved docs (evidence: `app/context/builder.py`)
- Context builder → Four-layer memory: uses memory items (evidence: `app/context/builder.py`)
- Session state → SQLite storage: reads and writes (evidence: `app/session/state_manager.py`)
- RAG retrieval → Embedding provider: embeds queries (evidence: `app/rag/retriever.py`)
- RAG retrieval → Vector store: searches vectors (evidence: `app/rag/retriever.py`)
- Document ingestion → Embedding provider: embeds chunks (evidence: `app/rag/pipeline.py`)
- Document ingestion → Vector store: stores chunks (evidence: `app/rag/pipeline.py`)
- RAG routes → Document ingestion: imports documents (evidence: `app/api/routes/rag.py`)
- RAG routes → RAG retrieval: runs searches (evidence: `app/api/routes/rag.py`)
- ReAct agent → Learning tools: dispatches tools
- Learning tools → Learning store: updates learning state
- Memory manager → Four-layer memory: retrieves and stores
- ReAct agent → MCP tools: uses optional tools
