# trideep091/kairo architecture

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

- Interactive diagram: https://gitdiagram.com/trideep091/kairo
- Repository: https://github.com/trideep091/kairo

## Overview

Kairo is a Gmail-embedded email assistant: the user selects an email in the extension, the backend analyzes and routes it through agent stages, then presents a draft for explicit approval before any send. The graph also preserves documented OAuth/calendar integration, follow-up tracking, and extension capabilities. Relationships among agents and major runtime stages follow the workflow excerpt and README; unsampled extension wiring is shown only where the README documents it.

Main entry points: [`backend/app/graph/workflow.py`](https://github.com/trideep091/kairo/blob/main/backend/app/graph/workflow.py) (LangGraph Workflow), [`backend/app/api/routes.py`](https://github.com/trideep091/kairo/blob/main/backend/app/api/routes.py) (API Routes), [`backend/app/agents/critic.py`](https://github.com/trideep091/kairo/blob/main/backend/app/agents/critic.py) (Draft Critic), [`backend/app/agents/rag_agent.py`](https://github.com/trideep091/kairo/blob/main/backend/app/agents/rag_agent.py) (Agentic RAG)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["Chrome Extension"]
  node_content["Gmail Content Hooks<br/>[content.js]"]
  node_extractor["Email Extractor<br/>[extractor.ts]"]
  node_selectors["Gmail Selectors<br/>[selectors.ts]"]
  node_injector["Reply Injector<br/>[injector.ts]"]
  node_sidepanel["Side Panel<br/>[sidepanel.js]"]
  node_background["Background Worker<br/>[background.js]"]
end

subgraph group_api["Backend API"]
  node_routes["API Routes<br/>[routes.py]"]
  node_stream["SSE Streaming<br/>[sse.py]"]
end

subgraph group_agents["Agent Workflow"]
  node_triage["Email Triage<br/>[triage.py]"]
  node_supervisor["Plan Supervisor<br/>[supervisor.py]"]
  node_rag["Agentic RAG<br/>[rag_agent.py]"]
  node_calendar_agent["Calendar Agent<br/>[calendar_agent.py]"]
  node_drafter["Reply Drafter<br/>[drafter.py]"]
  node_critic["Draft Critic<br/>[critic.py]"]
  node_approval["Approval Gate<br/>[approval.py]"]
  node_workflow["LangGraph Workflow<br/>[workflow.py]"]
  node_state["Shared Agent State<br/>[state.py]"]
  node_engine["Extraction Engine<br/>[engine.py]"]
  node_validator["Unslop Validator<br/>[validator.py]"]
end

subgraph group_memory["Memory and Tracking"]
  node_sqlite[("SQLite Records<br/>[db.py]")]
  node_vectors[("Vector Store<br/>[vector_store.py]")]
  node_followups["Follow-up Scheduler<br/>[followups.py]"]
end

subgraph group_integrations["Workspace Integrations"]
  node_google_auth["Google OAuth<br/>[google_auth.py]"]
  node_google_service["Google Workspace Service<br/>[google_service.py]"]
  node_calendar_tool["MCP Calendar<br/>[mcp_calendar.py]"]
  node_mailer["Mail Dispatcher<br/>[mailer.py]"]
end

node_user(("Email User"))
node_gmail(("Gmail"))

node_user -->|"uses Gmail"| node_content
node_content -.->|"extracts email"| node_extractor
node_extractor -->|"queries DOM"| node_selectors
node_content -.->|"injects replies"| node_injector
node_user -->|"reviews drafts"| node_sidepanel
node_sidepanel -->|"sends requests"| node_routes
node_routes -->|"starts processing"| node_workflow
node_routes -->|"streams events"| node_stream
node_sidepanel -->|"displays SSE"| node_stream
node_background -.->|"routes requests"| node_routes
node_workflow -->|"starts at"| node_triage
node_workflow -->|"dispatches"| node_supervisor
node_workflow -->|"dispatches"| node_rag
node_workflow -->|"dispatches"| node_calendar_agent
node_workflow -->|"dispatches"| node_drafter
node_workflow -->|"dispatches"| node_critic
node_workflow -->|"dispatches"| node_approval
node_workflow -->|"uses state"| node_state
node_triage -->|"then routes"| node_supervisor
node_supervisor -->|"plans retrieval"| node_rag
node_rag -->|"retrieves context"| node_vectors
node_rag -.->|"routes calendar work"| node_calendar_agent
node_calendar_agent -->|"checks availability"| node_calendar_tool
node_calendar_agent -->|"replans conflicts"| node_supervisor
node_drafter -->|"submits draft"| node_critic
node_critic -->|"requests revision"| node_drafter
node_critic -->|"passes draft"| node_approval
node_drafter -->|"validates voice"| node_validator
node_critic -->|"checks style"| node_validator
node_approval -->|"sends when approved"| node_mailer
node_approval -->|"records approval"| node_sqlite
node_routes -->|"reads email records"| node_sqlite
node_routes -->|"retrieves follow-ups"| node_followups
node_followups -->|"tracks commitments"| node_sqlite
node_routes -->|"handles OAuth"| node_google_auth
node_routes -->|"syncs workspace"| node_google_service
node_google_service -->|"checks credentials"| node_google_auth
node_google_service -->|"stores synced email"| node_sqlite
node_mailer -->|"dispatches via Gmail"| node_google_service
node_user -->|"connects account"| node_google_auth

click node_content "https://github.com/trideep091/kairo/blob/main/extension/content.js"
click node_extractor "https://github.com/trideep091/kairo/blob/main/extension/src/content/extractor.ts"
click node_selectors "https://github.com/trideep091/kairo/blob/main/extension/src/content/selectors.ts"
click node_injector "https://github.com/trideep091/kairo/blob/main/extension/src/content/injector.ts"
click node_sidepanel "https://github.com/trideep091/kairo/blob/main/extension/sidepanel.js"
click node_background "https://github.com/trideep091/kairo/blob/main/extension/background.js"
click node_routes "https://github.com/trideep091/kairo/blob/main/backend/app/api/routes.py"
click node_stream "https://github.com/trideep091/kairo/blob/main/backend/app/api/sse.py"
click node_triage "https://github.com/trideep091/kairo/blob/main/backend/app/agents/triage.py"
click node_supervisor "https://github.com/trideep091/kairo/blob/main/backend/app/agents/supervisor.py"
click node_rag "https://github.com/trideep091/kairo/blob/main/backend/app/agents/rag_agent.py"
click node_calendar_agent "https://github.com/trideep091/kairo/blob/main/backend/app/agents/calendar_agent.py"
click node_drafter "https://github.com/trideep091/kairo/blob/main/backend/app/agents/drafter.py"
click node_critic "https://github.com/trideep091/kairo/blob/main/backend/app/agents/critic.py"
click node_approval "https://github.com/trideep091/kairo/blob/main/backend/app/agents/approval.py"
click node_workflow "https://github.com/trideep091/kairo/blob/main/backend/app/graph/workflow.py"
click node_state "https://github.com/trideep091/kairo/blob/main/backend/app/graph/state.py"
click node_engine "https://github.com/trideep091/kairo/blob/main/backend/app/pipeline/engine.py"
click node_validator "https://github.com/trideep091/kairo/blob/main/backend/app/unslop/validator.py"
click node_sqlite "https://github.com/trideep091/kairo/blob/main/backend/app/memory/db.py"
click node_vectors "https://github.com/trideep091/kairo/blob/main/backend/app/memory/vector_store.py"
click node_followups "https://github.com/trideep091/kairo/blob/main/backend/app/scheduler/followups.py"
click node_google_auth "https://github.com/trideep091/kairo/blob/main/backend/app/tools/google_auth.py"
click node_google_service "https://github.com/trideep091/kairo/blob/main/backend/app/tools/google_service.py"
click node_calendar_tool "https://github.com/trideep091/kairo/blob/main/backend/app/tools/mcp_calendar.py"
click node_mailer "https://github.com/trideep091/kairo/blob/main/backend/app/tools/mailer.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_content,node_extractor,node_selectors,node_injector,node_sidepanel,node_background,node_user toneBlue
class node_routes,node_stream toneAmber
class node_triage,node_supervisor,node_rag,node_calendar_agent,node_drafter,node_critic,node_approval,node_workflow,node_state,node_engine,node_validator toneMint
class node_sqlite,node_vectors,node_followups toneRose
class node_google_auth,node_google_service,node_calendar_tool,node_mailer,node_gmail toneIndigo
```

## Components

### Chrome Extension

- [Gmail Content Hooks](https://github.com/trideep091/kairo/blob/main/extension/content.js): `extension/content.js`
- [Email Extractor](https://github.com/trideep091/kairo/blob/main/extension/src/content/extractor.ts): `extension/src/content/extractor.ts`
- [Gmail Selectors](https://github.com/trideep091/kairo/blob/main/extension/src/content/selectors.ts): `extension/src/content/selectors.ts`
- [Reply Injector](https://github.com/trideep091/kairo/blob/main/extension/src/content/injector.ts): `extension/src/content/injector.ts`
- [Side Panel](https://github.com/trideep091/kairo/blob/main/extension/sidepanel.js): `extension/sidepanel.js`
- [Background Worker](https://github.com/trideep091/kairo/blob/main/extension/background.js): `extension/background.js`

### Backend API

- [API Routes](https://github.com/trideep091/kairo/blob/main/backend/app/api/routes.py): `backend/app/api/routes.py`
- [SSE Streaming](https://github.com/trideep091/kairo/blob/main/backend/app/api/sse.py): `backend/app/api/sse.py`

### Agent Workflow

- [Email Triage](https://github.com/trideep091/kairo/blob/main/backend/app/agents/triage.py): `backend/app/agents/triage.py`
- [Plan Supervisor](https://github.com/trideep091/kairo/blob/main/backend/app/agents/supervisor.py): `backend/app/agents/supervisor.py`
- [Agentic RAG](https://github.com/trideep091/kairo/blob/main/backend/app/agents/rag_agent.py): `backend/app/agents/rag_agent.py`
- [Calendar Agent](https://github.com/trideep091/kairo/blob/main/backend/app/agents/calendar_agent.py): `backend/app/agents/calendar_agent.py`
- [Reply Drafter](https://github.com/trideep091/kairo/blob/main/backend/app/agents/drafter.py): `backend/app/agents/drafter.py`
- [Draft Critic](https://github.com/trideep091/kairo/blob/main/backend/app/agents/critic.py): `backend/app/agents/critic.py`
- [Approval Gate](https://github.com/trideep091/kairo/blob/main/backend/app/agents/approval.py): `backend/app/agents/approval.py`
- [LangGraph Workflow](https://github.com/trideep091/kairo/blob/main/backend/app/graph/workflow.py): `backend/app/graph/workflow.py`
- [Shared Agent State](https://github.com/trideep091/kairo/blob/main/backend/app/graph/state.py): `backend/app/graph/state.py`
- [Extraction Engine](https://github.com/trideep091/kairo/blob/main/backend/app/pipeline/engine.py): `backend/app/pipeline/engine.py`
- [Unslop Validator](https://github.com/trideep091/kairo/blob/main/backend/app/unslop/validator.py): `backend/app/unslop/validator.py`

### Memory and Tracking

- [SQLite Records](https://github.com/trideep091/kairo/blob/main/backend/app/memory/db.py): `backend/app/memory/db.py`
- [Vector Store](https://github.com/trideep091/kairo/blob/main/backend/app/memory/vector_store.py): `backend/app/memory/vector_store.py`
- [Follow-up Scheduler](https://github.com/trideep091/kairo/blob/main/backend/app/scheduler/followups.py): `backend/app/scheduler/followups.py`

### Workspace Integrations

- [Google OAuth](https://github.com/trideep091/kairo/blob/main/backend/app/tools/google_auth.py): `backend/app/tools/google_auth.py`
- [Google Workspace Service](https://github.com/trideep091/kairo/blob/main/backend/app/tools/google_service.py): `backend/app/tools/google_service.py`
- [MCP Calendar](https://github.com/trideep091/kairo/blob/main/backend/app/tools/mcp_calendar.py): `backend/app/tools/mcp_calendar.py`
- [Mail Dispatcher](https://github.com/trideep091/kairo/blob/main/backend/app/tools/mailer.py): `backend/app/tools/mailer.py`

### Other components

- **Email User**
- **Gmail**

## Connections

- Email User → Gmail Content Hooks: uses Gmail
- Gmail Content Hooks → Email Extractor: extracts email
- Email Extractor → Gmail Selectors: queries DOM (evidence: `extension/src/content/extractor.ts`)
- Gmail Content Hooks → Reply Injector: injects replies
- Email User → Side Panel: reviews drafts
- Side Panel → API Routes: sends requests
- API Routes → LangGraph Workflow: starts processing (evidence: `backend/app/api/routes.py`)
- API Routes → SSE Streaming: streams events (evidence: `backend/app/api/routes.py`)
- Side Panel → SSE Streaming: displays SSE
- Background Worker → API Routes: routes requests
- LangGraph Workflow → Email Triage: starts at (evidence: `backend/app/graph/workflow.py`)
- LangGraph Workflow → Plan Supervisor: dispatches (evidence: `backend/app/graph/workflow.py`)
- LangGraph Workflow → Agentic RAG: dispatches (evidence: `backend/app/graph/workflow.py`)
- LangGraph Workflow → Calendar Agent: dispatches (evidence: `backend/app/graph/workflow.py`)
- LangGraph Workflow → Reply Drafter: dispatches (evidence: `backend/app/graph/workflow.py`)
- LangGraph Workflow → Draft Critic: dispatches (evidence: `backend/app/graph/workflow.py`)
- LangGraph Workflow → Approval Gate: dispatches (evidence: `backend/app/graph/workflow.py`)
- LangGraph Workflow → Shared Agent State: uses state (evidence: `backend/app/graph/workflow.py`)
- Email Triage → Plan Supervisor: then routes (evidence: `backend/app/graph/workflow.py`)
- Plan Supervisor → Agentic RAG: plans retrieval
- Agentic RAG → Vector Store: retrieves context (evidence: `backend/app/agents/rag_agent.py`)
- Agentic RAG → Calendar Agent: routes calendar work
- Calendar Agent → MCP Calendar: checks availability (evidence: `backend/app/agents/calendar_agent.py`)
- Calendar Agent → Plan Supervisor: replans conflicts
- Reply Drafter → Draft Critic: submits draft (evidence: `backend/app/graph/workflow.py`)
- Draft Critic → Reply Drafter: requests revision (evidence: `backend/app/graph/workflow.py`)
- Draft Critic → Approval Gate: passes draft (evidence: `backend/app/graph/workflow.py`)
- Reply Drafter → Unslop Validator: validates voice (evidence: `backend/app/agents/drafter.py`)
- Draft Critic → Unslop Validator: checks style (evidence: `backend/app/agents/critic.py`)
- Approval Gate → Mail Dispatcher: sends when approved (evidence: `backend/app/agents/approval.py`)
- Approval Gate → SQLite Records: records approval (evidence: `backend/app/agents/approval.py`)
- API Routes → SQLite Records: reads email records (evidence: `backend/app/api/routes.py`)
- API Routes → Follow-up Scheduler: retrieves follow-ups (evidence: `backend/app/api/routes.py`)
- Follow-up Scheduler → SQLite Records: tracks commitments (evidence: `backend/app/scheduler/followups.py`)
- API Routes → Google OAuth: handles OAuth (evidence: `backend/app/api/routes.py`)
- API Routes → Google Workspace Service: syncs workspace (evidence: `backend/app/api/routes.py`)
- Google Workspace Service → Google OAuth: checks credentials (evidence: `backend/app/tools/google_service.py`)
- Google Workspace Service → SQLite Records: stores synced email (evidence: `backend/app/tools/google_service.py`)
- Mail Dispatcher → Google Workspace Service: dispatches via Gmail (evidence: `backend/app/tools/mailer.py`)
- Email User → Google OAuth: connects account
