# tnqbao/gau_validation_service architecture

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

- Interactive diagram: https://gitdiagram.com/tnqbao/gau_validation_service
- Repository: https://github.com/tnqbao/gau_validation_service

## Overview

##### Project Overview
- This project is a RESTful API for sending emails and SMS messages. It’s built using the Gin framework for handling HTTP requests and GORM for database interactions. The API also features middleware for JWT-based authentication and CORS handling.
- The software is designed with a modular structure, with separate components for API endpoints (healthcheck, mail, sms), configuration, middleware, and supporting providers (helpers and types).

##### Main Components of the System
- API Endpoints:
- Healthcheck Service (api/healthcheck)
- Mail Service (api/mail) – includes functions for sending and checking OTPs via email.
- SMS Service (api/sms) – includes functions for sending and checking OTPs via SMS.
- Middleware:
- Authentication (middlewares/auth.go)
- CORS (middlewares/cors.go)
- Routing and Server Bootstrapping:
- Main application file (main.go)
- Routes definitions (routes/routes.go)
- Configuration:
- Database configurations (config/database.go)
- Redis configurations (config/redis.go)
- Utility Providers:
- Helper functions and types (providers/helpers.go, providers/types.go)
- Deployment and Build:
- Dockerfile for containerization.
- GitHub workflows for CI/CD deployments (.github/workflows/deploy-production.yml and deploy-staging.yml).

##### Relationships and Interactions among Components
- The RESTful endpoints (healthcheck, mail, sms) are hooked into the HTTP server via the routes defined in routes/routes.go.
- Middleware components (auth and cors) wrap the endpoints to enforce security and enable cross-origin requests.
- The main.go file orchestrates the startup of the server, handles database/Redis migrations, and links all the above modules.
- Configuration modules (database and redis) are used to initialize connections that can be accessed by other components (for example, GORM for DB operations and a Redis client for caching or session management).
- Providers supply helper functions that are shared across the application (such as formatting or common types).

##### Important Architectural Patterns and Technologies
- Modular design: Each functional area (API endpoints, middleware, configuration, etc.) is separated into its own directory.
- RESTful design: Follows standard REST principles for endpoint design.
- Use of Gin web framework and middleware to separate concerns and secure endpoints.
- Dependency management and builds are handled via Go modules (go.mod, go.sum) and Docker for containerization.
- CI/CD workflow is integrated through GitHub Actions for automated deployment to production and staging.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client Requests"]:::external
    subgraph "Application Entry"
        Main["HTTP Server (Gin)"]:::main
    end
    subgraph "Routing Layer"
        Routes["Routes & Endpoint Integration"]:::routes
    end
    subgraph "Middleware Layer"
        Auth["Authentication Middleware"]:::middleware
        CORS["CORS Middleware"]:::middleware
    end
    subgraph "API Layer"
        HC["Healthcheck Service"]:::api
        Mail["Mail Service"]:::api
        SMS["SMS Service"]:::api
    end
    subgraph "Configuration & Persistence"
        DB["Database Configuration (GORM)"]:::config
        Redis["Redis Configuration"]:::config
    end
    subgraph "Utility Providers"
        Helpers["Helpers"]:::provider
        Types["Types"]:::provider
    end
    subgraph "Deployment & CI/CD"
        Docker["Docker"]:::deployment
        GH_Prod["GitHub Workflow: Deploy Production"]:::deployment
        GH_Staging["GitHub Workflow: Deploy Staging"]:::deployment
    end
    subgraph "External Service Providers"
        SMTP["SMTP Provider"]:::external
        Twilio["Twilio SMS Provider"]:::external
    end

    Client --> Main
    Main --> Routes
    Routes --> Auth
    Routes --> CORS
    Auth --> HC
    CORS --> HC
    Auth --> Mail
    CORS --> Mail
    Auth --> SMS
    CORS --> SMS
    HC --- DB
    Mail --- DB
    SMS --- DB
    HC --- Redis
    Mail --- Redis
    SMS --- Redis
    Mail --> Helpers
    Mail --> Types
    SMS --> Helpers
    SMS --> Types
    Mail -->|"sendsmail"| SMTP
    SMS -->|"sendssms"| Twilio
    Docker --- Main
    GH_Prod --- Docker
    GH_Staging --- Docker

    classDef main fill:#f9f,stroke:#333,stroke-width:2px;
    classDef routes fill:#ccf,stroke:#333,stroke-width:2px;
    classDef middleware fill:#9f9,stroke:#333,stroke-width:2px;
    classDef api fill:#cff,stroke:#333,stroke-width:2px;
    classDef config fill:#fc9,stroke:#333,stroke-width:2px;
    classDef provider fill:#ff9,stroke:#333,stroke-width:2px;
    classDef deployment fill:#c9f,stroke:#333,stroke-width:2px;
    classDef external fill:#eee,stroke:#333,stroke-width:2px;

    click Main "https://github.com/tnqbao/gau_validation_service/blob/main/main.go"
    click Routes "https://github.com/tnqbao/gau_validation_service/blob/main/routes/routes.go"
    click HC "https://github.com/tnqbao/gau_validation_service/blob/main/api/healthcheck/healthcheck.go"
    click Mail "https://github.com/tnqbao/gau_validation_service/blob/main/api/mail/mailSender.go"
    click Mail "https://github.com/tnqbao/gau_validation_service/blob/main/api/mail/sendOTP.go"
    click Mail "https://github.com/tnqbao/gau_validation_service/blob/main/api/mail/checkOTP.go"
    click SMS "https://github.com/tnqbao/gau_validation_service/blob/main/api/sms/sendOTP.go"
    click SMS "https://github.com/tnqbao/gau_validation_service/blob/main/api/sms/checkOTP.go"
    click Auth "https://github.com/tnqbao/gau_validation_service/blob/main/middlewares/auth.go"
    click CORS "https://github.com/tnqbao/gau_validation_service/blob/main/middlewares/cors.go"
    click DB "https://github.com/tnqbao/gau_validation_service/blob/main/config/database.go"
    click Redis "https://github.com/tnqbao/gau_validation_service/blob/main/config/redis.go"
    click Helpers "https://github.com/tnqbao/gau_validation_service/blob/main/providers/helpers.go"
    click Types "https://github.com/tnqbao/gau_validation_service/blob/main/providers/types.go"
    click Docker "https://github.com/tnqbao/gau_validation_service/tree/main/Dockerfile"
    click GH_Prod "https://github.com/tnqbao/gau_validation_service/blob/main/.github/workflows/deploy-production.yml"
    click GH_Staging "https://github.com/tnqbao/gau_validation_service/blob/main/.github/workflows/deploy-staging.yml"
```
