chapter nine

9 Building WriteFlow: The complete implementation

 

This chapter covers

  • Assembling a complete vertical slice from domain core to REST adapter
  • Applying the always-valid model, ports, handlers, and adapters as one cohesive build
  • Wiring a command and a query path through the bus
  • Consuming one domain event two ways through two separate listeners
  • Choosing in-memory and fake adapters where infrastructure is not the lesson
  • Mapping the finished application back to the ArchUnit rules and testing recipes

We’ve built WriteFlow one concern at a time. This chapter introduces no new patterns, and almost no new code. That is the point. Nearly every artifact here is one you already wrote in chapters 3 through 8, as we built WriteFlow step by step. What was missing was the whole: until now you have seen the pieces in isolation, each illustrating one idea. This chapter assembles them into a single, continuous, runnable build, from the innermost value object to the outermost HTTP response, with no gaps, and adds only the thin connective tissue (the composition root, the listeners, the controller wiring) that the full assembly demands. You will not retype the domain core or the handlers; you will watch them snap into place. If a class in this chapter surprises you, the surprise belongs to an earlier chapter; here we only connect what those chapters established.

9.1 What we are building

9.2 The domain core

9.2.1 Value objects: The smallest always-valid things

9.2.2 The status: A two-state lifecycle

9.2.3 The Article aggregate: Creation, reconstitution, and behaviour

9.2.4 The domain event: A primitive-typed, cross-boundary contract

9.2.5 What the domain guarantees

9.3 The ports

9.3.1 Commands and queries carry primitives, not domain types

9.3.2 Input ports: The use cases the application offers

9.3.3 The read-side DTO

9.3.4 Output ports: What the application needs from the world

9.3.5 The contracts are complete

9.4 The handlers

9.4.1 Creating a draft: The simplest handler

9.4.2 Publishing: The handler at the heart of the chapter

9.4.3 One event, two phases: The listeners

9.4.4 Reading: The query handler

9.4.5 The two paths at runtime

9.5 Adapters: Wiring the core to the outside world

9.5.1 The persistence adapter

9.5.2 The transactional outbox

9.5.3 The event bridge and the notification fake

9.5.4 The REST driving adapter

9.5.5 The edges are built, nothing is connected

9.6 Assembly: The composition root

9.6.1 The bootstrap class

9.6.2 Wiring beans by stereotype, not by name