How tnqbao/gau_validation_service works
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.