How wesionaryteam/go_clean_architecture works
This project is a web server application built following Clean Architecture principles in Go. It uses the Gin Web Framework for API handling, uber-go/fx for dependency injection, and GORM for ORM support. The architecture is deliberately segmented into well-defined layers and modules to promote separation of concerns and testability.
Main Components Identification
• Entry Point & Bootstrapping: The starting point is main.go, which initializes the application. The bootstrap/ directory contains modules needed for application startup (e.g., dependency setup and service/module initialization).
• API Layer (Presentation Layer): Built with the Gin framework, this includes routing, controllers, and HTTP-related logic. For instance, files in domain/user (controller.go, route.go) handle user-specific API endpoints.
• Domain Layer (Business Logic): Located in domain/, this holds the business entities (models), constants, and domain-specific functionalities like user business logic including repositories and services.
• Infrastructure Layer: Housed in pkg/infrastructure, this layer covers connections to external systems such as databases (db.go) and AWS services—and integrates third-party services (Firebase, S3, SES, etc.).
• Services & Utilities: The pkg/services directory encapsulates core functionalities (like cognito, s3, ses service) that support the business logic, whereas pkg/utils and pkg/types offer helper functions and shared data type definitions.
• Middlewares: Found in pkg/middlewares, these components intercept HTTP requests to provide cross-cutting functionalities like authentication, rate limiting, and request uploads.
• Console & CLI Tools: The console/ directory includes entry points for running server commands, which can be used for tasks beyond the typical API serving.
• Database & Migrations: Migrations are located under migrations/, and database configuration is defined in dbconfig.yml, aligning with the overall persistence strategy.
• Docker & Deployment: Docker-related files (docker/, docker-compose.yml) indicate containerization support, which can be modeled as an external boundary for deployment, ensuring proper environment isolation.
Relationships & Interactions
• The Client (or API consumer) sends HTTP requests to the server.
• The API Gateway (Gin) receives these requests, passing them through a chain of middlewares (authentication, rate limiting, etc.) before routing to the appropriate domain layer.
• Within the Domain layer, controllers invoke services (defined in domain/user and pkg/services) that encapsulate business logic.
• Services interact with repositories that handle database operations using GORM models found in domain/models.
• Infrastructure components (from pkg/infrastructure) facilitate external service integration (e.g., AWS connectivity, Firebase).
• Bootstrap modules initialize and wire dependencies (using uber-go/fx) ensuring loose coupling across layers.
• Console commands provide alternative entry points to run server commands, maintenance tasks, or seed initial data.
Architectural Patterns & Key Technologies
• Clean Architecture Layering: Separation into API/presentation, domain, and infrastructure layers.
• Dependency Injection: Uber’s fx is used for wiring modules and managing life cycles.
• MVC-like Structure: Controllers, services, and repository patterns for domain-related functionalities.
• External Services: Integration with AWS modules, Firebase, and third-party libraries like Gin, GORM.
• Containerization: Docker files and docker-compose setup show that the application is designed with deployment in isolated environments in mind.