chapter three
3 Building the domain core
This chapter covers
- Building domain entities that enforce business invariants at construction time
- The Always-Valid Domain Model: Why invalid objects should never exist
- Factory methods as the only gateway into your domain
- Value objects that make implicit concepts explicit
- Domain services for logic that spans multiple entities
- Validation strategies: What works, what fails, and the recommended approach
We’ve mapped the five migration phases for WriteFlow. Phase 1—Extract the domain—is where we start building. Most teams reach this point after the hard part is already done: stakeholders are aligned, the migration has been approved, and everyone agrees the current system is too fragile to evolve safely. What comes next is often less obvious. When you start from the middle of the hexagon, you are solving a very specific problem: how to rebuild the business core so that invalid states become impossible, rules live in one place, and the domain can evolve independently of frameworks.