# sushant777/mailplatform architecture

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

- Interactive diagram: https://gitdiagram.com/sushant777/mailplatform
- Repository: https://github.com/sushant777/mailplatform

## Overview

##### Project type and purpose
- This is a full-stack, containerized web application called **Email Manager**.
- Purpose: allow users to sign up/sign in, connect multiple email accounts (Gmail, Outlook via OAuth2), view and sync messages in a unified inbox.

##### File structure
Top-level:
- backend/ – Node.js + Express app
– app.js (Express server entry)
– config/db.js (Elasticsearch or other DB connection)
– controllers/ (MVC controllers: auth.js, email.js, user.js)
– models/ (ORM or data-model classes)
– routes/ (Express routers per feature)
– middleware/auth.js (JWT auth guard)
– service/ (business logic for EmailService, GmailService, OutlookService)
– Dockerfile, package.json
- frontend/ – Static single-page HTML + CSS + JS
– HTML pages for login, signup, callbacks, inbox, compose, profile, users
– css/styles.css
– Dockerfile
- docker-compose.yml – defines frontend, backend (and possibly Elasticsearch) containers
- README.md, Notes.txt, .gitignore

##### README for additional insights
- Tech stack: Node.js, Express, OAuth2, Gmail API, Microsoft Graph API, Elasticsearch (for storage/indexing).
- Deployment: Docker Compose with environment variables (.env in backend) for DB, JWT secret, OAuth credentials.
- Workflow: frontend served at `http://localhost:8080`; backend API at `http://localhost:3005`.

