# bhargavreddy098/kantha-agent architecture

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

- Interactive diagram: https://gitdiagram.com/bhargavreddy098/kantha-agent
- Repository: https://github.com/bhargavreddy098/kantha-agent

## Overview

Kantha is a local developer workbench: users chat with a model, or attach a workspace so the API server can run tools, read files, and propose edits subject to approval. The browser presents chat, settings, and inspection; the server owns sessions and coordinates orchestration, providers, permissions, and persistence. The README documents these capabilities, while the excerpts and source index expose only selected wiring, so unsampled subsystem connections are omitted rather than inferred.

Main entry points: [`packages/server/src/router.ts`](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/router.ts) (Request Router), [`packages/orchestrator/src/graph.ts`](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/orchestrator/src/graph.ts) (Agent Graph), [`packages/providers/src/service.ts`](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/providers/src/service.ts) (Provider Service), [`apps/web/src/features/chat/ChatWorkspace.tsx`](https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/features/chat/ChatWorkspace.tsx) (Chat Workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workbench["Workbench UI"]
  node_webapp["Workbench App<br/>[App.tsx]"]
  node_chat["Chat Workspace<br/>[ChatWorkspace.tsx]"]
  node_settings["Provider Settings"]
  node_inspector["Gateway Inspector"]
  node_browserdb[("Browser Chat Cache<br/>[chatDb.ts]")]
  node_providerui["Provider API Client<br/>[providerService.ts]"]
  node_harnessui["Workspace API Client<br/>[harnessService.ts]"]
end

subgraph group_server["API Server"]
  node_http["HTTP API<br/>[http.ts]"]
  node_router["Request Router<br/>[router.ts]"]
  node_sessions["Session Routes<br/>[sessions.ts]"]
  node_gatewayroute["Gateway Routes<br/>[gateway.ts]"]
  node_workspaceroute["Workspace Routes<br/>[workspace.ts]"]
end

subgraph group_execution["Session Execution"]
  node_runner["Session Runner<br/>[runner.ts]"]
  node_graph["Agent Graph<br/>[graph.ts]"]
  node_compaction["Context Compaction<br/>[compaction.ts]"]
  node_toolset["Workspace Tools"]
  node_permissions["Approvals and Questions"]
end

subgraph group_inference["Model Gateway"]
  node_providerui_service["Provider Service<br/>[service.ts]"]
  node_inferenceclient["Inference Client<br/>[client.ts]"]
  node_bifrost["Bifrost Client<br/>[client.ts]"]
  node_catalog["Model Catalog<br/>[service.ts]"]
  node_ssrf["Endpoint Guard<br/>[ssrf.ts]"]
end

subgraph group_support["State and Integrations"]
  node_database[("Session Database<br/>[index.ts]")]
  node_events[("Session Event Store<br/>[session-events.ts]")]
  node_mcp["MCP Integration<br/>[client.ts]"]
  node_pty["Terminal Manager<br/>[manager.ts]"]
end

node_developer(("Developer"))
node_cli["Pairing CLI<br/>[index.ts]"]
node_externalmodel{{"Model Endpoint"}}

node_developer -->|"uses"| node_webapp
node_developer -->|"pairs with"| node_cli
node_webapp -->|"renders"| node_chat
node_chat -.->|"requests inference"| node_providerui
node_chat -.->|"requests workspace tasks"| node_harnessui
node_chat -->|"caches display state"| node_browserdb
node_settings -.->|"configures providers"| node_providerui
node_inspector -.->|"queries gateway"| node_providerui
node_providerui -->|"calls API"| node_http
node_harnessui -->|"calls API"| node_http
node_cli -->|"pairs with server"| node_http
node_http -->|"routes requests"| node_router
node_router -->|"dispatches sessions"| node_sessions
node_router -->|"dispatches gateway"| node_gatewayroute
node_router -->|"dispatches workspace"| node_workspaceroute
node_router -->|"opens database"| node_database
node_sessions -->|"starts session runs"| node_runner
node_runner -.->|"runs graph"| node_graph
node_graph -->|"manages context"| node_compaction
node_graph -->|"resolves tools"| node_toolset
node_graph -.->|"checks approvals"| node_permissions
node_graph -.->|"requests inference"| node_providerui_service
node_sessions -.->|"persists session events"| node_events
node_gatewayroute -.->|"uses gateway"| node_providerui_service
node_providerui_service -->|"loads catalog"| node_catalog
node_providerui_service -->|"generates inference"| node_inferenceclient
node_inferenceclient -->|"builds provider client"| node_bifrost
node_bifrost -->|"validates endpoint"| node_ssrf
node_bifrost -.->|"fetches model data"| node_externalmodel
node_providerui_service -.->|"sends inference"| node_externalmodel
node_router -.->|"routes terminal access"| node_pty
node_graph -.->|"uses MCP tools"| node_mcp

click node_cli "https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/cli/src/index.ts"
click node_webapp "https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/App.tsx"
click node_chat "https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/features/chat/ChatWorkspace.tsx"
click node_settings "https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/features/settings/ModelProvidersPanel.tsx"
click node_inspector "https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/features/inspector/GatewayInspector.tsx"
click node_browserdb "https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/db/chatDb.ts"
click node_providerui "https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/services/providerService.ts"
click node_harnessui "https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/services/harnessService.ts"
click node_http "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/http.ts"
click node_router "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/router.ts"
click node_sessions "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/routes/sessions.ts"
click node_gatewayroute "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/routes/gateway.ts"
click node_workspaceroute "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/routes/workspace.ts"
click node_runner "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/orchestrator/src/runner.ts"
click node_graph "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/orchestrator/src/graph.ts"
click node_compaction "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/orchestrator/src/compaction.ts"
click node_toolset "https://github.com/bhargavreddy098/kantha-agent/tree/main/packages/tools"
click node_permissions "https://github.com/bhargavreddy098/kantha-agent/tree/main/packages/permissions"
click node_providerui_service "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/providers/src/service.ts"
click node_inferenceclient "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/providers/src/inference/client.ts"
click node_bifrost "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/providers/src/bifrost/client.ts"
click node_catalog "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/providers/src/catalog/service.ts"
click node_ssrf "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/providers/src/compat/ssrf.ts"
click node_database "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/database/src/index.ts"
click node_events "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/database/src/session-events.ts"
click node_mcp "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/mcp/src/client.ts"
click node_pty "https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/pty/manager.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_webapp,node_chat,node_settings,node_inspector,node_browserdb,node_providerui,node_harnessui toneBlue
class node_http,node_router,node_sessions,node_gatewayroute,node_workspaceroute toneAmber
class node_runner,node_graph,node_compaction,node_toolset,node_permissions toneMint
class node_providerui_service,node_inferenceclient,node_bifrost,node_catalog,node_ssrf toneRose
class node_database,node_events,node_mcp,node_pty,node_developer,node_externalmodel toneIndigo
class node_cli toneTeal
```

## Components

### Workbench UI

- [Workbench App](https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/App.tsx): `apps/web/src/App.tsx`
- [Chat Workspace](https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/features/chat/ChatWorkspace.tsx): `apps/web/src/features/chat/ChatWorkspace.tsx`
- [Provider Settings](https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/features/settings/ModelProvidersPanel.tsx): `apps/web/src/features/settings/ModelProvidersPanel.tsx`
- [Gateway Inspector](https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/features/inspector/GatewayInspector.tsx): `apps/web/src/features/inspector/GatewayInspector.tsx`
- [Browser Chat Cache](https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/db/chatDb.ts): `apps/web/src/db/chatDb.ts`
- [Provider API Client](https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/services/providerService.ts): `apps/web/src/services/providerService.ts`
- [Workspace API Client](https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/web/src/services/harnessService.ts): `apps/web/src/services/harnessService.ts`

### API Server

- [HTTP API](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/http.ts): `packages/server/src/http.ts`
- [Request Router](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/router.ts): `packages/server/src/router.ts`
- [Session Routes](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/routes/sessions.ts): `packages/server/src/routes/sessions.ts`
- [Gateway Routes](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/routes/gateway.ts): `packages/server/src/routes/gateway.ts`
- [Workspace Routes](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/routes/workspace.ts): `packages/server/src/routes/workspace.ts`

### Session Execution

- [Session Runner](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/orchestrator/src/runner.ts): `packages/orchestrator/src/runner.ts`
- [Agent Graph](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/orchestrator/src/graph.ts): `packages/orchestrator/src/graph.ts`
- [Context Compaction](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/orchestrator/src/compaction.ts): `packages/orchestrator/src/compaction.ts`
- [Workspace Tools](https://github.com/bhargavreddy098/kantha-agent/tree/main/packages/tools): `packages/tools`
- [Approvals and Questions](https://github.com/bhargavreddy098/kantha-agent/tree/main/packages/permissions): `packages/permissions`

### Model Gateway

- [Provider Service](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/providers/src/service.ts): `packages/providers/src/service.ts`
- [Inference Client](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/providers/src/inference/client.ts): `packages/providers/src/inference/client.ts`
- [Bifrost Client](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/providers/src/bifrost/client.ts): `packages/providers/src/bifrost/client.ts`
- [Model Catalog](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/providers/src/catalog/service.ts): `packages/providers/src/catalog/service.ts`
- [Endpoint Guard](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/providers/src/compat/ssrf.ts): `packages/providers/src/compat/ssrf.ts`

### State and Integrations

- [Session Database](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/database/src/index.ts): `packages/database/src/index.ts`
- [Session Event Store](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/database/src/session-events.ts): `packages/database/src/session-events.ts`
- [MCP Integration](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/mcp/src/client.ts): `packages/mcp/src/client.ts`
- [Terminal Manager](https://github.com/bhargavreddy098/kantha-agent/blob/main/packages/server/src/pty/manager.ts): `packages/server/src/pty/manager.ts`

### Other components

- **Developer**
- [Pairing CLI](https://github.com/bhargavreddy098/kantha-agent/blob/main/apps/cli/src/index.ts): `apps/cli/src/index.ts`
- **Model Endpoint**

## Connections

- Developer → Workbench App: uses (evidence: `README.md`)
- Developer → Pairing CLI: pairs with (evidence: `README.md`)
- Workbench App → Chat Workspace: renders (evidence: `apps/web/src/App.tsx`)
- Chat Workspace → Provider API Client: requests inference
- Chat Workspace → Workspace API Client: requests workspace tasks
- Chat Workspace → Browser Chat Cache: caches display state (evidence: `README.md`)
- Provider Settings → Provider API Client: configures providers
- Gateway Inspector → Provider API Client: queries gateway
- Provider API Client → HTTP API: calls API (evidence: `README.md`)
- Workspace API Client → HTTP API: calls API (evidence: `README.md`)
- Pairing CLI → HTTP API: pairs with server (evidence: `README.md`)
- HTTP API → Request Router: routes requests (evidence: `packages/server/src/router.ts`)
- Request Router → Session Routes: dispatches sessions (evidence: `packages/server/src/router.ts`)
- Request Router → Gateway Routes: dispatches gateway (evidence: `packages/server/src/router.ts`)
- Request Router → Workspace Routes: dispatches workspace (evidence: `packages/server/src/router.ts`)
- Request Router → Session Database: opens database (evidence: `packages/server/src/router.ts`)
- Session Routes → Session Runner: starts session runs (evidence: `packages/server/src/routes/sessions.ts`)
- Session Runner → Agent Graph: runs graph
- Agent Graph → Context Compaction: manages context (evidence: `packages/orchestrator/src/graph.ts`)
- Agent Graph → Workspace Tools: resolves tools (evidence: `packages/orchestrator/src/graph.ts`)
- Agent Graph → Approvals and Questions: checks approvals (evidence: `packages/orchestrator/src/graph.ts`)
- Agent Graph → Provider Service: requests inference
- Session Routes → Session Event Store: persists session events
- Gateway Routes → Provider Service: uses gateway
- Provider Service → Model Catalog: loads catalog (evidence: `packages/providers/src/service.ts`)
- Provider Service → Inference Client: generates inference (evidence: `packages/providers/src/service.ts`)
- Inference Client → Bifrost Client: builds provider client (evidence: `packages/providers/src/inference/client.ts`)
- Bifrost Client → Endpoint Guard: validates endpoint (evidence: `packages/providers/src/bifrost/client.ts`)
- Bifrost Client → Model Endpoint: fetches model data
- Provider Service → Model Endpoint: sends inference
- Request Router → Terminal Manager: routes terminal access (evidence: `packages/server/src/router.ts`)
- Agent Graph → MCP Integration: uses MCP tools
