# jys0615/agent-khu architecture

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

- Interactive diagram: https://gitdiagram.com/jys0615/agent-khu
- Repository: https://github.com/jys0615/agent-khu

## Overview

Agent KHU is a personalized campus-information assistant. A student uses the React app to sign in and ask a question; the backend loads session context, routes simple questions through SLM/RAG or complex ones through Claude tool use, calls campus MCP services, then returns a response (including SSE streaming). The map includes the documented domain services and storage. Some MCP implementations and routing code were not excerpted, so their documented connections are cited to the README rather than inferred from names.

Main entry points: [`backend/app/mcp_client.py`](https://github.com/jys0615/agent-khu/blob/main/backend/app/mcp_client.py) (MCP HTTP client), [`backend/app/agent/complex_handler.py`](https://github.com/jys0615/agent-khu/blob/main/backend/app/agent/complex_handler.py) (Agent loop), [`frontend/src/App.tsx`](https://github.com/jys0615/agent-khu/blob/main/frontend/src/App.tsx) (React app), [`backend/app/routers/auth.py`](https://github.com/jys0615/agent-khu/blob/main/backend/app/routers/auth.py) (Authentication routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Student application"]
  node_webapp["React app<br/>[App.tsx]"]
  node_chatui["Chat interface<br/>[ChatInterface.tsx]"]
  node_chatapi["Chat API client<br/>[chat.ts]"]
  node_authapi["Auth API client<br/>[auth.ts]"]
end

subgraph group_backend["AI and API"]
  node_stream["Chat stream route<br/>[chat_stream.py]"]
  node_agent["Agent loop<br/>[complex_handler.py]"]
  node_executor["Tool executor<br/>[tool_executor.py]"]
  node_tooldefs["Tool definitions"]
  node_slm["SLM classifier<br/>[slm_agent.py]"]
  node_rag["RAG search<br/>[rag_agent.py]"]
  node_result["Response builder<br/>[result_builder.py]"]
  node_mcpclient["MCP HTTP client<br/>[mcp_client.py]"]
  node_authroute["Authentication routes<br/>[auth.py]"]
end

subgraph group_state["Persistence and memory"]
  node_redis[("Redis cache and sessions<br/>[cache.py]")]
  node_db[("PostgreSQL data<br/>[database.py]")]
end

subgraph group_campus["Campus information services"]
  node_classroom["Classroom service<br/>[server.py]"]
  node_notice["Notice service<br/>[server.py]"]
  node_meal["Meal service<br/>[server.py]"]
  node_library["Library service<br/>[server.py]"]
  node_course["Course service<br/>[server.py]"]
  node_curriculum["Curriculum service<br/>[server.py]"]
  node_shuttle["Shuttle service<br/>[server.py]"]
end

subgraph group_sources["Campus data sources"]
  node_mealdata["Meal scraper<br/>[scraper.py]"]
  node_librarydata["Library scraper<br/>[library_scraper.py]"]
  node_noticedata["Notice crawler<br/>[crawler.py]"]
end

node_student(("Student"))
node_external(("Campus websites"))

node_student -->|"uses"| node_webapp
node_webapp -->|"renders"| node_chatui
node_chatui -.->|"submits question"| node_chatapi
node_chatapi -->|"requests SSE"| node_stream
node_webapp -.->|"authenticates"| node_authapi
node_authapi -->|"calls auth API"| node_authroute
node_stream -->|"routes question"| node_agent
node_agent -->|"classifies"| node_slm
node_agent -->|"searches simple query"| node_rag
node_agent -->|"dispatches tools"| node_executor
node_agent -->|"selects tools"| node_tooldefs
node_executor -->|"calls tools"| node_mcpclient
node_agent -->|"builds response"| node_result
node_agent -->|"loads and saves turns"| node_redis
node_authroute -->|"caches credentials"| node_redis
node_authroute -->|"reads and writes users"| node_db
node_mcpclient -->|"calls over HTTP"| node_classroom
node_mcpclient -->|"calls over HTTP"| node_notice
node_mcpclient -->|"calls over HTTP"| node_meal
node_mcpclient -->|"calls over HTTP"| node_library
node_mcpclient -->|"calls over HTTP"| node_course
node_mcpclient -->|"calls over HTTP"| node_curriculum
node_mcpclient -->|"calls over HTTP"| node_shuttle
node_classroom -->|"queries"| node_db
node_meal -->|"uses"| node_mealdata
node_library -->|"uses"| node_librarydata
node_notice -->|"uses"| node_noticedata
node_mealdata -.->|"fetches menus"| node_external
node_noticedata -.->|"crawls notices"| node_external
node_librarydata -.->|"fetches availability"| node_external

click node_webapp "https://github.com/jys0615/agent-khu/blob/main/frontend/src/App.tsx"
click node_chatui "https://github.com/jys0615/agent-khu/blob/main/frontend/src/components/ChatInterface.tsx"
click node_chatapi "https://github.com/jys0615/agent-khu/blob/main/frontend/src/api/chat.ts"
click node_authapi "https://github.com/jys0615/agent-khu/blob/main/frontend/src/api/auth.ts"
click node_stream "https://github.com/jys0615/agent-khu/blob/main/backend/app/routers/chat_stream.py"
click node_agent "https://github.com/jys0615/agent-khu/blob/main/backend/app/agent/complex_handler.py"
click node_executor "https://github.com/jys0615/agent-khu/blob/main/backend/app/agent/tool_executor.py"
click node_tooldefs "https://github.com/jys0615/agent-khu/blob/main/backend/app/agent/tools_definition.py"
click node_slm "https://github.com/jys0615/agent-khu/blob/main/backend/app/slm_agent.py"
click node_rag "https://github.com/jys0615/agent-khu/blob/main/backend/app/rag_agent.py"
click node_result "https://github.com/jys0615/agent-khu/blob/main/backend/app/agent/result_builder.py"
click node_mcpclient "https://github.com/jys0615/agent-khu/blob/main/backend/app/mcp_client.py"
click node_authroute "https://github.com/jys0615/agent-khu/blob/main/backend/app/routers/auth.py"
click node_redis "https://github.com/jys0615/agent-khu/blob/main/backend/app/cache.py"
click node_db "https://github.com/jys0615/agent-khu/blob/main/backend/app/database.py"
click node_classroom "https://github.com/jys0615/agent-khu/blob/main/mcp-servers/classroom-mcp/server.py"
click node_notice "https://github.com/jys0615/agent-khu/blob/main/mcp-servers/notice-mcp/server.py"
click node_meal "https://github.com/jys0615/agent-khu/blob/main/mcp-servers/meal-mcp/server.py"
click node_library "https://github.com/jys0615/agent-khu/blob/main/mcp-servers/library-mcp/server.py"
click node_course "https://github.com/jys0615/agent-khu/blob/main/mcp-servers/course-mcp/server.py"
click node_curriculum "https://github.com/jys0615/agent-khu/blob/main/mcp-servers/curriculum-mcp/server.py"
click node_shuttle "https://github.com/jys0615/agent-khu/blob/main/mcp-servers/shuttle-mcp/server.py"
click node_mealdata "https://github.com/jys0615/agent-khu/blob/main/mcp-servers/meal-mcp/scraper.py"
click node_librarydata "https://github.com/jys0615/agent-khu/blob/main/mcp-servers/library-mcp/scrapers/library_scraper.py"
click node_noticedata "https://github.com/jys0615/agent-khu/blob/main/mcp-servers/notice-mcp/crawler.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_webapp,node_chatui,node_chatapi,node_authapi toneBlue
class node_stream,node_agent,node_executor,node_tooldefs,node_slm,node_rag,node_result,node_mcpclient,node_authroute toneAmber
class node_redis,node_db toneMint
class node_classroom,node_notice,node_meal,node_library,node_course,node_curriculum,node_shuttle toneRose
class node_mealdata,node_librarydata,node_noticedata,node_student,node_external toneIndigo
```

## Components

### Student application

- [React app](https://github.com/jys0615/agent-khu/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Chat interface](https://github.com/jys0615/agent-khu/blob/main/frontend/src/components/ChatInterface.tsx): `frontend/src/components/ChatInterface.tsx`
- [Chat API client](https://github.com/jys0615/agent-khu/blob/main/frontend/src/api/chat.ts): `frontend/src/api/chat.ts`
- [Auth API client](https://github.com/jys0615/agent-khu/blob/main/frontend/src/api/auth.ts): `frontend/src/api/auth.ts`

### AI and API

- [Chat stream route](https://github.com/jys0615/agent-khu/blob/main/backend/app/routers/chat_stream.py): `backend/app/routers/chat_stream.py`
- [Agent loop](https://github.com/jys0615/agent-khu/blob/main/backend/app/agent/complex_handler.py): `backend/app/agent/complex_handler.py`
- [Tool executor](https://github.com/jys0615/agent-khu/blob/main/backend/app/agent/tool_executor.py): `backend/app/agent/tool_executor.py`
- [Tool definitions](https://github.com/jys0615/agent-khu/blob/main/backend/app/agent/tools_definition.py): `backend/app/agent/tools_definition.py`
- [SLM classifier](https://github.com/jys0615/agent-khu/blob/main/backend/app/slm_agent.py): `backend/app/slm_agent.py`
- [RAG search](https://github.com/jys0615/agent-khu/blob/main/backend/app/rag_agent.py): `backend/app/rag_agent.py`
- [Response builder](https://github.com/jys0615/agent-khu/blob/main/backend/app/agent/result_builder.py): `backend/app/agent/result_builder.py`
- [MCP HTTP client](https://github.com/jys0615/agent-khu/blob/main/backend/app/mcp_client.py): `backend/app/mcp_client.py`
- [Authentication routes](https://github.com/jys0615/agent-khu/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`

### Persistence and memory

- [Redis cache and sessions](https://github.com/jys0615/agent-khu/blob/main/backend/app/cache.py): `backend/app/cache.py`
- [PostgreSQL data](https://github.com/jys0615/agent-khu/blob/main/backend/app/database.py): `backend/app/database.py`

### Campus information services

- [Classroom service](https://github.com/jys0615/agent-khu/blob/main/mcp-servers/classroom-mcp/server.py): `mcp-servers/classroom-mcp/server.py`
- [Notice service](https://github.com/jys0615/agent-khu/blob/main/mcp-servers/notice-mcp/server.py): `mcp-servers/notice-mcp/server.py`
- [Meal service](https://github.com/jys0615/agent-khu/blob/main/mcp-servers/meal-mcp/server.py): `mcp-servers/meal-mcp/server.py`
- [Library service](https://github.com/jys0615/agent-khu/blob/main/mcp-servers/library-mcp/server.py): `mcp-servers/library-mcp/server.py`
- [Course service](https://github.com/jys0615/agent-khu/blob/main/mcp-servers/course-mcp/server.py): `mcp-servers/course-mcp/server.py`
- [Curriculum service](https://github.com/jys0615/agent-khu/blob/main/mcp-servers/curriculum-mcp/server.py): `mcp-servers/curriculum-mcp/server.py`
- [Shuttle service](https://github.com/jys0615/agent-khu/blob/main/mcp-servers/shuttle-mcp/server.py): `mcp-servers/shuttle-mcp/server.py`

### Campus data sources

- [Meal scraper](https://github.com/jys0615/agent-khu/blob/main/mcp-servers/meal-mcp/scraper.py): `mcp-servers/meal-mcp/scraper.py`
- [Library scraper](https://github.com/jys0615/agent-khu/blob/main/mcp-servers/library-mcp/scrapers/library_scraper.py): `mcp-servers/library-mcp/scrapers/library_scraper.py`
- [Notice crawler](https://github.com/jys0615/agent-khu/blob/main/mcp-servers/notice-mcp/crawler.py): `mcp-servers/notice-mcp/crawler.py`

### Other components

- **Student**
- **Campus websites**

## Connections

- Student → React app: uses (evidence: `README.md`)
- React app → Chat interface: renders (evidence: `frontend/src/App.tsx`)
- Chat interface → Chat API client: submits question
- Chat API client → Chat stream route: requests SSE (evidence: `README.md`)
- React app → Auth API client: authenticates
- Auth API client → Authentication routes: calls auth API (evidence: `frontend/src/api/auth.ts`)
- Chat stream route → Agent loop: routes question (evidence: `README.md`)
- Agent loop → SLM classifier: classifies (evidence: `README.md`)
- Agent loop → RAG search: searches simple query (evidence: `README.md`)
- Agent loop → Tool executor: dispatches tools (evidence: `backend/app/agent/complex_handler.py`)
- Agent loop → Tool definitions: selects tools (evidence: `backend/app/agent/complex_handler.py`)
- Tool executor → MCP HTTP client: calls tools (evidence: `backend/app/agent/tool_executor.py`)
- Agent loop → Response builder: builds response (evidence: `backend/app/agent/complex_handler.py`)
- Agent loop → Redis cache and sessions: loads and saves turns (evidence: `README.md`)
- Authentication routes → Redis cache and sessions: caches credentials (evidence: `backend/app/routers/auth.py`)
- Authentication routes → PostgreSQL data: reads and writes users (evidence: `backend/app/routers/auth.py`)
- MCP HTTP client → Classroom service: calls over HTTP (evidence: `README.md`)
- MCP HTTP client → Notice service: calls over HTTP (evidence: `README.md`)
- MCP HTTP client → Meal service: calls over HTTP (evidence: `README.md`)
- MCP HTTP client → Library service: calls over HTTP (evidence: `README.md`)
- MCP HTTP client → Course service: calls over HTTP (evidence: `README.md`)
- MCP HTTP client → Curriculum service: calls over HTTP (evidence: `README.md`)
- MCP HTTP client → Shuttle service: calls over HTTP (evidence: `README.md`)
- Classroom service → PostgreSQL data: queries (evidence: `mcp-servers/classroom-mcp/server.py`)
- Meal service → Meal scraper: uses
- Library service → Library scraper: uses
- Notice service → Notice crawler: uses
- Meal scraper → Campus websites: fetches menus
- Notice crawler → Campus websites: crawls notices
- Library scraper → Campus websites: fetches availability
