Learning path
New to Domain-Driven Design? Read the pages in this order: each step builds on the one before, and each page explains one idea with the same Order example.
An introduction, not a course
These pages explain each idea as far as you need it to use Alveolus. They are not a complete course on Domain-Driven Design. For the whole picture, read the books:
- Domain-Driven Design: Tackling Complexity in the Heart of Software, Eric Evans, 2003
- Implementing Domain-Driven Design, Vaughn Vernon, 2013
- Domain-Driven Design Distilled, Vaughn Vernon, 2016
- Learning Domain-Driven Design, Vlad Khononov, 2021
- For
- Developers who know TypeScript and have never used Domain-Driven Design
- You need
- TypeScript and classes, nothing about DDD
- Order
- The one of Domain-Driven Design Distilled (Vaughn Vernon, 2016): split the system first, then model each part
Already know DDD?
Go straight to Getting started and come back to a page when you need it.
Why DDD
Software gets hard to change when its code no longer says what the business means. DDD puts the business at the center of the code, in its own words.
Split the system
Before writing a class, decide where its words apply. A "product" in the catalog and a "product" in ordering are not the same thing: each part of the system gets its own model.
Model the rules
Inside a context, the domain holds the business rules. Start from the smallest pieces and build up to the aggregate, the object that keeps the rules of an order.
OrderId, checked once and never changed.Order and its lines, changed as one unit through the root that keeps the rules.Record what happened
When the rules accept a change, the aggregate records it as a fact other code can react to.
OrderPlaced.Reach the outside world
The domain still needs things it does not own: a rule spread over several objects, a price from elsewhere, a place to store orders. It asks for them in its own words.
Run a use case
The application layer turns a request, such as "place this order", into a call to the domain, and saves the result.
Talk to other contexts
Contexts never import each other. They tell each other what happened in plain JSON, and each one translates what it reads into its own model.
Keep it on track
Each idea above becomes a rule the checks verify, so the code keeps it whoever writes it.
alveolus arch check reports, and why.See also
- Getting started, to install Alveolus and run the checks
- Project layout, the folders and layers of a project
- Building blocks, every class
@alveolus/coregives