How sklinkert/go-ddd works
Main Components
• Entities (e.g., Product, Seller, ValidatedProduct, ValidatedSeller under internal/domain/entities)
• Domain repositories interfaces (located under internal/domain/repositories)
• Application Layer: Acts as the mediator between the Domain and external interfaces. It includes:
• Commands, Queries, and use-case specific operations (under internal/application/command, internal/application/query, and services)
• Mappers to transform data between layers (internal/application/mapper)
• Infrastructure Layer: Provides technical capabilities such as database access:
• Database connectivity and concrete repository implementations (under internal/infrastructure/db with separate folders for Postgres and SQLite tests)
• Interface Layer: The external-facing API which exposes the system to users or external systems:
• REST API controllers and DTOs (under internal/interface/api/rest and its subdirectories for requests, responses, and mappers)
Relationships and Interactions
• The Domain layer should be independent and does not depend on other layers.
• The Application layer uses the Domain layer to execute business logic and enforces rules by handling commands, queries, and validations.
• The Infrastructure layer implements the persistence details as defined by the Domain (and sometimes Application) interfaces.
• The Interface layer (REST API) communicates with the Application layer to handle client requests and transform external demands into commands or queries.
Architectural Patterns & Design Principles
• Onion Architecture/Layered DDD: Emphasize how the Domain is central and all other layers depend inward toward it.
• Separation of concerns and dependency inversion: Domain knows nothing about Infrastructure, but domain’s interface contracts are implemented there.
• The use of clear boundaries to allow potential future migration to a microservices architecture.
Technologies and Components
• Golang as the primary programming language.
• The repository might include tooling via GitHub workflows (for CI/CD) and dependency management with go.mod and go.sum.
• REST API endpoints to expose the service (via controllers in internal/interface/api/rest).
• Database technology specifics: Postgres in production (and SQLite tests for in-memory validation).
Importance of Detailing the Architecture
• Critical components are represented.
• Use labels for clear identification (e.g., “SellerController”, “CreateSellerCommand”, “ProductRepository”).
• Where patterns like dependency inversion and separation of concerns are applied.