# raghavendraatb/mail-portal architecture

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

- Interactive diagram: https://gitdiagram.com/raghavendraatb/mail-portal
- Repository: https://github.com/raghavendraatb/mail-portal

## Overview

1. **Overall shape**
   - This repository is a small, single-service Flask application that acts as a Gmail-like inbox viewer.
   - The architecture is intentionally simple: one web process, one IMAP mail-access module, and one HTML template for the UI.

2. **Runtime and deployment boundary**
   - The app is designed to run as a Python web service under **Gunicorn** on **Render**.
   - There is no separate database, queue, or worker tier; every request is handled synchronously by the Flask process.

3. **HTTP entry points**
   - `app.py` is the application entry layer.
   - The README documents at least two routes:
     - `GET /` to render the inbox
     - `GET /health` to return a lightweight JSON health check
   - The `/` route is the main request path and drives the email-fetching flow.

4. **Mail access subsystem**
   - `imap_client.py` contains the IMAP integration with Gmail.
   - This module is the external-system boundary for the repository: it talks to Gmail’s IMAP server using credentials supplied by environment variables.
   - The backend fetches email data directly from the mailbox rather than through Gmail’s web UI or Gmail API.

5. **Request-to-data flow**
   - A browser request to `/` triggers Flask to call into the IMAP client.
   - The IMAP client fetches all emails, returning message details for display.
   - The app then passes that data into the HTML template for server-side rendering.

6. **UI rendering**
   - `templates/inbox.html` is the only front-end asset in the tree.
   - The UI is server-rendered with Jinja, producing a Gmail-like expandable inbox view.
   - The template displays the key message fields mentioned in the README: From, To, Date, Subject, and Body.

7. **Refresh behavior**
   - Refresh is not background polling; it is a user-triggered re-fetch.
   - Clicking Refresh simply issues another `GET /`, causing the backend to query IMAP again and render the latest inbox state.
   - This means the data source of truth is always Gmail, not an intermediate cache.

8. **Time handling**
   - The app tracks and displays the last refresh timestamp in **IST**.
   - Time formatting is handled in the backend before being injected into the template, so the UI receives a ready-to-display string.

9. **Configuration and secrets boundary**
   - Credentials are externalized via environment variables:
     - `GMAIL_USER`
     - `GMAIL_APP_PASSWORD`
   - This keeps Gmail access credentials out of source control and makes the app deployable on Render without code changes.

10. **Operational dependencies**
   - The app depends on Flask for routing and templating, and Gunicorn as the production WSGI server.
   - The IMAP connection to Gmail is the only external service dependency that materially affects architecture.

11. **Health and observability**
   - `GET /health` is a minimal service check endpoint for deployment platforms.
   - It provides a simple indicator that the web process is running, independent of mailbox contents.

12. **Architectural summary for a diagram**
   - The main diagram should show:
     - Browser/User → Flask app (`app.py`)
     - Flask app → IMAP client (`imap_client.py`)
     - IMAP client → Gmail IMAP server
     - Flask app → Jinja template (`templates/inbox.html`) → Browser
   - The key boundary is between the internal web app and the external Gmail IMAP service.

Main entry points: [`app.py`](https://github.com/raghavendraatb/mail-portal/blob/main/app.py) (Flask app), [`imap_client.py`](https://github.com/raghavendraatb/mail-portal/blob/main/imap_client.py) (IMAP client), [`templates/inbox.html`](https://github.com/raghavendraatb/mail-portal/blob/main/templates/inbox.html) (Inbox view)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_gunicorn["Gunicorn<br/>WSGI server"]
  node_env["Env vars<br/>config"]
end

subgraph group_app["App"]
  node_app_py["Flask app<br/>web app<br/>[app.py]"]
  node_imap_client["IMAP client<br/>mail adapter<br/>[imap_client.py]"]
  node_inbox_template["Inbox view<br/>Jinja template<br/>[inbox.html]"]
end

subgraph group_external["External"]
  node_gmail_imap[("Gmail IMAP<br/>external mail service")]
  node_browser(("User browser<br/>client"))
end

node_browser -->|"HTTP request"| node_gunicorn
node_gunicorn -->|"serves"| node_app_py
node_app_py -->|"fetch mail"| node_imap_client
node_imap_client -->|"read creds"| node_env
node_imap_client -->|"IMAP login"| node_gmail_imap
node_app_py -->|"render"| node_inbox_template
node_inbox_template -->|"HTML response"| node_browser
node_browser -.->|"refresh"| node_app_py
node_app_py -->|"health JSON"| node_browser

click node_app_py "https://github.com/raghavendraatb/mail-portal/blob/main/app.py"
click node_imap_client "https://github.com/raghavendraatb/mail-portal/blob/main/imap_client.py"
click node_inbox_template "https://github.com/raghavendraatb/mail-portal/blob/main/templates/inbox.html"

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_gunicorn,node_env toneBlue
class node_app_py,node_imap_client,node_inbox_template toneAmber
class node_gmail_imap,node_browser toneMint
```

## Components

### Runtime

Python web service runtime and deployment boundary.

- **Gunicorn**: WSGI server · Production entrypoint for the Flask app.
- **Env vars**: config · Provides Gmail credentials and deployment configuration.

### App

Flask request handling and server-side rendering.

- [Flask app](https://github.com/raghavendraatb/mail-portal/blob/main/app.py): web app · Handles HTTP routes and orchestrates mailbox fetch plus rendering. · `app.py`
- [IMAP client](https://github.com/raghavendraatb/mail-portal/blob/main/imap_client.py): mail adapter · Connects to Gmail IMAP and fetches messages using env credentials. · `imap_client.py`
- [Inbox view](https://github.com/raghavendraatb/mail-portal/blob/main/templates/inbox.html): Jinja template · Server-rendered inbox UI showing message details and refresh state. · `templates/inbox.html`

### External

Outside systems the app depends on.

- **Gmail IMAP**: external mail service · Source of truth for mailbox contents.
- **User browser**: client · Sends requests and receives rendered inbox HTML.

## Connections

- User browser → Gunicorn: HTTP request · User requests the inbox or health endpoint.
- Gunicorn → Flask app: serves · WSGI server runs the Flask application.
- Flask app → IMAP client: fetch mail · Inbox route asks for current messages.
- IMAP client → Env vars: read creds · Loads Gmail username and app password from environment.
- IMAP client → Gmail IMAP: IMAP login · Connects directly to Gmail mailbox over IMAP.
- Flask app → Inbox view: render · Passes messages and timestamp into the template.
- Inbox view → User browser: HTML response · Returns the server-rendered inbox page.
- User browser → Flask app: refresh · Refresh reissues GET / and triggers a fresh IMAP fetch.
- Flask app → User browser: health JSON · GET /health returns a lightweight service check.
