# songf0140/campusoverflow_hwa architecture

> Architecture diagram of the GitHub repository songf0140/campusoverflow_hwa, 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/songf0140/campusoverflow_hwa
- Repository: https://github.com/songf0140/campusoverflow_hwa

## Overview

CampusOverflow AI is a course-centered campus Q&A and community platform, with a documented second-stage Agent Runtime. The main user path is browser pages through the Next.js same-origin BFF to FastAPI, where identity and permissions gate course, question-and-answer, and interaction operations backed by MySQL. Discovery adds search and recommendations; governance provides an initial schema-and-placeholder boundary. The README also describes planned AI assistance, MCP, persistent memory, and human approvals, but the checked-in Agent tree is only a small runtime skeleton. Those planned links are documentation-based, not evidence of implemented end-to-end flows.

Main entry points: [`campus-overflow-ai/backend/app/main.py`](https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/backend/app/main.py) (FastAPI assembly), [`campus-overflow-ai/agent/src/app.ts`](https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/agent/src/app.ts) (Agent service), [`campus-overflow-ai/backend/app/modules/identity`](https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/identity) (Identity and profiles), [`campus-overflow-ai/backend/app/modules/discovery`](https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/discovery) (Search and discovery)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_pages["Student and teacher pages"]
  node_features["Domain UI"]
  node_api["API client"]
  node_bff["Next.js BFF"]
end

subgraph group_backend["Business API"]
  node_backend_app["FastAPI assembly<br/>[main.py]"]
  node_identity["Identity and profiles"]
  node_permissions["Access control<br/>[permissions.py]"]
  node_courses["Course spaces"]
  node_qa["Questions and answers"]
  node_interaction["Votes and reputation"]
  node_discovery["Search and discovery"]
  node_governance["Content governance"]
  node_core["Shared API core<br/>[response.py]"]
end

subgraph group_data["Persistence"]
  node_db_session["Database sessions<br/>[session.py]"]
  node_mysql[("MySQL store")]
end

subgraph group_agent["Agent extension"]
  node_agent_ui["AI and MCP tools<br/>[registry.ts]"]
  node_agent_runtime["Agent service<br/>[app.ts]"]
end

node_browser(("Campus user"))
node_model{{"Model and MCP services"}}
node_admin(("Human approver"))

node_browser -->|"uses"| node_pages
node_pages -.->|"renders"| node_features
node_features -.->|"requests data"| node_api
node_api -->|"same-origin calls"| node_bff
node_bff -->|"forwards requests"| node_backend_app
node_bff -->|"forwards AI requests"| node_agent_runtime
node_backend_app -->|"registers routes"| node_identity
node_backend_app -->|"registers routes"| node_courses
node_backend_app -->|"registers routes"| node_qa
node_backend_app -->|"registers routes"| node_interaction
node_backend_app -->|"registers routes"| node_discovery
node_backend_app -->|"registers routes"| node_governance
node_backend_app -->|"configures responses"| node_core
node_permissions -->|"loads user identity"| node_identity
node_permissions -->|"gets session"| node_db_session
node_identity -.->|"uses sessions"| node_db_session
node_courses -->|"looks up users"| node_identity
node_qa -->|"checks course access"| node_courses
node_interaction -->|"coordinates content"| node_qa
node_interaction -->|"adjusts reputation"| node_identity
node_discovery -->|"queries courses"| node_courses
node_discovery -->|"queries questions"| node_qa
node_discovery -->|"adds vote state"| node_interaction
node_backend_app -.->|"serves database sessions"| node_db_session
node_db_session -->|"persists data"| node_mysql
node_agent_runtime -->|"uses tool registry"| node_agent_ui
node_agent_ui -.->|"calls allowlisted API"| node_backend_app
node_agent_runtime -.->|"generates assistance"| node_model
node_agent_runtime -.->|"connects MCP tools"| node_model
node_agent_runtime -.->|"requests approval"| node_admin

