DDD as Code + Spec-Driven Development

When Code Is Cheap: Software Engineering in 2027

Ivan Garcia Sainz-Aja speaking at Spring I/O 2025
Ivan Garcia Sainz-Aja

Agentic builder · Java Tech Lead · AsyncAPI TSC member · Spring I/O speaker
Building ZenWave SDK and ZenWave Platform

Design and verification are the new bottlenecks,
and Markdown is making things worse.

Spec-Driven Development is the way, but in order to leverage long-running autonomous agentic coding loops we need specs that are detailed enough to leave nothing to guess. That leaves two options:

Write the spec by hand, and you may end up writing more text than the code itself.

Let an agent write it, and you end up with more Markdown than you can review and approve.

My proposal in a nutshell is DDD as Code:

  • compact domain models you and your agents can read,
  • instead of piles of Markdown specs.

Two DSLs for capturing EventStorming as code:

  • ZFL Process level: the business flows across services.
  • ZDL Software design level: the design of each service or module.

How do I know it works? Arcadia Editions

An entire e-commerce system, Arcadia Editions, fits in 7 files (1 ZFL + 6 ZDL), ~14k tokens: a fraction of the smart zone of your agent's context window.

I built Arcadia Editions using only the models as specs for the agents

fileLOCNCLOCtokens (est.)
place-order-flow.zfl 346 178 ~3.5k
orders-checkout.zdl 184 149 ~1.5k
catalog-inventory.zdl 263 193 ~1.9k
catalog-products.zdl 107 90 ~0.7k
payments-processing.zdl 252 174 ~2.2k
fulfillment-shipping.zdl 157 117 ~1.2k
notifications-consumer.zdl 145 116 ~1.1k
total1,4541,017~14k
  • Modular monolith Spring Boot · JavaSpring Boot · KotlinQuarkus
  • Microservices orders-checkoutcatalog-inventorypayments-processingfulfillment-shippingnotifications-consumer

You can use the rest of this page to dive deeper into different aspects.

Generating code becomes cheap. Design and verification are a bottleneck. Code quality is a problem.

When generating code becomes cheap, what remains are the three pillars of software engineering:

  • Understanding the domain DDD as Code
  • Proving the design is correct Formal Verification
  • Validating the result Verification Contract

All three happen before the spec goes to the agent.

The three pillars of agentic engineering: Domain-Driven Design, Formal Verification and Behaviour Validation feeding a code generation machine.

Spec-driven development in two loops

  • Human in the Loop (HITL). Discover the business with Domain-Driven Design and capture the findings in models a human can read and approve.
  • Away From Keyboard (AFK). Agents split those models into a backlog of tasks. Once I approve that backlog, an orchestrator agent runs the loop on its own.

My focus is the human loop. The agentic loop is a technical challenge, and it will keep changing as the tools evolve. The lasting work is getting models a human can read and approve, and that stay in the team's heads.

Human in the loop: domain models you can read and approve.
Away from keyboard: agents implement the approved models.

The problem: Markdown is the bottleneck

To let the agentic loop run on its own you need a spec that is sharp and concrete, detailed down to the level where the agent doesn't need to ask. Two options:

  • You write it by hand, and you may end up writing more text than the code itself.
  • An LLM writes it, and you cannot possibly read and validate it at the speed of an agent. Decisions slip in unread, and the agent takes them as gospel.
An engineer drowning in a flood of Markdown pages written by an LLM.

The proposal: Domain-Driven Design as Code

My answer is not new. It is model-driven development: instead of describing the system in prose, you describe it with a model. I take the EventStorming sessions to code, at two zoom levels, with one DSL each:

  • Process level: the business flows across services. ZFL.
  • Design level: the software design of each service or module. ZDL.
EventStorming, state machine and class diagram blueprints become place-order.zfl (process level) and payments-processing.zdl (design level).

I've been doing this in production for 4 years, writing domain models by hand and generating all the boring parts. Now agents can help with that too.

Arcadia Editions: see it for yourself

Arcadia Editions logo

