# tejasghatte/interact-mailer-microservice architecture

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

- Interactive diagram: https://gitdiagram.com/tejasghatte/interact-mailer-microservice
- Repository: https://github.com/tejasghatte/interact-mailer-microservice

## Overview

##### Project Type & Purpose
- It’s a standalone backend microservice:
- Exposes HTTP endpoints for authentication (OTP flows) and sending email notifications.
- Houses ~80+ HTML templates mapped to numeric “types” (per README) for different notification scenarios.
- Uses Nodemailer to dispatch messages via an external SMTP provider.

##### Top-Level Components
- “deployment” & Docker artifacts
- NGINX reverse-proxy (deployment/nginx)
- Dockerfile + docker-compose.yml for containerization and local orchestration
- Runtime service (“src”)
- HTTP server entrypoint (src/index.ts)
- Configuration (src/config)
- Middleware (src/middlewares)
- Controllers (src/controllers)
- Mailer module (src/mailers)
- Error & helper utilities (src/helpers, src/utils)
- Email templates (src/templates)

##### External Dependencies
- SMTP server (e.g. SendGrid, SES, corporate mail)
- GitHub Actions (deployment via .github/workflows/deployment.yml)

##### Core Request Flow & Interactions
1) API Client or upstream service calls HTTP endpoint →
2) NGINX (reverse proxy/load balancer) →
3) Express server (src/index.ts)
- CORS (src/config/cors.ts)
- JWT validation (src/middlewares/protect.ts)
- Route dispatch (src/routes/mailer.ts, auth routes)
- Controller logic (src/controllers/mailer.ts, auth.ts)
- Template lookup (src/templates/<type>.html)
- Nodemailer sendMail (src/mailers/nodemailer.ts)
4) External SMTP provider
5) Response back to client

##### Architectural Patterns & Principles
- Layered (Config → Middleware → Controllers → Services → External)
- Centralized error handling (src/controllers/error.ts + src/helpers/app_error.ts)
- Async error wrapper (src/helpers/catch_async.ts)
- Type safety (TypeScript declarations in src/types)
- Dockerized deployment + CI/CD via GitHub Actions

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client/API Consumer"]:::external
    NGINX["NGINX Reverse Proxy"]:::infra
    Express["Express Service Container"]:::service
    SMTP["SMTP Provider"]:::external
    Docker["Docker & Compose"]:::infra
    CICD["GitHub Actions Pipeline"]:::infra

    subgraph "Express Service"
        subgraph Config
            Cors["CORS"]:::config
            Env["Env"]:::config
            JWTconf["JWT"]:::config
            Mailerconf["Mailer Config"]:::config
        end
        Protect["JWT Protection"]:::middleware
        Router["Routes"]:::router
        subgraph Controllers
            AuthCtrl["Auth Controller"]:::controller
            MailerCtrl["Mailer Controller"]:::controller
            ErrorCtrl["Error Controller"]:::controller
        end
        MailerSvc["Mailer Service"]:::service
        subgraph Helpers
            AppErr["AppError"]:::helper
            CatchAsync["CatchAsync"]:::helper
        end
        subgraph Templates
            Templates["Email Templates"]:::template
        end
        subgraph Utils
            Comment["comment.ts"]:::util
            Logger["logger.ts"]:::util
            Session["session.ts"]:::util
            Validator["validator.ts"]:::util
        end
        subgraph Types
            TypesIndex["index.ts"]:::type
            ReqTypes["request.d.ts"]:::type
        end
        Public["Public Assets"]:::infra
        Metadata["Metadata & Scripts"]:::infra
    end

    Client -->|requests| NGINX
    NGINX -->|forwards| Express
    Express -->|sends email| SMTP
    SMTP -->|response| Express
    Express -->|response| NGINX
    NGINX -->|returns| Client

    Express --> Cors
    Express --> Env
    Express --> JWTconf
    Express --> Mailerconf
    Cors --> Protect
    Env --> Protect
    JWTconf --> Protect
    Mailerconf --> Protect
    Protect --> Router
    Router --> AuthCtrl
    Router --> MailerCtrl
    AuthCtrl --> AppErr
    MailerCtrl --> AppErr
    AuthCtrl --> CatchAsync
    MailerCtrl --> CatchAsync
    AuthCtrl --> Comment
    AuthCtrl --> Logger
    MailerCtrl --> Logger
    MailerCtrl --> Session
    MailerCtrl --> Validator
    AuthCtrl --> TypesIndex
    MailerCtrl --> TypesIndex
    AuthCtrl --> ReqTypes
    MailerCtrl --> ReqTypes
    MailerCtrl --> MailerSvc
    MailerSvc --> Templates
    MailerSvc --> SMTP
    ErrorCtrl --> AppErr
    ErrorCtrl --> CatchAsync
    Public --> Express
    Metadata --> Express

    click Cors "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/config/cors.ts"
    click Env "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/config/env.ts"
    click JWTconf "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/config/jwt.ts"
    click Mailerconf "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/config/mailer.ts"
    click Protect "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/middlewares/protect.ts"
    click Router "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/routes/mailer.ts"
    click AuthCtrl "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/controllers/auth.ts"
    click MailerCtrl "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/controllers/mailer.ts"
    click ErrorCtrl "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/controllers/error.ts"
    click MailerSvc "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/mailers/nodemailer.ts"
    click AppErr "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/helpers/app_error.ts"
    click CatchAsync "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/helpers/catch_async.ts"
    click Templates "https://github.com/tejasghatte/interact-mailer-microservice/tree/main/src/templates"
    click Comment "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/utils/comment.ts"
    click Logger "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/utils/logger.ts"
    click Session "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/utils/session.ts"
    click Validator "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/utils/validator.ts"
    click TypesIndex "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/types/index.ts"
    click ReqTypes "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/src/types/request.d.ts"
    click Public "https://github.com/tejasghatte/interact-mailer-microservice/tree/main/public/"
    click Metadata "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/package.json"

    click NGINX "https://github.com/tejasghatte/interact-mailer-microservice/tree/main/deployment/nginx/"
    click Docker "https://github.com/tejasghatte/interact-mailer-microservice/tree/main/Dockerfile"
    click Docker "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/docker-compose.yml"
    click CICD "https://github.com/tejasghatte/interact-mailer-microservice/blob/main/.github/workflows/deployment.yml"

    classDef infra fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef service fill:#90EE90,stroke:#333,stroke-width:1px
    classDef config fill:#D0F0C0,stroke:#333,stroke-width:1px
    classDef middleware fill:#98FB98,stroke:#333,stroke-width:1px
    classDef router fill:#AFEEEE,stroke:#333,stroke-width:1px
    classDef controller fill:#66CDAA,stroke:#333,stroke-width:1px
    classDef helper fill:#FFFACD,stroke:#333,stroke-width:1px
    classDef template fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef util fill:#E0FFFF,stroke:#333,stroke-width:1px
    classDef type fill:#E6E6FA,stroke:#333,stroke-width:1px
```
