DDD Example Project in Java: eCommerce
The DDD Example eCommerce project is a software initiative built to demonstrate the application of Domain-Driven Design (DDD) and Service-Oriented Architecture (SOA) principles in an e-commerce context. Developed using Java and the Spring framework, this project aims to provide a clear illustration of how these methodologies can be utilized to design and implement a functional e-commerce application. Here, let us delve into the details of the project.
Domains
In the context of this project, various Business Capabilities have been identified, each serving as a specific functional area within the e-commerce application.
Core Domain
The core domain encompasses fundamental business processes related to sales, including:
- Listing products for sale
- Categorizing and updating products
- Adjusting product prices
- Validating and placing orders
Supporting Subdomains
In addition to the core domain, supporting subdomains provide additional functionality to enhance the shopping experience:
- Warehouse: Manages the storage and retrieval of goods for shipping.
- Billing: Handles payment collection.
- Shipping: Oversees the dispatch of deliveries.
Potential future subdomains (not yet implemented) could include marketing, user reviews, and customer care.
Event Workflow
The project employs an event-driven architecture to facilitate communication between different domains. For instance, once a customer places an order, several events are sequentially triggered to handle shipping preparations, payment collection, and stock updates. This "happy path" workflow outlines a basic operational flow, with room for sophisticated enhancements such as error handling or timeout mechanisms for delayed events.
Services Dependencies
The services within the application are interdependent, functioning collaboratively to manage business capabilities like sales and delivery. Dependencies amongst services are mainly mediated through events, which are managed by listeners, ensuring a structured and clear separation between domains.
Architectural Overview
The architecture of the project draws on several modern design principles observed in popular frameworks like Onion, Clean, and Hexagonal architectures. It focuses on:
- Maintaining low coupling and high cohesion
- Emphasizing implementation hiding
- Adopting a rich domain model
- Clearly separating concerns
- Adhering to the Dependency Rule
The design avoids exposing internal object details, instead promoting full object encapsulation to maintain clear boundaries and avoid anti-patterns such as anemic domain models.
Screaming Architecture
This approach to architecture emphasizes its intended functionality through its structure. The project's code is organized into package domains like billing
, sales
, shipping
, and warehouse
, with further breakdown by technical concerns such as JDBC and REST interfaces.
Packaging and Assembling
The packaging strategy employs a modular approach, organizing code by domain and technical aspects. This modular monolith design allows for logical separation without physical deployment fragmentation. Services can be further divided into separate modules based on features or components, which aids in system scalability and maintainability.
Anatomy of a Service
A service is defined as the technical authority over a business capability and may align with a Bounded Context. Within the architecture, services are organized into applications, configuration, gateways, use-cases, and domain implementations. This structure provides a clear pathway for each service, from interfacing with users or other systems to implementing business logic and interacting with data.
Example of a Service Anatomy
To illustrate, consider the capability of finding payments in the billing service. This involves:
- A Spring Boot application for deployment
- A REST controller as the gateway
- Interfaces and classes for domain logic
- JDBC for data persistence
In this setup, each layer is strictly dependent on the one directly below it, ensuring a neat and understandable service outline.
Conclusion
The eCommerce project serves as a practical demonstration of DDD principles applied to a well-known industry domain. While the fundamental use cases are implemented, the project leaves room for additional features and enhancements like security and monitoring.
Where to Next
To explore further, check the alternative project branches that demonstrate modularity, microfrontends, microservices, and even a Kotlin implementation to understand its versatile applicability across various technology stacks and deployment strategies.