How javiertelioz/clean-architecture-go works
Main components
• Domain Layer:
• Contains the core business logic.
• Key folders: pkg/domain – with subdirectories for entity definitions, contracts (for repositories and services), exceptions, and domain-specific services.
• Application Layer:
• Implements business use cases.
• Folder: pkg/application/use_cases where each use case (e.g., authentication, “hello”, and user management) is encapsulated. This layer orchestrates the application logic and defines the execution path by calling into the domain when needed.
• Infrastructure Layer:
• Provides concrete implementations for contracts defined in the Domain layer.
• Includes controllers (HTTP, GraphQL), the database interactions (ORM, models, migrations), external service providers (such as Slack, crypto, and JWT implementations), and middleware (CORS and JWT authentication).
• Also contains routing definitions and server startup code.
• Presentation Layer:
• Provides user interface aspects such as localization (i18n) and serialization of responses.
• It acts as the outward facet of the application, interfacing directly with incoming HTTP requests.
Relationships and interactions
• The outer layer (Presentation & Infrastructure such as controllers and routes) receives HTTP requests (via a gin-gonic server as mentioned in the README) and hands them over to the appropriate controller.
• Controllers extract request parameters, then invoke the corresponding use case from the Application layer.
• Use Cases execute business logic by accessing domain entities, possibly calling domain services or validating business rules.
• To persist data or call external services, the system uses the Infrastructure layer’s implementations – for example, the repository (data access) from pkg/infrastructure/repository and other adapters.
Architectural patterns and design principles
• Clean Architecture/Onion Architecture: Emphasize the ringed layout of the software system with concentric layers (infrastructure controllers & presenters on the outside, application and domain in the center).
• DDD: Distinguish the Domain Model with entities, exceptions, and contracts.
• Use of middleware, controllers, and plugins for route handling and API exposure.
Relevant technologies, frameworks, and libraries
• Gin-Gonic is used as the HTTP server framework.
• GraphQL is supported as shown in pkg/infrastructure/graphql (with query, mutation, and resolver components).
• Database access is handled via an ORM implementation included in pkg/infrastructure/database along with a postgres-specific repository.
• Additional services include slack integration, JWT-based authentication, and crypto services.
• Testing and mocks are structured under the test directory for unit and integration testing which validate the use cases and controller behavior.
• HTTP Request → Controller (in Infrastructure) → Use Case (Application) → Domain Entity/Service.
• Also, show calls from use cases to infrastructural components (like repositories) and from controllers to routing middleware.
• Adding details such as:
• Configuration and bootstrap components (e.g., in pkg/infrastructure/bootstrap.go) which initialize the server and dependency injection.
• Testing and mocks layers as separate components clearly meant for unit/integration purposes (to emphasize isolation of concerns).