# lakshaypandey25/ai_email_assistant architecture

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

- Interactive diagram: https://gitdiagram.com/lakshaypandey25/ai_email_assistant
- Repository: https://github.com/lakshaypandey25/ai_email_assistant

## Overview

AI Email Assistant classifies Gmail, drafts replies, and proposes meetings, with human approval before externally visible actions. The main workflow runs from inbox processing through email parsing, classification, scheduling or drafting, then an approval queue; approval can create a calendar invite before sending a reply. The README documents the web UI, CLI, configurable memory and history, and optional MCP tools. Source excerpts and the index establish some internal links; where implementation details were not sampled, links are limited to documented relationships or omitted.

Main entry points: [`src/email_assistant/agent/orchestrator.py`](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/agent/orchestrator.py) (Email agent), [`src/email_assistant/ui/app.py`](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/ui/app.py) (Web UI), [`src/email_assistant/cli.py`](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/cli.py) (CLI), [`src/email_assistant/services/hitl.py`](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/hitl.py) (Approval handling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entry points"]
  node_ui["Web UI<br/>[app.py]"]
  node_cli["CLI<br/>[cli.py]"]
end

subgraph group_workflow["Email workflow"]
  node_agent["Email agent<br/>[orchestrator.py]"]
  node_fetch["Inbox fetching<br/>[fetcher.py]"]
  node_parse["Email parsing<br/>[mime_parser.py]"]
  node_classify["Classification<br/>[classification.py]"]
  node_route["Response routing<br/>[routing.py]"]
  node_draft["Reply drafting<br/>[drafting.py]"]
  node_schedule["Meeting scheduling<br/>[scheduling.py]"]
  node_slots["Availability logic<br/>[slots.py]"]
end

subgraph group_actions["Actions and integrations"]
  node_hitl["Approval handling<br/>[hitl.py]"]
  node_gmail["Gmail integration<br/>[gmail_client.py]"]
  node_calendar["Calendar integration<br/>[calendar_client.py]"]
  node_llm["Groq LLM<br/>[groq_client.py]"]
  node_oauth["Google OAuth<br/>[google_auth.py]"]
end

subgraph group_state["Safety and state"]
  node_database[("SQLite database<br/>[session.py]")]
  node_repositories["Data repositories<br/>[repositories.py]"]
  node_pii["PII protection<br/>[pii.py]"]
end

subgraph group_extensions["Supporting capabilities"]
  node_memory["User memory<br/>[memory.py]"]
  node_knowledge["Knowledge context<br/>[knowledge.py]"]
  node_mcp["MCP tools<br/>[server.py]"]
  node_evaluation["Evaluation<br/>[runner.py]"]
end

node_user(("User"))

node_user -->|"uses"| node_ui
node_user -->|"uses"| node_cli
node_ui -->|"processes inbox"| node_agent
node_cli -->|"runs processing"| node_agent
node_agent -->|"coordinates"| node_fetch
node_fetch -.->|"fetches mail"| node_gmail
node_fetch -.->|"parses messages"| node_parse
node_agent -->|"classifies"| node_classify
node_agent -->|"requests drafts"| node_draft
node_agent -->|"queues actions"| node_hitl
node_agent -.->|"selects response"| node_route
node_route -.->|"selects scheduling"| node_schedule
node_schedule -->|"checks availability"| node_slots
node_schedule -.->|"checks calendar"| node_calendar
node_draft -.->|"generates reply"| node_llm
node_hitl -.->|"approves sending"| node_gmail
node_hitl -.->|"approves invite"| node_calendar
node_oauth -.->|"authorizes access"| node_gmail
node_oauth -.->|"authorizes access"| node_calendar
node_agent -.->|"persists processing"| node_repositories
node_repositories -->|"reads and writes"| node_database
node_agent -->|"protects prompt data"| node_pii
node_agent -.->|"loads context"| node_memory
node_agent -.->|"retrieves context"| node_knowledge
node_cli -->|"starts server"| node_mcp
node_cli -->|"runs evaluation"| node_evaluation
node_ui -->|"manages memories"| node_memory
node_ui -->|"reviews approvals"| node_hitl

click node_ui "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/ui/app.py"
click node_cli "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/cli.py"
click node_agent "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/agent/orchestrator.py"
click node_fetch "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/fetcher.py"
click node_parse "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/preprocessing/mime_parser.py"
click node_classify "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/classification.py"
click node_route "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/routing.py"
click node_draft "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/drafting.py"
click node_schedule "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/scheduling.py"
click node_slots "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/scheduling/slots.py"
click node_hitl "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/hitl.py"
click node_gmail "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/integrations/gmail_client.py"
click node_calendar "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/integrations/calendar_client.py"
click node_llm "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/llm/groq_client.py"
click node_oauth "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/auth/google_auth.py"
click node_database "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/db/session.py"
click node_repositories "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/db/repositories.py"
click node_pii "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/core/pii.py"
click node_memory "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/memory.py"
click node_knowledge "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/knowledge.py"
click node_mcp "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/mcp_tools/server.py"
click node_evaluation "https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/evaluation/runner.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_ui,node_cli,node_user toneBlue
class node_agent,node_fetch,node_parse,node_classify,node_route,node_draft,node_schedule,node_slots toneAmber
class node_hitl,node_gmail,node_calendar,node_llm,node_oauth toneMint
class node_database,node_repositories,node_pii toneRose
class node_memory,node_knowledge,node_mcp,node_evaluation toneIndigo
```

## Components

### User entry points

- [Web UI](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/ui/app.py): `src/email_assistant/ui/app.py`
- [CLI](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/cli.py): `src/email_assistant/cli.py`

### Email workflow

- [Email agent](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/agent/orchestrator.py): `src/email_assistant/agent/orchestrator.py`
- [Inbox fetching](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/fetcher.py): `src/email_assistant/services/fetcher.py`
- [Email parsing](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/preprocessing/mime_parser.py): `src/email_assistant/preprocessing/mime_parser.py`
- [Classification](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/classification.py): `src/email_assistant/services/classification.py`
- [Response routing](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/routing.py): `src/email_assistant/services/routing.py`
- [Reply drafting](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/drafting.py): `src/email_assistant/services/drafting.py`
- [Meeting scheduling](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/scheduling.py): `src/email_assistant/services/scheduling.py`
- [Availability logic](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/scheduling/slots.py): `src/email_assistant/scheduling/slots.py`

### Actions and integrations

- [Approval handling](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/hitl.py): `src/email_assistant/services/hitl.py`
- [Gmail integration](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/integrations/gmail_client.py): `src/email_assistant/integrations/gmail_client.py`
- [Calendar integration](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/integrations/calendar_client.py): `src/email_assistant/integrations/calendar_client.py`
- [Groq LLM](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/llm/groq_client.py): `src/email_assistant/llm/groq_client.py`
- [Google OAuth](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/auth/google_auth.py): `src/email_assistant/auth/google_auth.py`

### Safety and state

- [SQLite database](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/db/session.py): `src/email_assistant/db/session.py`
- [Data repositories](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/db/repositories.py): `src/email_assistant/db/repositories.py`
- [PII protection](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/core/pii.py): `src/email_assistant/core/pii.py`

### Supporting capabilities

- [User memory](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/memory.py): `src/email_assistant/services/memory.py`
- [Knowledge context](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/services/knowledge.py): `src/email_assistant/services/knowledge.py`
- [MCP tools](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/mcp_tools/server.py): `src/email_assistant/mcp_tools/server.py`
- [Evaluation](https://github.com/lakshaypandey25/ai_email_assistant/blob/main/src/email_assistant/evaluation/runner.py): `src/email_assistant/evaluation/runner.py`

### Other components

- **User**

## Connections

- User → Web UI: uses
- User → CLI: uses
- Web UI → Email agent: processes inbox
- CLI → Email agent: runs processing
- Email agent → Inbox fetching: coordinates (evidence: `src/email_assistant/agent/orchestrator.py`)
- Inbox fetching → Gmail integration: fetches mail
- Inbox fetching → Email parsing: parses messages
- Email agent → Classification: classifies (evidence: `src/email_assistant/agent/orchestrator.py`)
- Email agent → Reply drafting: requests drafts (evidence: `src/email_assistant/agent/orchestrator.py`)
- Email agent → Approval handling: queues actions (evidence: `src/email_assistant/agent/orchestrator.py`)
- Email agent → Response routing: selects response (evidence: `src/email_assistant/agent/orchestrator.py`)
- Response routing → Meeting scheduling: selects scheduling
- Meeting scheduling → Availability logic: checks availability (evidence: `src/email_assistant/services/scheduling.py`)
- Meeting scheduling → Calendar integration: checks calendar
- Reply drafting → Groq LLM: generates reply
- Approval handling → Gmail integration: approves sending
- Approval handling → Calendar integration: approves invite
- Google OAuth → Gmail integration: authorizes access
- Google OAuth → Calendar integration: authorizes access
- Email agent → Data repositories: persists processing (evidence: `src/email_assistant/agent/orchestrator.py`)
- Data repositories → SQLite database: reads and writes (evidence: `src/email_assistant/db/session.py`)
- Email agent → PII protection: protects prompt data (evidence: `src/email_assistant/agent/orchestrator.py`)
- Email agent → User memory: loads context (evidence: `src/email_assistant/agent/orchestrator.py`)
- Email agent → Knowledge context: retrieves context (evidence: `src/email_assistant/agent/orchestrator.py`)
- CLI → MCP tools: starts server (evidence: `src/email_assistant/cli.py`)
- CLI → Evaluation: runs evaluation (evidence: `src/email_assistant/cli.py`)
- Web UI → User memory: manages memories (evidence: `src/email_assistant/ui/app.py`)
- Web UI → Approval handling: reviews approvals
