# aharikrishnan0810/ai_email-roadmap architecture

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

- Interactive diagram: https://gitdiagram.com/aharikrishnan0810/ai_email-roadmap
- Repository: https://github.com/aharikrishnan0810/ai_email-roadmap

## Overview

1. This is a single-process Python web application, not a distributed system. The architecture is a Flask-based monolith with separate modules for Gmail access, email extraction, classification, roadmap generation, persistence, and web rendering.

2. The main user entry point is the browser UI in `templates/` plus `static/`. Users interact with pages like inbox, email detail, roadmap, and index; the frontend is mostly server-rendered HTML with a small amount of client-side JavaScript in `static/js/app.js` for actions like fetching or triggering updates.

3. `main.py` and `app.py` appear to be the application bootstrap and routing layer. This is the orchestration boundary: it receives HTTP requests, calls backend services, and returns rendered templates or JSON-like responses to the frontend.

4. `gmail_service.py` is the external integration layer. It handles Gmail API access through OAuth 2.0, pulling email data from Google as the system’s source of truth. This is the main outbound dependency and the first step in the email ingestion flow.

5. `db.py` provides local persistence, likely SQLite based on the README and file naming. The database stores fetched emails and related metadata so the app can display inbox history, deduplicate messages, and reuse previously processed content without re-querying Gmail every time.

6. `extractor.py` is the text normalization layer. It turns raw Gmail payloads into usable subject/body text and likely strips formatting or MIME noise so downstream modules work with clean content rather than raw email structures.

7. `classifier.py` is the intent-filtering subsystem. It distinguishes placement-related emails from general mail using heuristic or rule-based keyword logic, creating a boundary between noisy inbox content and messages worth generating roadmaps for.

8. `roadmap.py` is the AI synthesis layer. It takes extracted email content and converts it into a structured study or action roadmap, using Google Gemini as the external reasoning service. This is the second major outbound integration, and it is used after classification so only relevant emails trigger roadmap generation.

9. The main data flow is: Gmail API fetch → email extraction/normalization → classification → store in SQLite → render inbox/detail views → generate roadmap on demand. The roadmap generation path typically reads email content from the database, sends it to Gemini, and returns structured output for the roadmap page.

10. The app’s key boundaries are: Google services on the outside, Flask orchestration in the middle, and local persistence plus business logic inside. The UI is a thin presentation layer, while the real system behavior lives in the service modules.

11. `templates/inbox.html`, `templates/email_detail.html`, and `templates/roadmap.html` map to distinct workflow stages: inbox browsing, message inspection, and AI-generated planning. `templates/index.html` likely acts as the landing or control page for starting the email fetch and navigation flow.

12. Overall, the architecture is best drawn as a layered web application with two external systems: Gmail for input and Gemini for intelligence. SQLite is the local data store, Flask is the coordinator, and the domain modules implement email parsing, filtering, and roadmap creation.

Main entry points: [`app.py`](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/app.py) (app.py), [`roadmap.py`](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/roadmap.py) (Roadmap), [`gmail_service.py`](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/gmail_service.py) (Gmail Service), [`db.py`](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/db.py) (db.py)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_index_tpl["Index<br/>template<br/>[index.html]"]
  node_inbox_tpl["Inbox<br/>template<br/>[inbox.html]"]
  node_detail_tpl["Email Detail<br/>template<br/>[email_detail.html]"]
  node_roadmap_tpl["Roadmap<br/>template<br/>[roadmap.html]"]
  node_app_js["app.js<br/>frontend js<br/>[app.js]"]
  node_style_css["style.css<br/>stylesheet<br/>[style.css]"]
end

subgraph group_orchestration["Web App"]
  node_main_py["main.py<br/>entrypoint<br/>[main.py]"]
  node_app_py["app.py<br/>flask app<br/>[app.py]"]
end

subgraph group_domain["Domain Logic"]
  node_extractor["Extractor<br/>normalizer<br/>[extractor.py]"]
  node_classifier["Classifier<br/>filter<br/>[classifier.py]"]
  node_roadmap_py["Roadmap<br/>synthesis<br/>[roadmap.py]"]
end

subgraph group_integrations["External Services"]
  node_gmail_service["Gmail Service<br/>gmail integration<br/>[gmail_service.py]"]
  node_gmail_api(("Gmail API<br/>external api"))
  node_gemini_api(("Gemini<br/>external ai"))
end

subgraph group_storage["Persistence"]
  node_db_py[("db.py<br/>sqlite store<br/>[db.py]")]
end