a. Main components
1. Client Web Browser (UI)
2. Frontend Container (serves static assets, JS)
3. Backend Container (Node.js/Express API)
4. Database (Elasticsearch or primary datastore)
5. External Services: Gmail API, Microsoft Graph API (Outlook)
6. (Optional) Docker network or orchestration layer
b. Relationships & interactions
- Browser → Frontend (HTTP request for HTML/CSS/JS)
- Frontend JS → Backend API (HTTP/REST, AJAX)
- Backend API → Database (read/write user data, emails metadata)
- Backend Service Layer → External Email APIs (OAuth2 token exchange, fetch/send emails)
- Database ←→ Backend models (persistence)
c. Architectural patterns & principles
- MVC / Layered architecture in backend (controllers → service → models)
- Separation of concerns: UI vs API vs data store
- Containerization for isolation and reproducible deployment
- OAuth2 integration for third-party APIs
d. Key technologies & frameworks
- Node.js, Express
- Elasticsearch (or other DB)
- OAuth2, Gmail API, Microsoft Graph API
- Docker, Docker Compose
- Static HTML/JS frontend

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    Browser["Web Browser"]:::client

    %% Docker Compose network
    subgraph "Docker Compose" 
        direction TB

        %% Frontend Container
        subgraph "Frontend Container"
            direction TB
            FEStatic["Static Assets"]:::frontend
            FE_index["index.html"]:::frontend
            FE_login["login.html"]:::frontend
            FE_signup["signup.html"]:::frontend
            FE_gmailCB["gmailCallBack.html"]:::frontend
            FE_outlookCB["outlookCallBack.html"]:::frontend
            FE_inbox["mailInbox.html"]:::frontend
            FE_send["sendMail.html"]:::frontend
            FE_profile["profile.html"]:::frontend
            FE_users["users.html"]:::frontend
            CSS["styles.css"]:::frontend
            FEDockerfile["Dockerfile"]:::infra
        end

        %% Backend Container
        subgraph "Backend Container"
            direction TB
            App["app.js"]:::backend
            BkdDockerfile["Dockerfile"]:::infra
            ConfigDB["config/db.js"]:::internal
            PKG["package.json"]:::internal
            PKGLOCK["package-lock.json"]:::internal

            subgraph "Controllers"
                AuthC["AuthController"]:::backend
                EmailC["EmailController"]:::backend
                UserC["UserController"]:::backend
            end

            subgraph "Routes"
                AuthR["Auth Routes"]:::backend
                EmailR["Email Routes"]:::backend
                ProfileR["Profile Routes"]:::backend
                UsersR["Users Routes"]:::backend
            end

            subgraph "Middleware"
                AuthM["Auth Middleware"]:::backend
            end

            subgraph "Services"
                EmailS["EmailService"]:::backend
                GmailS["GmailService"]:::backend
                OutlookS["OutlookService"]:::backend
            end

            subgraph "Models"
                BaseM["BaseModel"]:::backend
                UserM["User Model"]:::backend
                UserAuthM["UserAuth"]:::backend
                UserEmailM["UserEmail"]:::backend
            end
        end

        %% Database
        DB["Elasticsearch"]:::db
    end

    %% External Services
    subgraph "External Services"
        GmailAPI["Gmail API"]:::external
        OutlookAPI["Microsoft Graph API"]:::external
    end

    %% Connections
    Browser --> FEStatic
    Browser --> FE_index
    Browser --> FE_login
    Browser --> FE_signup
    Browser --> FE_gmailCB
    Browser --> FE_outlookCB
    Browser --> FE_inbox
    Browser --> FE_send
    Browser --> FE_profile
    Browser --> FE_users

    FEStatic --> CSS
    FEStatic -->|"Serves static files"| App
    FE_index -->|"AJAX to API"| App
    FE_login -->|"AJAX to API"| App
    FE_signup -->|"AJAX to API"| App
    FE_inbox -->|"AJAX to API"| App
    FE_send -->|"AJAX to API"| App
    FE_profile -->|"AJAX to API"| App
    FE_users -->|"AJAX to API"| App

    App --> AuthR
    App --> EmailR
    App --> ProfileR
    App --> UsersR

    AuthR --> AuthM
    AuthR --> AuthC
    EmailR --> AuthM
    EmailR --> EmailC
    ProfileR --> AuthM
    ProfileR --> UserC
    UsersR --> AuthM
    UsersR --> UserC

    AuthC --> EmailS
    EmailC --> EmailS
    UserC --> BaseM

    EmailS --> GmailS
    EmailS --> OutlookS

    GmailS --> GmailAPI
    OutlookS --> OutlookAPI

    BaseM --> ConfigDB
    UserM --> ConfigDB
    UserAuthM --> ConfigDB
    UserEmailM --> ConfigDB

    ConfigDB --> DB

    %% Click Events
    click FEStatic "https://github.com/sushant777/mailplatform/tree/main/frontend/"
    click FE_index "https://github.com/sushant777/mailplatform/blob/main/frontend/index.html"
    click FE_login "https://github.com/sushant777/mailplatform/blob/main/frontend/login.html"
    click FE_signup "https://github.com/sushant777/mailplatform/blob/main/frontend/signup.html"
    click FE_gmailCB "https://github.com/sushant777/mailplatform/blob/main/frontend/gmailCallBack.html"
    click FE_outlookCB "https://github.com/sushant777/mailplatform/blob/main/frontend/outlookCallBack.html"
    click FE_inbox "https://github.com/sushant777/mailplatform/blob/main/frontend/mailInbox.html"
    click FE_send "https://github.com/sushant777/mailplatform/blob/main/frontend/sendMail.html"
    click FE_profile "https://github.com/sushant777/mailplatform/blob/main/frontend/profile.html"
    click FE_users "https://github.com/sushant777/mailplatform/blob/main/frontend/users.html"
    click CSS "https://github.com/sushant777/mailplatform/blob/main/frontend/css/styles.css"
    click FEDockerfile "https://github.com/sushant777/mailplatform/tree/main/frontend/Dockerfile"

    click App "https://github.com/sushant777/mailplatform/blob/main/backend/app.js"
    click BkdDockerfile "https://github.com/sushant777/mailplatform/tree/main/backend/Dockerfile"
    click ConfigDB "https://github.com/sushant777/mailplatform/blob/main/backend/config/db.js"
    click AuthC "https://github.com/sushant777/mailplatform/blob/main/backend/controllers/auth.js"
    click EmailC "https://github.com/sushant777/mailplatform/blob/main/backend/controllers/email.js"
    click UserC "https://github.com/sushant777/mailplatform/blob/main/backend/controllers/user.js"
    click AuthM "https://github.com/sushant777/mailplatform/blob/main/backend/middleware/auth.js"
    click AuthR "https://github.com/sushant777/mailplatform/blob/main/backend/routes/auth.js"
    click EmailR "https://github.com/sushant777/mailplatform/blob/main/backend/routes/email.js"
    click ProfileR "https://github.com/sushant777/mailplatform/blob/main/backend/routes/profile.js"
    click UsersR "https://github.com/sushant777/mailplatform/blob/main/backend/routes/users.js"
    click BaseM "https://github.com/sushant777/mailplatform/blob/main/backend/models/BaseModel.js"
    click UserM "https://github.com/sushant777/mailplatform/blob/main/backend/models/User.js"
    click UserAuthM "https://github.com/sushant777/mailplatform/blob/main/backend/models/UserAuth.js"
    click UserEmailM "https://github.com/sushant777/mailplatform/blob/main/backend/models/UserEmail.js"
    click EmailS "https://github.com/sushant777/mailplatform/blob/main/backend/service/EmailService.js"
    click GmailS "https://github.com/sushant777/mailplatform/blob/main/backend/service/GmailService.js"
    click OutlookS "https://github.com/sushant777/mailplatform/blob/main/backend/service/OutlookService.js"
    click PKG "https://github.com/sushant777/mailplatform/blob/main/backend/package.json"
    click PKGLOCK "https://github.com/sushant777/mailplatform/blob/main/backend/package-lock.json"
    click DC "https://github.com/sushant777/mailplatform/blob/main/docker-compose.yml"

    %% Styles
    classDef client fill:#a2d2ff,stroke:#000
    classDef frontend fill:#8ecae6,stroke:#000
    classDef backend fill:#219ebc,stroke:#000
    classDef db fill:#52b69a,stroke:#000
    classDef external fill:#ffb703,stroke:#000
    classDef infra fill:#fb8500,stroke:#000
    classDef internal fill:#e0fbfc,stroke:#000
```
