# dhruvk1706/email-summarizer architecture

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

- Interactive diagram: https://gitdiagram.com/dhruvk1706/email-summarizer
- Repository: https://github.com/dhruvk1706/email-summarizer

## Overview

Email Assistant polls Gmail for recent inbox mail, summarizes new messages with Gemini, and delivers them through Telegram. Its second major workflow accepts authorized Telegram messages, runs a conversation agent that searches or retrieves Gmail and can produce draft-only previews, then returns the result. SQLite tracks delivery and summary-message associations; optional Postgres stores agent conversation memory. The graph follows the documented routes and sampled calls; the optional memory backend is documented and configured in the agent, but its runtime connection is not shown beyond that configuration.

Main entry points: [`server.py`](https://github.com/dhruvk1706/email-summarizer/blob/master/server.py) (HTTP server), [`gmail.py`](https://github.com/dhruvk1706/email-summarizer/blob/master/gmail.py) (Gmail access), [`state.py`](https://github.com/dhruvk1706/email-summarizer/blob/master/state.py) (Delivery and message state), [`agent.py`](https://github.com/dhruvk1706/email-summarizer/blob/master/agent.py) (Conversation agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_delivery["Polling and delivery"]
  node_server["HTTP server<br/>[server.py]"]
  node_telegram["Telegram Bot API"]
end

subgraph group_mail["Gmail access"]
  node_gmail["Gmail access<br/>[gmail.py]"]
  node_mail_store["Gmail mailbox"]
end

subgraph group_assistant["Conversation and AI"]
  node_agent["Conversation agent<br/>[agent.py]"]
  node_tools["Agent tools<br/>[tools.py]"]
  node_summarizer["Gemini workflows<br/>[summarizer.py]"]
  node_vertex["Vertex AI Gemini"]
end

subgraph group_state["Persistence"]
  node_delivery_state[("Delivery and message state<br/>[state.py]")]
  node_sqlite[("SQLite state store")]
  node_chat_memory["Conversation checkpoint<br/>[agent.py]"]
  node_postgres[("Postgres")]
end

node_scheduler(("Poll scheduler"))
node_telegram_user(("Telegram user"))

node_scheduler -->|"requests poll"| node_server
node_telegram_user -->|"sends messages"| node_telegram
node_telegram -->|"posts webhook"| node_server
node_server -->|"fetches new mail"| node_gmail
node_gmail -->|"reads inbox"| node_mail_store
node_gmail -->|"checks delivery"| node_delivery_state
node_gmail -->|"marks baseline"| node_delivery_state
node_server -->|"checks and records"| node_delivery_state
node_server -->|"requests summary"| node_summarizer
node_summarizer -->|"generates content"| node_vertex
node_server -->|"sends summaries"| node_telegram
node_server -->|"dispatches chat"| node_agent
node_server -->|"resolves reply email"| node_delivery_state
node_agent -->|"dispatches tools"| node_tools
node_agent -->|"gets chat model"| node_summarizer
node_tools -->|"searches and fetches"| node_gmail
node_tools -->|"generates draft"| node_summarizer
node_agent -->|"configures checkpoints"| node_chat_memory
node_chat_memory -.->|"stores memory"| node_postgres
node_delivery_state -->|"reads and writes"| node_sqlite
node_server -->|"sends chat replies"| node_telegram

click node_server "https://github.com/dhruvk1706/email-summarizer/blob/master/server.py"
click node_gmail "https://github.com/dhruvk1706/email-summarizer/blob/master/gmail.py"
click node_agent "https://github.com/dhruvk1706/email-summarizer/blob/master/agent.py"
click node_tools "https://github.com/dhruvk1706/email-summarizer/blob/master/tools.py"
click node_summarizer "https://github.com/dhruvk1706/email-summarizer/blob/master/summarizer.py"
click node_delivery_state "https://github.com/dhruvk1706/email-summarizer/blob/master/state.py"
click node_chat_memory "https://github.com/dhruvk1706/email-summarizer/blob/master/agent.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_server,node_telegram,node_telegram_user toneBlue
class node_gmail,node_mail_store toneAmber
class node_agent,node_tools,node_summarizer,node_vertex toneMint
class node_delivery_state,node_sqlite,node_chat_memory,node_postgres,node_scheduler toneRose
```

## Components

### Polling and delivery

- [HTTP server](https://github.com/dhruvk1706/email-summarizer/blob/master/server.py): `server.py`
- **Telegram Bot API**

### Gmail access

- [Gmail access](https://github.com/dhruvk1706/email-summarizer/blob/master/gmail.py): `gmail.py`
- **Gmail mailbox**

### Conversation and AI

- [Conversation agent](https://github.com/dhruvk1706/email-summarizer/blob/master/agent.py): `agent.py`
- [Agent tools](https://github.com/dhruvk1706/email-summarizer/blob/master/tools.py): `tools.py`
- [Gemini workflows](https://github.com/dhruvk1706/email-summarizer/blob/master/summarizer.py): `summarizer.py`
- **Vertex AI Gemini**

### Persistence

- [Delivery and message state](https://github.com/dhruvk1706/email-summarizer/blob/master/state.py): `state.py`
- **SQLite state store**
- [Conversation checkpoint](https://github.com/dhruvk1706/email-summarizer/blob/master/agent.py): `agent.py`
- **Postgres**

### Other components

- **Poll scheduler**
- **Telegram user**

## Connections

- Poll scheduler → HTTP server: requests poll (evidence: `README.md`)
- Telegram user → Telegram Bot API: sends messages (evidence: `README.md`)
- Telegram Bot API → HTTP server: posts webhook (evidence: `README.md`)
- HTTP server → Gmail access: fetches new mail (evidence: `server.py`)
- Gmail access → Gmail mailbox: reads inbox (evidence: `gmail.py`)
- Gmail access → Delivery and message state: checks delivery (evidence: `gmail.py`)
- Gmail access → Delivery and message state: marks baseline (evidence: `gmail.py`)
- HTTP server → Delivery and message state: checks and records (evidence: `server.py`)
- HTTP server → Gemini workflows: requests summary (evidence: `server.py`)
- Gemini workflows → Vertex AI Gemini: generates content (evidence: `summarizer.py`)
- HTTP server → Telegram Bot API: sends summaries (evidence: `server.py`)
- HTTP server → Conversation agent: dispatches chat (evidence: `server.py`)
- HTTP server → Delivery and message state: resolves reply email (evidence: `server.py`)
- Conversation agent → Agent tools: dispatches tools (evidence: `agent.py`)
- Conversation agent → Gemini workflows: gets chat model (evidence: `agent.py`)
- Agent tools → Gmail access: searches and fetches (evidence: `tools.py`)
- Agent tools → Gemini workflows: generates draft (evidence: `tools.py`)
- Conversation agent → Conversation checkpoint: configures checkpoints (evidence: `agent.py`)
- Conversation checkpoint → Postgres: stores memory (evidence: `README.md`)
- Delivery and message state → SQLite state store: reads and writes (evidence: `state.py`)
- HTTP server → Telegram Bot API: sends chat replies (evidence: `server.py`)
