# tutadeploy/sms-serve architecture

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

- Interactive diagram: https://gitdiagram.com/tutadeploy/sms-serve
- Repository: https://github.com/tutadeploy/sms-serve

## Overview

##### Project Type and Its Purpose
- This project is a full-stack backend application built with the NestJS framework. Its purpose is to act as a centralized SMS and email sending platform that supports multiple channels, template management, batch messaging, state querying, logging, and integration with external systems (e.g., SMS/email providers, MySQL, and Redis).
- The README and file tree indicate a modular, service-oriented structure with clearly separated modules for authentication, users, notifications, SMS messages, email messages, templates, payments, tenants, etc.

##### File Structure
- The main code resides in the “src/” directory. Each subdirectory (e.g., account, auth, captcha, email-message, sms-provider, sms, notification, template, tenant, user, etc.) represents a distinct module with its own controllers, services, DTOs, and entity definitions.
- Database migration files (in “db/” and “src/migrations/”) indicate that TypeORM is used for the persistence layer with MySQL.
- “docker-compose.yml” and “mysql.cnf” reveal the containerized components (MySQL, Redis, possibly other infrastructure) used in the project.

##### Extract Architectural Insights from the README
- The project's README highlights key system features: multi-channel support, template management, batch message sending via queues (likely implemented using Bull), API documentation (Swagger/OpenAPI), and extensive logging with Winston.
- The deployment instructions (Docker, environment variable configuration) imply that the design should accommodate a containerized production environment.