click node_pages "https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/frontend/src/app"
click node_features "https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/frontend/src/features"
click node_api "https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/frontend/src/api"
click node_bff "https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/frontend/src/app/api"
click node_backend_app "https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/backend/app/main.py"
click node_identity "https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/identity"
click node_permissions "https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/backend/app/core/permissions.py"
click node_courses "https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/courses"
click node_qa "https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/qa"
click node_interaction "https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/interaction"
click node_discovery "https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/discovery"
click node_governance "https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/governance"
click node_core "https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/backend/app/core/response.py"
click node_db_session "https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/backend/app/db/session.py"
click node_agent_ui "https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/agent/src/tools/registry.ts"
click node_agent_runtime "https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/agent/src/app.ts"

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_pages,node_features,node_api,node_bff,node_browser toneBlue
class node_backend_app,node_identity,node_permissions,node_courses,node_qa,node_interaction,node_discovery,node_governance,node_core toneAmber
class node_db_session,node_mysql toneMint
class node_agent_ui,node_agent_runtime toneRose
class node_model,node_admin toneIndigo
```

## Components

### Web experience

- [Student and teacher pages](https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/frontend/src/app): `campus-overflow-ai/frontend/src/app`
- [Domain UI](https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/frontend/src/features): `campus-overflow-ai/frontend/src/features`
- [API client](https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/frontend/src/api): `campus-overflow-ai/frontend/src/api`
- [Next.js BFF](https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/frontend/src/app/api): `campus-overflow-ai/frontend/src/app/api`

### Business API

- [FastAPI assembly](https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/backend/app/main.py): `campus-overflow-ai/backend/app/main.py`
- [Identity and profiles](https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/identity): `campus-overflow-ai/backend/app/modules/identity`
- [Access control](https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/backend/app/core/permissions.py): `campus-overflow-ai/backend/app/core/permissions.py`
- [Course spaces](https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/courses): `campus-overflow-ai/backend/app/modules/courses`
- [Questions and answers](https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/qa): `campus-overflow-ai/backend/app/modules/qa`
- [Votes and reputation](https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/interaction): `campus-overflow-ai/backend/app/modules/interaction`
- [Search and discovery](https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/discovery): `campus-overflow-ai/backend/app/modules/discovery`
- [Content governance](https://github.com/songf0140/campusoverflow_hwa/tree/main/campus-overflow-ai/backend/app/modules/governance): `campus-overflow-ai/backend/app/modules/governance`
- [Shared API core](https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/backend/app/core/response.py): `campus-overflow-ai/backend/app/core/response.py`

### Persistence

- [Database sessions](https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/backend/app/db/session.py): `campus-overflow-ai/backend/app/db/session.py`
- **MySQL store**

### Agent extension

- [AI and MCP tools](https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/agent/src/tools/registry.ts): `campus-overflow-ai/agent/src/tools/registry.ts`
- [Agent service](https://github.com/songf0140/campusoverflow_hwa/blob/main/campus-overflow-ai/agent/src/app.ts): `campus-overflow-ai/agent/src/app.ts`

### Other components

- **Campus user**
- **Model and MCP services**
- **Human approver**

## Connections

- Campus user → Student and teacher pages: uses (evidence: `README.md`)
- Student and teacher pages → Domain UI: renders (evidence: `README.md`)
- Domain UI → API client: requests data (evidence: `README.md`)
- API client → Next.js BFF: same-origin calls (evidence: `README.md`)
- Next.js BFF → FastAPI assembly: forwards requests (evidence: `README.md`)
- Next.js BFF → Agent service: forwards AI requests (evidence: `README.md`)
- FastAPI assembly → Identity and profiles: registers routes (evidence: `campus-overflow-ai/backend/app/main.py`)
- FastAPI assembly → Course spaces: registers routes (evidence: `campus-overflow-ai/backend/app/main.py`)
- FastAPI assembly → Questions and answers: registers routes (evidence: `campus-overflow-ai/backend/app/main.py`)
- FastAPI assembly → Votes and reputation: registers routes (evidence: `campus-overflow-ai/backend/app/main.py`)
- FastAPI assembly → Search and discovery: registers routes (evidence: `campus-overflow-ai/backend/app/main.py`)
- FastAPI assembly → Content governance: registers routes (evidence: `campus-overflow-ai/backend/app/main.py`)
- FastAPI assembly → Shared API core: configures responses (evidence: `campus-overflow-ai/backend/app/main.py`)
- Access control → Identity and profiles: loads user identity (evidence: `campus-overflow-ai/backend/app/core/permissions.py`)
- Access control → Database sessions: gets session (evidence: `campus-overflow-ai/backend/app/core/permissions.py`)
- Identity and profiles → Database sessions: uses sessions (evidence: `campus-overflow-ai/backend/app/modules/identity/router.py`)
- Course spaces → Identity and profiles: looks up users (evidence: `campus-overflow-ai/backend/app/modules/courses/service.py`)
- Questions and answers → Course spaces: checks course access (evidence: `campus-overflow-ai/backend/app/modules/qa/service.py`)
- Votes and reputation → Questions and answers: coordinates content (evidence: `campus-overflow-ai/backend/app/modules/interaction/service.py`)
- Votes and reputation → Identity and profiles: adjusts reputation (evidence: `campus-overflow-ai/backend/app/modules/interaction/service.py`)
- Search and discovery → Course spaces: queries courses (evidence: `campus-overflow-ai/backend/app/modules/discovery/service.py`)
- Search and discovery → Questions and answers: queries questions (evidence: `campus-overflow-ai/backend/app/modules/discovery/service.py`)
- Search and discovery → Votes and reputation: adds vote state (evidence: `campus-overflow-ai/backend/app/modules/discovery/service.py`)
- FastAPI assembly → Database sessions: serves database sessions
- Database sessions → MySQL store: persists data (evidence: `README.md`)
- Agent service → AI and MCP tools: uses tool registry
- AI and MCP tools → FastAPI assembly: calls allowlisted API (evidence: `README.md`)
- Agent service → Model and MCP services: generates assistance (evidence: `README.md`)
- Agent service → Model and MCP services: connects MCP tools (evidence: `README.md`)
- Agent service → Human approver: requests approval (evidence: `README.md`)
