How raghavendraatb/mail-portal works
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 Flask app · imap_client.py IMAP client · inbox.html Inbox view
Components 7
Runtime
Python web service runtime and deployment boundary.
- Gunicorn · Production entrypoint for the Flask app.
- Env vars · Provides Gmail credentials and deployment configuration.
App
Flask request handling and server-side rendering.
- Flask app · Handles HTTP routes and orchestrates mailbox fetch plus rendering.
app.py - IMAP client · Connects to Gmail IMAP and fetches messages using env credentials.
imap_client.py - Inbox view · Server-rendered inbox UI showing message details and refresh state.
templates/inbox.html
External
Outside systems the app depends on.
- Gmail IMAP · Source of truth for mailbox contents.
- User browser · Sends requests and receives rendered inbox HTML.
Connections 9
- 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.