##### Main Components
- API Gateway / HTTP Layer:
- Controllers (REST endpoints for authentication, SMS, email, user management, etc.)
- A Swagger/OpenAPI documented interface accessible at /api-docs
- Modular Business Logic Layers:
- Authentication & Authorization Module: Includes JWT and local strategies, guards, and services.
- User, Account, and Tenant Modules: For managing users’ data, account details, and multi-tenant information.
- Payment Module: Handling payment and billing operations.
- Template Module: For SMS/Email template management.
- Notification Module: Orchestrates SMS/email sending logic that interacts with multiple provider-specific modules.
- External Integration Components:
- SMS and Email Providers: Represent the modules like “sms-provider” and “sms-provider-onbuka” that integrate with external third-party services.
- Queue/Batch Processors: Outline components for handling asynchronous, batch processing (using Bull for queue management).
- Persistence and Infrastructure Layers:
- MySQL Database: Backed by TypeORM for data operations and migration management.
- Redis Cache: For caching and queue management purposes.
- Logging System: Using Winston for multi-level logging.
- Infrastructure and Deployment Elements:
- Containerization using Docker/Docker Compose for managing MySQL, Redis, and the application runtime.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Gateway Layer
    subgraph "API Gateway Layer"
        A1["App Controller"]:::controller
        A2["App Module"]:::controller
    end

    %% Business Modules Layer
    subgraph "Business Modules"
        %% Authentication Module
        subgraph "Authentication Module"
            B1["Auth Module"]:::module
        end
        %% User Management
        subgraph "User Management"
            B2["User Module"]:::module
        end
        %% Account & Tenant Modules
        subgraph "Account & Tenant Modules"
            B3["Account Module"]:::module
            B4["Tenant Module"]:::module
        end
        %% Payment Module
        subgraph "Payment Module"
            B5["Payment Module"]:::module
        end
        %% Template Module
        subgraph "Template Module"
            B6["SMS Template Module"]:::module
            B7["Email Template Module"]:::module
        end
        %% Notification Module
        subgraph "Notification Module"
            B8["Notification Module"]:::module
        end
        %% SMS Handling
        subgraph "SMS Handling"
            B9["SMS Module"]:::module
            B10["SMS API"]:::module
            B11["SMS Dispatcher"]:::module
        end
        %% Email Handling
        subgraph "Email Handling"
            B12["Email Message Module"]:::module
            B13["Email Batch Processor"]:::module
        end
    end

    %% External Integrations
    subgraph "External Integrations"
        C1["SMS Provider Integration"]:::external
        C2["Onbuka Provider Integration"]:::external
    end

    %% Persistence & Infrastructure
    subgraph "Persistence & Infrastructure"
        D1["MySQL Database"]:::database
        D2["Redis Cache"]:::cache
        D3["TypeORM Config"]:::persistence
        D4["Data Source"]:::persistence
        D5["Migration Scripts (db/src)"]:::persistence
        D6["Winston Logging"]:::infrastructure
        D7["Docker Compose"]:::infrastructure
        D8["MySQL Config"]:::infrastructure
    end

    %% Connections from API Gateway to Business Modules
    A1 -->|"authCall"| B1
    A1 -->|"userCall"| B2
    A1 -->|"accountCall"| B3
    A1 -->|"tenantCall"| B4
    A1 -->|"paymentCall"| B5
    A1 -->|"smsTemplate"| B6
    A1 -->|"emailTemplate"| B7
    A1 -->|"notify"| B8
    A1 -->|"smsProc"| B9
    A1 -->|"smsApi"| B10
    A1 -->|"smsDispatch"| B11
    A1 -->|"emailMsg"| B12
    A1 -->|"emailBatch"| B13

    %% Business Modules interacting with External Integrations
    B8 -->|"sendsSMS"| C1
    B8 -->|"sendsSMS"| C2

    %% Business Modules interacting with Persistence & Infrastructure
    B1 ---|"ORM"| D3
    B1 --- D4
    B2 --- D1
    B3 --- D1
    B4 --- D1
    B5 --- D1
    B6 --- D1
    B7 --- D1
    B8 ---|"cache/queue"| D2
    B9 --- D1
    B10 --- D1
    B11 --- D1
    B12 --- D1
    B13 --- D1

    %% Logging connection (all modules log to Winston)
    B1 ---|"logs"| D6
    B2 --- D6
    B3 --- D6
    B4 --- D6
    B5 --- D6
    B6 --- D6
    B7 --- D6
    B8 --- D6
    B9 --- D6
    B10 --- D6
    B11 --- D6
    B12 --- D6
    B13 --- D6

    %% Infrastructure supporting Persistence components
    D7 --- D1
    D7 --- D2
    D8 --- D1

    %% Click Events
    click A1 "https://github.com/tutadeploy/sms-serve/blob/main/src/app.controller.ts"
    click A2 "https://github.com/tutadeploy/sms-serve/blob/main/src/app.module.ts"
    click B1 "https://github.com/tutadeploy/sms-serve/tree/main/src/auth"
    click B2 "https://github.com/tutadeploy/sms-serve/tree/main/src/user"
    click B3 "https://github.com/tutadeploy/sms-serve/tree/main/src/account"
    click B4 "https://github.com/tutadeploy/sms-serve/tree/main/src/tenant"
    click B5 "https://github.com/tutadeploy/sms-serve/tree/main/src/payment"
    click B6 "https://github.com/tutadeploy/sms-serve/tree/main/src/template"
    click B7 "https://github.com/tutadeploy/sms-serve/tree/main/src/email-template"
    click B8 "https://github.com/tutadeploy/sms-serve/tree/main/src/notification"
    click B9 "https://github.com/tutadeploy/sms-serve/tree/main/src/sms"
    click B10 "https://github.com/tutadeploy/sms-serve/tree/main/src/sms-api"
    click B11 "https://github.com/tutadeploy/sms-serve/tree/main/src/sms-dispatcher"
    click B12 "https://github.com/tutadeploy/sms-serve/tree/main/src/email-message"
    click B13 "https://github.com/tutadeploy/sms-serve/tree/main/src/email-notification-batch"
    click C1 "https://github.com/tutadeploy/sms-serve/tree/main/src/sms-provider"
    click C2 "https://github.com/tutadeploy/sms-serve/tree/main/src/sms-provider-onbuka"
    click D3 "https://github.com/tutadeploy/sms-serve/blob/main/src/common/config/typeorm.config.ts"
    click D4 "https://github.com/tutadeploy/sms-serve/blob/main/src/data-source.ts"
    click D5 "https://github.com/tutadeploy/sms-serve/tree/main/db/migrations"
    click D2 "https://github.com/tutadeploy/sms-serve/blob/main/src/config/redis.config.ts"
    click D6 "https://github.com/tutadeploy/sms-serve/blob/main/src/common/config/logger.config.ts"
    click D7 "https://github.com/tutadeploy/sms-serve/blob/main/docker-compose.yml"
    click D8 "https://github.com/tutadeploy/sms-serve/blob/main/mysql.cnf"

    %% Styles
    classDef module fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef controller fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef external fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef database fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef cache fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef persistence fill:#D6EAF8,stroke:#1F618D,stroke-width:2px;
    classDef infrastructure fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
