# team-skyjs/kbap-pm-agent architecture

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

- Interactive diagram: https://gitdiagram.com/team-skyjs/kbap-pm-agent
- Repository: https://github.com/team-skyjs/kbap-pm-agent

## Overview

K-Bap PM Agent is a web app for product managers: users chat with an agent to investigate product metrics and a codebase, then review and refine experiment or funnel proposals. The frontend routes conversations and settings, while the backend serves the API, runs agent/tool workflows, and persists conversations and usage. The README is empty, so product capabilities are inferred from the provided source index and excerpts; unsampled subsystem behavior and some frontend-to-backend wiring are not independently verified.

Main entry points: [`backend/app/agent.py`](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/agent.py) (Agent orchestration), [`backend/app/main.py`](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/main.py) (HTTP API), [`backend/app/db.py`](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/db.py) (Application database), [`frontend/src/Chat.tsx`](https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/Chat.tsx) (Conversation chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["App routing<br/>[App.tsx]"]
  node_chat["Conversation chat<br/>[Chat.tsx]"]
  node_proposal_ui["Proposal review<br/>[ProposalCard.tsx]"]
  node_refine_ui["Proposal refinement<br/>[refine.ts]"]
  node_settings_ui["Settings screen<br/>[SettingsPage.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["API and conversations"]
  node_http_api["HTTP API<br/>[main.py]"]
  node_conversations["Conversation workflow<br/>[conversations.py]"]
  node_refinement["Proposal refinement<br/>[refine.py]"]
end

subgraph group_agent["Analysis and integrations"]
  node_agent_core["Agent orchestration<br/>[agent.py]"]
  node_anthropic["Anthropic runtime<br/>[agent_anthropic.py]"]
  node_openai["OpenAI runtime<br/>[agent_openai.py]"]
  node_code_tools["Codebase analysis<br/>[code_tools.py]"]
  node_repo["Repository indexing<br/>[repo.py]"]
  node_amplitude["Amplitude integration<br/>[amplitude.py]"]
end

subgraph group_state["Persistence and controls"]
  node_db[("Application database<br/>[db.py]")]
  node_budget["LLM budget tracking<br/>[budget.py]"]
  node_schemas["Proposal contracts<br/>[schemas.py]"]
end

node_user(("Product manager"))
node_amplitude_service{{"Amplitude MCP"}}
node_llm_service{{"LLM providers"}}

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_chat
node_app -->|"routes to"| node_settings_ui
node_chat -->|"requests"| node_api_client
node_chat -->|"renders"| node_proposal_ui
node_chat -->|"uses"| node_refine_ui
node_settings_ui -->|"requests"| node_api_client
node_api_client -.->|"sends API requests"| node_http_api
node_http_api -->|"routes to"| node_conversations
node_http_api -->|"routes to"| node_refinement
node_http_api -->|"checks health"| node_db
node_conversations -->|"runs agent"| node_agent_core
node_conversations -->|"persists conversations"| node_db
node_refinement -->|"runs refinement"| node_agent_core
node_refinement -->|"reads and writes"| node_db
node_agent_core -->|"dispatches"| node_anthropic
node_agent_core -->|"dispatches"| node_openai
node_agent_core -->|"invokes tools"| node_code_tools
node_agent_core -->|"uses repository data"| node_repo
node_agent_core -->|"records usage"| node_budget
node_agent_core -->|"validates answers"| node_schemas
node_anthropic -->|"calls"| node_llm_service
node_openai -->|"calls"| node_llm_service
node_code_tools -->|"queries codebase"| node_repo
node_code_tools -->|"checks budget"| node_budget
node_repo -->|"stores repository state"| node_db
node_budget -->|"records usage"| node_db
node_amplitude -->|"stores OAuth state"| node_db
node_amplitude -->|"connects and queries"| node_amplitude_service
node_agent_core -.->|"uses analytics tools"| node_amplitude
node_http_api -->|"mounts routes"| node_amplitude
node_http_api -->|"initializes"| node_db

click node_app "https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/App.tsx"
click node_chat "https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/Chat.tsx"
click node_proposal_ui "https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/ProposalCard.tsx"
click node_refine_ui "https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/refine.ts"
click node_settings_ui "https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/SettingsPage.tsx"
click node_api_client "https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/api.ts"
click node_http_api "https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/main.py"
click node_conversations "https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/conversations.py"
click node_refinement "https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/refine.py"
click node_agent_core "https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/agent.py"
click node_anthropic "https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/agent_anthropic.py"
click node_openai "https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/agent_openai.py"
click node_code_tools "https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/code_tools.py"
click node_repo "https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/repo.py"
click node_amplitude "https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/amplitude.py"
click node_db "https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/db.py"
click node_budget "https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/budget.py"
click node_schemas "https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/schemas.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_chat,node_proposal_ui,node_refine_ui,node_settings_ui,node_api_client toneBlue
class node_http_api,node_conversations,node_refinement toneAmber
class node_agent_core,node_anthropic,node_openai,node_code_tools,node_repo,node_amplitude toneMint
class node_db,node_budget,node_schemas toneRose
class node_user,node_amplitude_service,node_llm_service toneIndigo
```

## Components

### Web application

- [App routing](https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Conversation chat](https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/Chat.tsx): `frontend/src/Chat.tsx`
- [Proposal review](https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/ProposalCard.tsx): `frontend/src/ProposalCard.tsx`
- [Proposal refinement](https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/refine.ts): `frontend/src/refine.ts`
- [Settings screen](https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/SettingsPage.tsx): `frontend/src/SettingsPage.tsx`
- [API client](https://github.com/team-skyjs/kbap-pm-agent/blob/main/frontend/src/api.ts): `frontend/src/api.ts`

### API and conversations

- [HTTP API](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/main.py): `backend/app/main.py`
- [Conversation workflow](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/conversations.py): `backend/app/conversations.py`
- [Proposal refinement](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/refine.py): `backend/app/refine.py`

### Analysis and integrations

- [Agent orchestration](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/agent.py): `backend/app/agent.py`
- [Anthropic runtime](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/agent_anthropic.py): `backend/app/agent_anthropic.py`
- [OpenAI runtime](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/agent_openai.py): `backend/app/agent_openai.py`
- [Codebase analysis](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/code_tools.py): `backend/app/code_tools.py`
- [Repository indexing](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/repo.py): `backend/app/repo.py`
- [Amplitude integration](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/amplitude.py): `backend/app/amplitude.py`

### Persistence and controls

- [Application database](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/db.py): `backend/app/db.py`
- [LLM budget tracking](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/budget.py): `backend/app/budget.py`
- [Proposal contracts](https://github.com/team-skyjs/kbap-pm-agent/blob/main/backend/app/schemas.py): `backend/app/schemas.py`

### Other components

- **Product manager**
- **Amplitude MCP**
- **LLM providers**

## Connections

- Product manager → App routing: uses (evidence: `frontend/src/App.tsx`)
- App routing → Conversation chat: routes to (evidence: `frontend/src/App.tsx`)
- App routing → Settings screen: routes to (evidence: `frontend/src/App.tsx`)
- Conversation chat → API client: requests (evidence: `frontend/src/Chat.tsx`)
- Conversation chat → Proposal review: renders (evidence: `frontend/src/Chat.tsx`)
- Conversation chat → Proposal refinement: uses (evidence: `frontend/src/Chat.tsx`)
- Settings screen → API client: requests (evidence: `frontend/src/SettingsPage.tsx`)
- API client → HTTP API: sends API requests
- HTTP API → Conversation workflow: routes to (evidence: `backend/app/main.py`)
- HTTP API → Proposal refinement: routes to (evidence: `backend/app/main.py`)
- HTTP API → Application database: checks health (evidence: `backend/app/main.py`)
- Conversation workflow → Agent orchestration: runs agent (evidence: `backend/app/conversations.py`)
- Conversation workflow → Application database: persists conversations (evidence: `backend/app/conversations.py`)
- Proposal refinement → Agent orchestration: runs refinement (evidence: `backend/app/refine.py`)
- Proposal refinement → Application database: reads and writes (evidence: `backend/app/refine.py`)
- Agent orchestration → Anthropic runtime: dispatches (evidence: `backend/app/agent.py`)
- Agent orchestration → OpenAI runtime: dispatches (evidence: `backend/app/agent.py`)
- Agent orchestration → Codebase analysis: invokes tools (evidence: `backend/app/agent.py`)
- Agent orchestration → Repository indexing: uses repository data (evidence: `backend/app/agent.py`)
- Agent orchestration → LLM budget tracking: records usage (evidence: `backend/app/agent.py`)
- Agent orchestration → Proposal contracts: validates answers (evidence: `backend/app/agent.py`)
- Anthropic runtime → LLM providers: calls (evidence: `backend/app/agent_anthropic.py`)
- OpenAI runtime → LLM providers: calls (evidence: `backend/app/agent_openai.py`)
- Codebase analysis → Repository indexing: queries codebase (evidence: `backend/app/code_tools.py`)
- Codebase analysis → LLM budget tracking: checks budget (evidence: `backend/app/code_tools.py`)
- Repository indexing → Application database: stores repository state (evidence: `backend/app/repo.py`)
- LLM budget tracking → Application database: records usage (evidence: `backend/app/budget.py`)
- Amplitude integration → Application database: stores OAuth state (evidence: `backend/app/amplitude.py`)
- Amplitude integration → Amplitude MCP: connects and queries (evidence: `backend/app/amplitude.py`)
- Agent orchestration → Amplitude integration: uses analytics tools (evidence: `backend/app/amplitude.py`)
- HTTP API → Amplitude integration: mounts routes (evidence: `backend/app/main.py`)
- HTTP API → Application database: initializes (evidence: `backend/app/main.py`)
