# harishbabu2007/kapexai architecture

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

- Interactive diagram: https://gitdiagram.com/harishbabu2007/kapexai
- Repository: https://github.com/harishbabu2007/kapexai

## Overview

KapexAI is a business-consulting chatbot whose main workflow takes a user from business-profile setup through questionnaire and conversation to research, inline analysis, or a dashboard report. The frontend manages chat sessions and renders streamed results; the FastAPI backend authenticates users, accepts chat jobs, and streams worker output. The worker plans each turn, dispatches registered subagents, and composes results. The README documents the broader analysis capabilities; some agent implementations were not sampled, so those branches are shown without inferred internal call details.

Main entry points: [`backend/main.py`](https://github.com/harishbabu2007/kapexai/blob/main/backend/main.py) (Chat API and WebSocket), [`worker/orchestrator/orchestrator.py`](https://github.com/harishbabu2007/kapexai/blob/main/worker/orchestrator/orchestrator.py) (Turn orchestrator), [`frontend/src/hooks/useChatSession.ts`](https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/hooks/useChatSession.ts) (Session state), [`services/redis-service/redis_service/client.py`](https://github.com/harishbabu2007/kapexai/blob/main/services/redis-service/redis_service/client.py) (Queue and stream store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["User experience"]
  node_app["App routes<br/>[App.tsx]"]
  node_profile["Business profile"]
  node_chat["Chat workspace<br/>[ChatPage.tsx]"]
  node_session["Session state<br/>[useChatSession.ts]"]
  node_api_client["API client<br/>[api.ts]"]
  node_result_views["Message and dashboard views<br/>[index.tsx]"]
end

subgraph group_backend["API and streaming"]
  node_backend_api["Chat API and WebSocket<br/>[main.py]"]
  node_auth_routes["Google authentication<br/>[auth.py]"]
  node_auth_middleware["Request authentication<br/>[auth.py]"]
end

subgraph group_worker["Worker orchestration"]
  node_worker_main["Job consumer<br/>[main.py]"]
  node_job_handler["Job processing<br/>[agent.py]"]
  node_orchestrator["Turn orchestrator<br/>[orchestrator.py]"]
  node_planner["Mode planner<br/>[planner.py]"]
  node_composer["Response composer<br/>[composer.py]"]
  node_dashboard_builder["Dashboard builder"]
end

subgraph group_agents["Consulting capabilities"]
  node_agent_registry["Subagent registry<br/>[registry.py]"]
  node_domain_agents["Consulting subagents"]
  node_llm["LLM provider<br/>[llm.py]"]
end

subgraph group_data["Persistence and services"]
  node_postgres[("Conversation database<br/>[client.py]")]
  node_redis[("Queue and stream store<br/>[client.py]")]
end

node_user(("Business user"))
node_business_idea["Business idea"]
node_external_services["LLM and search providers"]

node_user -->|"opens"| node_app
node_app -->|"routes to"| node_profile
node_app -->|"routes to"| node_chat
node_user -->|"describes"| node_business_idea
node_chat -->|"uses"| node_session
node_session -->|"requests"| node_api_client
node_api_client -.->|"calls"| node_backend_api
node_backend_api -->|"routes authentication"| node_auth_routes
node_backend_api -->|"reads and writes"| node_postgres
node_backend_api -->|"queues jobs"| node_redis
node_redis -->|"delivers jobs"| node_worker_main
node_worker_main -->|"processes job"| node_job_handler
node_job_handler -->|"handles turn"| node_orchestrator
node_orchestrator -->|"plans turn"| node_planner
node_orchestrator -->|"dispatches subagents"| node_agent_registry
node_orchestrator -->|"commits response"| node_composer
node_orchestrator -->|"builds dashboard"| node_dashboard_builder
node_planner -->|"selects capabilities"| node_agent_registry
node_agent_registry -->|"registers"| node_domain_agents
node_domain_agents -.->|"uses model"| node_llm
node_llm -->|"calls provider"| node_external_services
node_domain_agents -.->|"searches web"| node_external_services
node_composer -->|"persists messages"| node_postgres
node_composer -->|"publishes frames"| node_redis
node_backend_api -->|"reads stream frames"| node_redis
node_backend_api -.->|"streams results"| node_session
node_session -.->|"renders results"| node_result_views
node_result_views -.->|"shows analysis"| node_user
node_auth_routes -->|"loads user"| node_postgres
node_auth_middleware -->|"validates user"| node_postgres

click node_app "https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/App.tsx"
click node_profile "https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/pages/BusinessProfilePage.tsx"
click node_chat "https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/pages/ChatPage.tsx"
click node_session "https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/hooks/useChatSession.ts"
click node_api_client "https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/lib/api.ts"
click node_result_views "https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/components/messages/index.tsx"
click node_backend_api "https://github.com/harishbabu2007/kapexai/blob/main/backend/main.py"
click node_auth_routes "https://github.com/harishbabu2007/kapexai/blob/main/backend/routers/auth.py"
click node_auth_middleware "https://github.com/harishbabu2007/kapexai/blob/main/backend/middleware/auth.py"
click node_worker_main "https://github.com/harishbabu2007/kapexai/blob/main/worker/main.py"
click node_job_handler "https://github.com/harishbabu2007/kapexai/blob/main/worker/agent.py"
click node_orchestrator "https://github.com/harishbabu2007/kapexai/blob/main/worker/orchestrator/orchestrator.py"
click node_planner "https://github.com/harishbabu2007/kapexai/blob/main/worker/orchestrator/planner.py"
click node_composer "https://github.com/harishbabu2007/kapexai/blob/main/worker/orchestrator/composer.py"
click node_dashboard_builder "https://github.com/harishbabu2007/kapexai/blob/main/worker/orchestrator/dashboard_builder.py"
click node_agent_registry "https://github.com/harishbabu2007/kapexai/blob/main/worker/agents/registry.py"
click node_domain_agents "https://github.com/harishbabu2007/kapexai/tree/main/worker/agents"
click node_llm "https://github.com/harishbabu2007/kapexai/blob/main/worker/llm.py"
click node_postgres "https://github.com/harishbabu2007/kapexai/blob/main/services/database/db_service/client.py"
click node_redis "https://github.com/harishbabu2007/kapexai/blob/main/services/redis-service/redis_service/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_app,node_profile,node_chat,node_session,node_api_client,node_result_views,node_user toneBlue
class node_backend_api,node_auth_routes,node_auth_middleware toneAmber
class node_worker_main,node_job_handler,node_orchestrator,node_planner,node_composer,node_dashboard_builder toneMint
class node_agent_registry,node_domain_agents,node_llm toneRose
class node_postgres,node_redis,node_business_idea,node_external_services toneIndigo
```

## Components

### User experience

- [App routes](https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Business profile](https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/pages/BusinessProfilePage.tsx): `frontend/src/pages/BusinessProfilePage.tsx`
- [Chat workspace](https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/pages/ChatPage.tsx): `frontend/src/pages/ChatPage.tsx`
- [Session state](https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/hooks/useChatSession.ts): `frontend/src/hooks/useChatSession.ts`
- [API client](https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`
- [Message and dashboard views](https://github.com/harishbabu2007/kapexai/blob/main/frontend/src/components/messages/index.tsx): `frontend/src/components/messages/index.tsx`

### API and streaming

- [Chat API and WebSocket](https://github.com/harishbabu2007/kapexai/blob/main/backend/main.py): `backend/main.py`
- [Google authentication](https://github.com/harishbabu2007/kapexai/blob/main/backend/routers/auth.py): `backend/routers/auth.py`
- [Request authentication](https://github.com/harishbabu2007/kapexai/blob/main/backend/middleware/auth.py): `backend/middleware/auth.py`

### Worker orchestration

- [Job consumer](https://github.com/harishbabu2007/kapexai/blob/main/worker/main.py): `worker/main.py`
- [Job processing](https://github.com/harishbabu2007/kapexai/blob/main/worker/agent.py): `worker/agent.py`
- [Turn orchestrator](https://github.com/harishbabu2007/kapexai/blob/main/worker/orchestrator/orchestrator.py): `worker/orchestrator/orchestrator.py`
- [Mode planner](https://github.com/harishbabu2007/kapexai/blob/main/worker/orchestrator/planner.py): `worker/orchestrator/planner.py`
- [Response composer](https://github.com/harishbabu2007/kapexai/blob/main/worker/orchestrator/composer.py): `worker/orchestrator/composer.py`
- [Dashboard builder](https://github.com/harishbabu2007/kapexai/blob/main/worker/orchestrator/dashboard_builder.py): `worker/orchestrator/dashboard_builder.py`

### Consulting capabilities

- [Subagent registry](https://github.com/harishbabu2007/kapexai/blob/main/worker/agents/registry.py): `worker/agents/registry.py`
- [Consulting subagents](https://github.com/harishbabu2007/kapexai/tree/main/worker/agents): `worker/agents`
- [LLM provider](https://github.com/harishbabu2007/kapexai/blob/main/worker/llm.py): `worker/llm.py`

### Persistence and services

- [Conversation database](https://github.com/harishbabu2007/kapexai/blob/main/services/database/db_service/client.py): `services/database/db_service/client.py`
- [Queue and stream store](https://github.com/harishbabu2007/kapexai/blob/main/services/redis-service/redis_service/client.py): `services/redis-service/redis_service/client.py`

### Other components

- **Business user**
- **Business idea**
- **LLM and search providers**

## Connections

- Business user → App routes: opens
- App routes → Business profile: routes to (evidence: `frontend/src/App.tsx`)
- App routes → Chat workspace: routes to (evidence: `frontend/src/App.tsx`)
- Business user → Business idea: describes
- Chat workspace → Session state: uses (evidence: `frontend/src/pages/ChatPage.tsx`)
- Session state → API client: requests (evidence: `frontend/src/hooks/useChatSession.ts`)
- API client → Chat API and WebSocket: calls
- Chat API and WebSocket → Google authentication: routes authentication (evidence: `backend/main.py`)
- Chat API and WebSocket → Conversation database: reads and writes (evidence: `backend/main.py`)
- Chat API and WebSocket → Queue and stream store: queues jobs (evidence: `backend/main.py`)
- Queue and stream store → Job consumer: delivers jobs
- Job consumer → Job processing: processes job (evidence: `worker/main.py`)
- Job processing → Turn orchestrator: handles turn (evidence: `worker/agent.py`)
- Turn orchestrator → Mode planner: plans turn (evidence: `worker/orchestrator/orchestrator.py`)
- Turn orchestrator → Subagent registry: dispatches subagents (evidence: `worker/orchestrator/orchestrator.py`)
- Turn orchestrator → Response composer: commits response (evidence: `worker/orchestrator/orchestrator.py`)
- Turn orchestrator → Dashboard builder: builds dashboard (evidence: `worker/orchestrator/orchestrator.py`)
- Mode planner → Subagent registry: selects capabilities (evidence: `worker/orchestrator/planner.py`)
- Subagent registry → Consulting subagents: registers
- Consulting subagents → LLM provider: uses model (evidence: `worker/agents/web_search_agent.py`)
- LLM provider → LLM and search providers: calls provider (evidence: `worker/llm.py`)
- Consulting subagents → LLM and search providers: searches web
- Response composer → Conversation database: persists messages
- Response composer → Queue and stream store: publishes frames
- Chat API and WebSocket → Queue and stream store: reads stream frames (evidence: `backend/main.py`)
- Chat API and WebSocket → Session state: streams results
- Session state → Message and dashboard views: renders results
- Message and dashboard views → Business user: shows analysis
- Google authentication → Conversation database: loads user (evidence: `backend/routers/auth.py`)
- Request authentication → Conversation database: validates user (evidence: `backend/middleware/auth.py`)
