How zatribune/springboot-ddd-example works
Main Components
• Domain Layer: This is at the heart of the project and represents the business logic and rules. In our file tree, it’s the “domain” module. It contains domain objects, aggregates, entities, value objects, events, DTOs, and contracts (adapter interfaces).
• Infrastructure Layer: This module (“infrastructure”) implements the adapter contracts from the domain, handling external interactions such as REST controllers, database repositories, entity mappings, error handling, and services that execute the domain’s contracts.
• Application Layer: Located in the “application” module, this layer wires together configurations and acts as the point of control, using Spring Boot’s features. It orchestrates calls between the domain and infrastructure modules.
• API Definition: The “api-definition” contains the OpenAPI specification (openapi.yaml) which defines how external clients interact with your service. This provides a contract for the endpoints and could be considered an external-facing part of the system.
Relationships and Interactions
• The Application layer depends on both Domain and Infrastructure layers. It is responsible for initiating operations (like order submission) which transit into the Infrastructure layer for validation and transformation, and then the data flows to the Domain layer where the business logic is executed.
• The Domain layer is independent; it only defines interfaces (adapters) and business objects and does not depend on Infrastructure or Application – reinforcing strong separation and independence.
• The Infrastructure layer implements the contracts from the Domain. It is responsible for converting incoming API requests (perhaps defined by the API specification in “api-definition”) into calls to Domain services.
• A clear flow exists: Client/API Request → Application Layer → Infrastructure Layer (validation, error handling, etc.) → Domain Layer (business logic processing) → Infra back → Application → Client.
• Event Bus and Event-driven interactions exist within the Domain to handle notifications or decouple operations across bounded contexts (as seen by domain event classes).
Architectural Patterns and Design Principles
• Domain Driven Design (DDD): Emphasis on dividing the system into Domain, Infrastructure, and Application layers.
• Bounded Contexts and Aggregates: Business functionality is encapsulated into separate aggregates within domain contexts (e.g., CustomerOrder and ShippingProcess).
• Adapter Pattern: Domain contracts (interfaces) are implemented by the Infrastructure layer.
• Event-Driven Architecture: The project uses an event bus within the domain to pass events and data, decoupling components that require eventual consistency.
• Clear separation of concerns: Domain remains framework agnostic; Infrastructure handles external integration details, and Application ties configurations together.