How dangpham112000/go-ecommerce-backend-api works
Project Type & Purpose
• This project is a backend web application developed in Go. It follows an MVC (Model-View-Controller) pattern as explicitly indicated in the README.
• The project includes features for user registration with an OTP-based verification flow, and it integrates with several external services such as MySQL (for persistence), Redis (for caching), and Kafka (for messaging/streaming).
• There are additional utilities for swagger documentation, logging, and database migration/interaction via sqlc and goose.
Main Components
a. Frontend (if any) vs. Backend:
b. Core Backend Layers (as described in README’s MVC flow):
• Users (Frontend clients/APIs)
• Controller Layer (located in internal/controller): Handles HTTP/S requests and transforms them to service calls.
• Service Layer (internal/service): Implements the business logic.
• Repository (Repo) Layer (internal/repo): Manages data access and interactions with the database.
• Models (internal/database models, internal/model, internal/po): Represent data structures and database schemas.
• Databases (MySQL as per SQL files and migration scripts)
c. Additional Infrastructure/Modules:
• Messaging and Events: Kafka components found under cmd/cli/kafka and initialization in internal/initialize/kafka.go.
• Configuration Management: Viper (cmd/cli/viper), config files in the config folder, and pkg/setting.
• API Documentation: Swagger documentation generation under cmd/swag and its docs directory.
• Middleware for authentication, logging, CORS handling, and rate limiting (located under internal/middlewares).
• Utility libraries for JWT handling, cryptography, and random number generation (internal/utils).
• Docker and deployment scripts: Dockerfile, docker-compose.yaml, and related Kafka docker configurations.
• Testing: tests directory with basic unit tests and coverage support.
Relationships & Interactions
• The Controllers pass these requests to the Service Layer.
• The Service Layer interacts with the Repository Layer which performs CRUD operations on the underlying MySQL Database.
• There are utility components and middleware sitting in between – e.g., authentication middleware intercepts requests to verify JWT tokens.
• The configuration management and logging systems (pkg/logger) are used across the application.
Highlighted Architectural Patterns & Technologies
• MVC architecture with clear separation of responsibilities.
• Layered/Hexagonal architecture: Controllers, Services, Repositories, and Utility layers are clearly demarcated.
• Use of middleware for cross-cutting concerns.
• Database migration & code generation using goose and sqlc.
• Microservice integration aspects (Kafka for messaging, Docker for containerized deployments).