# stalpha2708/smart_email_assistant architecture

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

- Interactive diagram: https://gitdiagram.com/stalpha2708/smart_email_assistant
- Repository: https://github.com/stalpha2708/smart_email_assistant

## Overview

##### Project type and purpose
- This is a lightweight, single-service Python application (“smart_email_assistant”) that automates email-based task extraction and management.
- It connects to Gmail (IMAP/SMTP), parses incoming emails for tasks, persists them in a local SQLite database, and can display or send emails back.

##### File structure
Top-level
- ReadMe.md               – installation & setup instructions
- smart_email_assistant/  – application source
Inside smart_email_assistant/
- .env                    – environment variables (GMAIL creds)
- db.py                   – database adapter (SQLite)
- email_reader.py         – IMAP/HTTP layer for fetching emails
- email_sender.py         – SMTP layer for sending emails
- task_extractor.py       – domain logic (NLP/rules to find “tasks” in email content)
- view_tasks.py           – presentation layer (CLI view of tasks)
- main.py                 – orchestration: wire up reader → extractor → storage → view/sender
- tasks.db                – persisted SQLite database file
- .gitignore, __pycache__ – housekeeping

##### README for additional insights
- Dependencies: python-dotenv (load .env), requests (if used for API calls), standard libs (imaplib, smtplib, sqlite3)
- Gmail App Password is required (security boundary)

a. Main components
1. User / CLI: entrypoint (main.py)
2. Email Service (Gmail IMAP/SMTP)
3. Application modules:
- Email Reader adapter
- Task Extractor (domain logic)
- Database Adapter (SQLite, via db.py)
- Email Sender adapter
- View/Presentation (view_tasks.py)
b. Relationships & interactions (data flow)
1. User invokes main.py with a command (e.g., “extract‐tasks” or “view‐tasks”)
2. main.py loads .env → credentials → calls Email Reader
3. Email Reader fetches new messages from Gmail IMAP
4. main.py passes raw email data to Task Extractor
5. Task Extractor returns structured task objects
6. main.py calls Database Adapter to save tasks into tasks.db
7. For “view‐tasks”, main.py calls View/Presentation to fetch & display tasks
8. If configured, main.py calls Email Sender to send summary/follow-up via SMTP
9. Email Sender → Gmail SMTP → external
c. Architectural patterns & design principles
- Layered Architecture:
– Adapters (Email Reader/Sender, DB) isolate external interfaces
– Domain Services (Task Extractor) encapsulate business logic
– Orchestrator (main) coordinates flows
– Presentation (view_tasks) handles user output
- Single Responsibility per module
- Dependency Injection via main.py wiring
- Environment-based configuration for secrets
d. Key technologies & libraries
- Python 3.x
- python-dotenv (configuration)
- imaplib/smtplib or requests (email I/O)
- sqlite3 (lightweight, file-based DB)
- NLP/regex (inside task_extractor)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Configuration Layer
    subgraph "Configuration Layer"
        ENV[".env Configuration"]:::config
        README["ReadMe.md"]:::doc
        GITIGNORE[".gitignore"]:::doc
    end

    %% CLI Layer
    subgraph "CLI Layer"
        CLI["CLI Entrypoint (main.py)"]:::orchestrator
        VIEW["View/Presentation (view_tasks.py)"]:::orchestrator
    end

    %% Domain Layer
    subgraph "Domain Layer"
        EXTRACTOR["Task Extractor Service (task_extractor.py)"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        READER["Email Reader Adapter (email_reader.py)"]:::adapter
        SENDER["Email Sender Adapter (email_sender.py)"]:::adapter
        DB["Database Adapter (db.py)"]:::adapter
        DBFILE["Persisted SQLite DB (tasks.db)"]:::storage
    end

    %% External Services
    subgraph "External Services"
        GMAIL["Gmail IMAP/SMTP"]:::external
    end

    %% Flows
    ENV -->|"load credentials"| CLI
    CLI -->|"fetch emails"| READER
    READER -->|"IMAP fetch"| GMAIL
    READER -->|"raw emails"| CLI
    CLI -->|"extract tasks"| EXTRACTOR
    EXTRACTOR -->|"parsed tasks"| CLI
    CLI -->|"SQL INSERT"| DB
    DB -->|"write to file"| DBFILE
    CLI -->|"view tasks"| VIEW
    CLI -->|"send summary"| SENDER
    SENDER -->|"SMTP send"| GMAIL

    %% Click Events
    click CLI "https://github.com/stalpha2708/smart_email_assistant/blob/main/smart_email_assistant/main.py"
    click READER "https://github.com/stalpha2708/smart_email_assistant/blob/main/smart_email_assistant/email_reader.py"
    click SENDER "https://github.com/stalpha2708/smart_email_assistant/blob/main/smart_email_assistant/email_sender.py"
    click EXTRACTOR "https://github.com/stalpha2708/smart_email_assistant/blob/main/smart_email_assistant/task_extractor.py"
    click DB "https://github.com/stalpha2708/smart_email_assistant/blob/main/smart_email_assistant/db.py"
    click VIEW "https://github.com/stalpha2708/smart_email_assistant/blob/main/smart_email_assistant/view_tasks.py"
    click ENV "https://github.com/stalpha2708/smart_email_assistant/blob/main/smart_email_assistant/.env"
    click DBFILE "https://github.com/stalpha2708/smart_email_assistant/blob/main/smart_email_assistant/tasks.db"
    click README "https://github.com/stalpha2708/smart_email_assistant/blob/main/ReadMe.md"
    click GITIGNORE "https://github.com/stalpha2708/smart_email_assistant/blob/main/smart_email_assistant/.gitignore"

    %% Styles
    classDef adapter fill:#c1f0c1,stroke:#333
    classDef domain fill:#c1d4f0,stroke:#333
    classDef orchestrator fill:#fbf5c3,stroke:#333
    classDef external fill:#d0d0d0,stroke:#333
    classDef config fill:#ffeedb,stroke:#333
    classDef doc fill:#e8e8e8,stroke:#333
    classDef storage fill:#f0d4c1,stroke:#333
```
