# haricrazy1432-bot/emailautomation architecture

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

- Interactive diagram: https://gitdiagram.com/haricrazy1432-bot/emailautomation
- Repository: https://github.com/haricrazy1432-bot/emailautomation

## Overview

EmailAutomation centers on processing unread Gmail messages into validated replies, with a Streamlit dashboard that triggers and displays the API workflow. It also provides separate document indexing and semantic-query tools through both an API and a standalone command-line script. The email workflow is implemented twice: in `main.py` and in `rag_api.py`. The former references `gmail_client` although it imports `gmail`, so that path appears to have a runtime naming issue. RAG edges reflect the shown implementations; the repository’s small README gives no further capability details.

Main entry points: [`llm_client.py`](https://github.com/haricrazy1432-bot/emailautomation/blob/main/llm_client.py) (Validate reply), [`rag_api.py`](https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py) (FastAPI service), [`minimal_rag_chroma.py`](https://github.com/haricrazy1432-bot/emailautomation/blob/main/minimal_rag_chroma.py) (Standalone RAG tools), [`main.py`](https://github.com/haricrazy1432-bot/emailautomation/blob/main/main.py) (Standalone workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_email["Email processing"]
  node_main_workflow["Standalone workflow<br/>[main.py]"]
  node_api_workflow["API email workflow<br/>[rag_api.py]"]
  node_retrieve["Fetch email<br/>[rag_api.py]"]
  node_draft["Draft reply<br/>[llm_client.py]"]
  node_validate["Validate reply<br/>[llm_client.py]"]
  node_rewrite["Rewrite reply<br/>[llm_client.py]"]
  node_send["Send reply<br/>[gmail.py]"]
end

subgraph group_service["API and dashboard"]
  node_dashboard["Streamlit dashboard<br/>[rag_ui.py]"]
  node_api["FastAPI service<br/>[rag_api.py]"]
end

subgraph group_rag["Document retrieval"]
  node_extract["Document extraction<br/>[rag_api.py]"]
  node_index["Document indexing<br/>[rag_api.py]"]
  node_query["Semantic query<br/>[rag_api.py]"]
  node_vector_store[("Chroma store<br/>[rag_api.py]")]
  node_cli_rag["Standalone RAG tools"]
  node_watcher["File watcher"]
end

subgraph group_connectors["Integrations"]
  node_gmail["Gmail connector<br/>[gmail.py]"]
  node_llm["LLM helpers<br/>[llm_client.py]"]
end

node_operator(("Operator"))
node_gmail_service["Gmail service"]
node_documents["Documents"]

node_operator -->|"uses"| node_dashboard
node_dashboard -->|"triggers workflow"| node_api
node_dashboard -->|"reads inbox"| node_gmail_service
node_api -->|"invokes"| node_api_workflow
node_api_workflow -->|"starts at"| node_retrieve
node_retrieve -->|"then drafts"| node_draft
node_draft -->|"then validates"| node_validate
node_validate -->|"on failure"| node_rewrite
node_rewrite -->|"revalidates"| node_validate
node_validate -->|"on approval"| node_send
node_retrieve -->|"fetches from"| node_gmail
node_send -->|"sends via"| node_gmail_service
node_gmail -->|"calls"| node_gmail_service
node_draft -->|"generates with"| node_llm
node_validate -->|"checks with"| node_llm
node_rewrite -->|"rewrites with"| node_llm
node_operator -->|"runs directly"| node_main_workflow
node_main_workflow -->|"fetches and sends"| node_gmail
node_main_workflow -->|"drafts and checks"| node_llm
node_api -->|"indexes uploads"| node_extract
node_documents -->|"uploaded to"| node_extract
node_extract -->|"extracts text for"| node_index
node_index -->|"stores embeddings"| node_vector_store
node_api -->|"serves queries"| node_query
node_query -->|"searches"| node_vector_store
node_operator -->|"runs tools"| node_cli_rag
node_documents -->|"indexes files"| node_cli_rag
node_cli_rag -->|"indexes and queries"| node_vector_store
node_watcher -->|"reindexes changes"| node_cli_rag

click node_main_workflow "https://github.com/haricrazy1432-bot/emailautomation/blob/main/main.py"
click node_api_workflow "https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py"
click node_retrieve "https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py"
click node_draft "https://github.com/haricrazy1432-bot/emailautomation/blob/main/llm_client.py"
click node_validate "https://github.com/haricrazy1432-bot/emailautomation/blob/main/llm_client.py"
click node_rewrite "https://github.com/haricrazy1432-bot/emailautomation/blob/main/llm_client.py"
click node_send "https://github.com/haricrazy1432-bot/emailautomation/blob/main/gmail.py"
click node_gmail "https://github.com/haricrazy1432-bot/emailautomation/blob/main/gmail.py"
click node_llm "https://github.com/haricrazy1432-bot/emailautomation/blob/main/llm_client.py"
click node_dashboard "https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_ui.py"
click node_api "https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py"
click node_extract "https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py"
click node_index "https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py"
click node_query "https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py"
click node_vector_store "https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py"
click node_cli_rag "https://github.com/haricrazy1432-bot/emailautomation/blob/main/minimal_rag_chroma.py"
click node_watcher "https://github.com/haricrazy1432-bot/emailautomation/blob/main/minimal_rag_chroma.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_main_workflow,node_api_workflow,node_retrieve,node_draft,node_validate,node_rewrite,node_send toneBlue
class node_dashboard,node_api toneAmber
class node_extract,node_index,node_query,node_vector_store,node_cli_rag,node_watcher toneMint
class node_gmail,node_llm toneRose
class node_operator,node_gmail_service,node_documents toneIndigo
```

## Components

### Email processing

- [Standalone workflow](https://github.com/haricrazy1432-bot/emailautomation/blob/main/main.py): `main.py`
- [API email workflow](https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py): `rag_api.py`
- [Fetch email](https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py): `rag_api.py`
- [Draft reply](https://github.com/haricrazy1432-bot/emailautomation/blob/main/llm_client.py): `llm_client.py`
- [Validate reply](https://github.com/haricrazy1432-bot/emailautomation/blob/main/llm_client.py): `llm_client.py`
- [Rewrite reply](https://github.com/haricrazy1432-bot/emailautomation/blob/main/llm_client.py): `llm_client.py`
- [Send reply](https://github.com/haricrazy1432-bot/emailautomation/blob/main/gmail.py): `gmail.py`

### API and dashboard

- [Streamlit dashboard](https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_ui.py): `rag_ui.py`
- [FastAPI service](https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py): `rag_api.py`

### Document retrieval

- [Document extraction](https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py): `rag_api.py`
- [Document indexing](https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py): `rag_api.py`
- [Semantic query](https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py): `rag_api.py`
- [Chroma store](https://github.com/haricrazy1432-bot/emailautomation/blob/main/rag_api.py): `rag_api.py`
- [Standalone RAG tools](https://github.com/haricrazy1432-bot/emailautomation/blob/main/minimal_rag_chroma.py): `minimal_rag_chroma.py`
- [File watcher](https://github.com/haricrazy1432-bot/emailautomation/blob/main/minimal_rag_chroma.py): `minimal_rag_chroma.py`

### Integrations

- [Gmail connector](https://github.com/haricrazy1432-bot/emailautomation/blob/main/gmail.py): `gmail.py`
- [LLM helpers](https://github.com/haricrazy1432-bot/emailautomation/blob/main/llm_client.py): `llm_client.py`

### Other components

- **Operator**
- **Gmail service**
- **Documents**

## Connections

- Operator → Streamlit dashboard: uses (evidence: `rag_ui.py`)
- Streamlit dashboard → FastAPI service: triggers workflow (evidence: `rag_ui.py`)
- Streamlit dashboard → Gmail service: reads inbox (evidence: `rag_ui.py`)
- FastAPI service → API email workflow: invokes (evidence: `rag_api.py`)
- API email workflow → Fetch email: starts at (evidence: `rag_api.py`)
- Fetch email → Draft reply: then drafts (evidence: `rag_api.py`)
- Draft reply → Validate reply: then validates (evidence: `rag_api.py`)
- Validate reply → Rewrite reply: on failure (evidence: `rag_api.py`)
- Rewrite reply → Validate reply: revalidates (evidence: `rag_api.py`)
- Validate reply → Send reply: on approval (evidence: `rag_api.py`)
- Fetch email → Gmail connector: fetches from (evidence: `rag_api.py`)
- Send reply → Gmail service: sends via (evidence: `gmail.py`)
- Gmail connector → Gmail service: calls (evidence: `gmail.py`)
- Draft reply → LLM helpers: generates with (evidence: `rag_api.py`)
- Validate reply → LLM helpers: checks with (evidence: `rag_api.py`)
- Rewrite reply → LLM helpers: rewrites with (evidence: `rag_api.py`)
- Operator → Standalone workflow: runs directly (evidence: `main.py`)
- Standalone workflow → Gmail connector: fetches and sends (evidence: `main.py`)
- Standalone workflow → LLM helpers: drafts and checks (evidence: `main.py`)
- FastAPI service → Document extraction: indexes uploads (evidence: `rag_api.py`)
- Documents → Document extraction: uploaded to (evidence: `rag_api.py`)
- Document extraction → Document indexing: extracts text for (evidence: `rag_api.py`)
- Document indexing → Chroma store: stores embeddings (evidence: `rag_api.py`)
- FastAPI service → Semantic query: serves queries (evidence: `rag_api.py`)
- Semantic query → Chroma store: searches (evidence: `rag_api.py`)
- Operator → Standalone RAG tools: runs tools (evidence: `minimal_rag_chroma.py`)
- Documents → Standalone RAG tools: indexes files (evidence: `minimal_rag_chroma.py`)
- Standalone RAG tools → Chroma store: indexes and queries (evidence: `minimal_rag_chroma.py`)
- File watcher → Standalone RAG tools: reindexes changes (evidence: `minimal_rag_chroma.py`)
