6 The running hexagon: From pieces to system
This chapter covers
- Organizing hexagonal code into Maven modules
- Wiring ports to adapters with Spring dependency injection
- Resolving technology-agnostic transactions at runtime
- Delivering domain events within transaction boundaries
- Publishing integration events through the outbox pattern
- Separating framework wiring from application core logic
We have built every piece of WriteFlow's hexagonal architecture in isolation. The domain model guards its invariants. Commands and queries carry validated input through the bus. Handlers orchestrate without owning business logic.
Adapters translate at the boundary. Repositories persist and reconstitute domain state. Each piece is independently testable, replaceable, and comprehensible.
None of them can run.
In a real project, you rarely build every piece in complete isolation and only assemble at the end. You usually move iteratively: carve out one use case, define its ports, implement the adapters it needs, wire it, and repeat. This book separates the pieces first for teaching purposes, so the role of each part is clear before we connect them into a running system.