Arcadia Editions is an open source fictional e-commerce that works as my laboratory, first for API governance and now for spec-driven development. I implemented it (5 microservices or 1 monolith) using agentic loops, without resorting to Markdown specs.

👷 Try it with your agent. Different scripts check out the repos you need, each with a prompt to analyze a different aspect: analyze with agents. Use them as they are, change them, or write your own.

Business flows: ZFL, process level

ZFL captures process-level EventStorming. Its main building block is the policy, the business rule that connects a domain event (a business fact) with the next command: when X do Y.

Arcadia Editions process-level EventStorming board in Miro.
ZFL policy: when OrderCreated do authorizePayment, emits PaymentAuthorized, PaymentDeclined, PaymentFailed.
ZFL sync calls: call reserveStock, on StockReservedResult emits OrderCreated.
ZFL outcomes: each branch named, service says who owns the command.
A ZFL file in VS Code next to its event flow diagram.
ZFL systems projection: commands and events grouped by system.
ZFL sequence diagram projection.

Service design: ZDL, design level

Zoom in from the business flow to the design of each microservice or module.

Design-level EventStorming stickies mapped to ZDL: aggregates, commands, events, policies, read models.

Built to last

Code is now very easy to change. Some things are not:

  • Data
  • APIs
  • Events

That is what we model here.

ZDL for data: aggregates and entities.
ZDL for APIs: services and commands with OpenAPI annotations.
ZDL for events: event payloads with AsyncAPI channels.

ZDL is structured and parseable, so a lot of code can be generated from it with deterministic templates instead of agents. More in Extra Ball.

A connected graph

ZFL and the ZDLs form one connected graph, deterministically parseable. That opens the door to formal verification.

place-order-flow.zfl references catalog-inventory domain-model.zdl: ZFL + ZDLs, one connected graph.

Pillar 2: Formal Verification

Each service can behave correctly in isolation while the system as a whole behaves incorrectly. From ZFL I derive a state machine per bounded context and model-check every path. On the Place Order flow of Arcadia Editions: 220 states, 3 incorrect final states. The repaired design: 312 states, none incorrect. ZFL is not 100% of TLA+, but humans can read it.

ZFL to a state machine per bounded context: transitions between systems, then the Orders state machine.

Pillar 3: Verification Contract

The definition of correctness has to be in place before the agentic loop starts. A Verification Contract lists falsifiable guarantees per requirement, in natural language, approved by a human. The Executable Verification Contract turns it into examples, acceptance tests and properties, frozen before the implementation and run against the code.

Top: human in the loop produces the approved, frozen baseline (specification, Verification Contract, Executable Verification Contract); the away-from-keyboard loop builds and produces the Assurance Report; a human decides the release. Bottom: Sion and April's assurance and build planes.

Extra Ball

Deterministic generation: keeping code quality from decaying

Instead of generating 100% of the code with agents, generate the structure with deterministic templates. Agents copy the patterns they find in the repo; if those patterns came from your best templates, quality stays consistent. Highly configurable if you want a different architecture. It started with Spring Boot Java, then Kotlin, and now there is an experimental Quarkus implementation.

ZDL generates OpenAPI (controllers, API tests), AsyncAPI (producers with transactional outbox, consumers, DTOs), tests (unit tests with in-memory mocks, integration tests as vertical slices) and backend code (microservices, modular monoliths).

Architecture manifest: an architectural world model

One YAML links every domain model and API in your organization. A Kotlin Multiplatform library parses it, ZenWave Platform for VS Code visualizes it, and an EventCatalog can be generated from it. A whole e-commerce fits in ~14k tokens, about 14% of a conservative smart zone. These aren't verbose Markdown specs you have to search with RAG or grep: you could talk to your whole architecture.

API repos release to the architecture manifest, which feeds ZenWave Platform for VS Code and an EventCatalog.
ZenWave Platform for VS Code navigating the architecture.
An EventCatalog generated from the architecture manifest.

The book

When Code Is Cheap: A field guide to agentic engineering, from domain models to verified behaviour. Everything on this page, the long version. Coming soon. The articles behind it are free today.

Book cover: When Code Is Cheap, a field guide to agentic engineering, from domain models to verified behaviour.