node_main_py -->|"starts"| node_app_py
node_app_py -->|"renders"| node_index_tpl
node_app_py -->|"renders"| node_inbox_tpl
node_app_py -->|"renders"| node_detail_tpl
node_app_py -->|"renders"| node_roadmap_tpl
node_app_py -->|"serves"| node_app_js
node_app_py -->|"orchestrates"| node_gmail_service
node_gmail_service -->|"fetches"| node_gmail_api
node_gmail_service -->|"hands off"| node_extractor
node_extractor -->|"feeds"| node_classifier
node_classifier -->|"stores"| node_db_py
node_app_py -->|"reads"| node_db_py
node_app_py -->|"requests"| node_roadmap_py
node_roadmap_py -->|"reads"| node_db_py
node_roadmap_py -->|"calls"| node_gemini_api
node_app_js -->|"fetches"| node_app_py

click node_main_py "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/main.py"
click node_app_py "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/app.py"
click node_index_tpl "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/templates/index.html"
click node_inbox_tpl "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/templates/inbox.html"
click node_detail_tpl "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/templates/email_detail.html"
click node_roadmap_tpl "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/templates/roadmap.html"
click node_app_js "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/static/js/app.js"
click node_style_css "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/static/css/style.css"
click node_gmail_service "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/gmail_service.py"
click node_extractor "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/extractor.py"
click node_classifier "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/classifier.py"
click node_roadmap_py "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/roadmap.py"
click node_db_py "https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/db.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_index_tpl,node_inbox_tpl,node_detail_tpl,node_roadmap_tpl,node_app_js,node_style_css toneBlue
class node_main_py,node_app_py toneAmber
class node_extractor,node_classifier,node_roadmap_py toneMint
class node_gmail_service,node_gmail_api,node_gemini_api toneRose
class node_db_py toneIndigo
```

## Components

### Presentation

Server-rendered UI and client-side assets

- [Index](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/templates/index.html): template · Landing and control page · `templates/index.html`
- [Inbox](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/templates/inbox.html): template · Email list view · `templates/inbox.html`
- [Email Detail](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/templates/email_detail.html): template · Single-message inspection view · `templates/email_detail.html`
- [Roadmap](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/templates/roadmap.html): template · Generated plan display · `templates/roadmap.html`
- [app.js](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/static/js/app.js): frontend js · Client-side actions and fetch triggers · `static/js/app.js`
- [style.css](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/static/css/style.css): stylesheet · UI styling · `static/css/style.css`

### Web App

Flask bootstrap and request routing

- [main.py](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/main.py): entrypoint · Application startup and launch path · `main.py`
- [app.py](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/app.py): flask app · HTTP routing and request orchestration · `app.py`

### Domain Logic

Email parsing, filtering, and roadmap generation

- [Extractor](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/extractor.py): normalizer · Turns raw message payloads into clean text · `extractor.py`
- [Classifier](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/classifier.py): filter · Selects placement-related emails · `classifier.py`
- [Roadmap](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/roadmap.py): synthesis · Builds structured roadmap content · `roadmap.py`

### External Services

Outbound APIs used by the app

- [Gmail Service](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/gmail_service.py): gmail integration · OAuth-backed Gmail API access and email fetch · `gmail_service.py`
- **Gmail API**: external api · Source email system
- **Gemini**: external ai · Generative reasoning service

### Persistence

Local database access

- [db.py](https://github.com/aharikrishnan0810/ai_email-roadmap/blob/master/db.py): sqlite store · Local persistence for emails and metadata · `db.py`

## Connections

- main.py → app.py: starts · Bootstraps the Flask application
- app.py → Index: renders · Serves landing page
- app.py → Inbox: renders · Serves inbox view
- app.py → Email Detail: renders · Serves email detail view
- app.py → Roadmap: renders · Serves roadmap view
- app.py → app.js: serves · Provides client-side interaction layer
- app.py → Gmail Service: orchestrates · Triggers email sync and retrieval
- Gmail Service → Gmail API: fetches · Reads mail from Google
- Gmail Service → Extractor: hands off · Passes raw payloads for normalization
- Extractor → Classifier: feeds · Provides clean text for filtering
- Classifier → db.py: stores · Persists selected messages and metadata
- app.py → db.py: reads · Loads inbox and message state
- app.py → Roadmap: requests · Generates roadmap on demand
- Roadmap → db.py: reads · Uses stored email content as input
- Roadmap → Gemini: calls · Sends content for roadmap synthesis
- app.js → app.py: fetches · Invokes backend actions from the browser
