Skip to content
English

Connect the whole process

Consider the mug shop introduced in The work behind the code. Accepting an order sets aside the requested mugs for the customer. To design its application, we need to connect the whole experience: a customer sees stock, orders a mug, and finds out whether the shop accepted the order.

Protect changes and answer questions explains the individual parts: a command requests a change, an event records an accepted fact, and a query supplies an answer.

Event Modeling connects those parts into a process people can examine together. It puts screens, commands, events, and queries in one model. The connections reveal where information comes from, where it is needed, and which business questions still need an answer. NeoHaskell uses that same structure to organize development and keep the specification in the code.

The shop has three mugs available. The owner wants customers to be able to cancel an order before dispatch and return its mugs to available stock. Start with the journey of ordering one mug and then cancelling it.

The model has two chapters, Place order and Cancel order. Each chapter groups two slices: one changes state through a command and its accepted event; the other supplies the stock answer through a query. Vertical lines separate the development units. Each arrow across the top spans the slices belonging to its chapter.

Place orderCancel orderAccept an orderShow remaining stockCancel before dispatchShow restored stock
Mug shop3 availableOrder one mug
CommandPlace order1 mug
EventOrder placed1 mug
QueryAvailable mugs2
Your order2 availableCancel order
CommandCancel orderThis order
EventOrder cancelledStock restored
QueryAvailable mugs3

After the order is accepted, the stock query answers two. After cancellation, it answers three. The repeated Available mugs nodes show the stock answer at those two points in the process.

Drawing the connections also exposes what this first sketch has not answered. “Add cancellation” sounded like a button. The model asks for the rest of the behavior:

  • Where does the cancellation command get the order identity?
  • What prevents cancellation after dispatch?
  • Which answer tells the customer that cancellation succeeded?
  • What tells staff to stop preparing that order?

Each unanswered question is a piece of the application that has not been designed yet. The owner and developer can resolve it while looking at the same process, before an agent or a person turns an assumption into code.

A slice is the unit of development. “Accept an order” has an input, a decision, and an observable outcome. Its implementation checks the requested quantity and stock, and its rules specify when to accept or reject. “Show remaining stock” is a separate slice with a different job: maintain the answer after an order is placed.

The same split applies to cancellation. One slice decides whether the order can be cancelled and records the outcome. Another supplies the updated stock answer. The chapter keeps them together as one part of the customer’s experience without making them one implementation task.

A feature groups related chapters. Here, an Orders feature contains Place order and Cancel order. An integration has its own slice when the process needs an external effect, such as sending the order confirmation. The model gives each task a place and shows the contracts it depends on.

A customer-facing command is a promise. A caller of PlaceOrder depends on its accepted inputs and behavior. A query’s consumers depend on the answer it supplies. Recorded events depend on definitions that preserve what those facts mean.

NeoHaskell’s deployment model freezes those definitions and their implementation when they are deployed. A deployed command, event, or query cannot be silently rewritten under the same identity. A new requirement or a corrected decision becomes new behavior alongside the deployed behavior.

Suppose the shop adds a delivery checkout that requires contact details before accepting an order. The existing collection checkout uses PlaceOrder, which accepts only a product and quantity. Instead of editing it in place, duplicate the feature in development, give the changed behavior a new name, such as PlaceOrderWithContact, and implement its additional check. A suffix is also an option. The important distinction is that the new contract has its own identity.

The delivery checkout uses the new contract while collection orders continue to use the original. NeoHaskell makes the small, explicit addition the normal development path: reuse the established structure, change the intended behavior, and check its rules. The work is focused on the new requirement instead of tracing every caller of an altered implementation.

A bug fix follows the same rule. If CancelOrder incorrectly accepts dispatched orders, create the corrected CancelUndispatchedOrder, test the missing case, move callers to it, and disable the faulty command. Freezing the old implementation preserves what was deployed; it does not require keeping a faulty entry point available.

Retire behavior without versioning the whole API

Section titled “Retire behavior without versioning the whole API”

Old and new contracts can coexist while their consumers migrate. The mobile app can keep offering collection through PlaceOrder while the website adds delivery through PlaceOrderWithContact. The stock query and unrelated commands keep their existing names and contracts.

This avoids copying an entire API into /v2 because one operation changed. Each changed behavior gets its own identity. Consumers adopt the replacement when they are ready, rather than having to move every operation to a new API version together.

Mark an old command or query as deprecated when new consumers should stop choosing it. Once usage shows that nobody calls it, disable or remove that entry point. Retiring a command does not erase the events it recorded or remove the definitions needed to interpret that history.

Why changing shared code creates more work

Section titled “Why changing shared code creates more work”

Consider the same delivery-contact requirement in a conventional application where the shop edits its existing POST /orders endpoint and shared Order model. Making the new field required breaks the old mobile checkout. Adding it to the shared model then affects the order editor and the staff screen, even though neither asked for a new ordering policy.

Next, the shop changes cancellation from a yes/no flag to a status that distinguishes requested, accepted, and refused. Code that previously checked cancelled now needs attention in dispatch, stock calculations, and customer emails. A small business request spreads across features because they all interpret the same mutable model.

The cost includes revisiting behavior that already worked. In this plot, A through G represent additions to the application. Each R is work repeated in an earlier behavior. The rising curve illustrates the increasing effort per change as those dependencies accumulate.

Change shared code and revisit its callers
Effort per change
A
B
C
DR
ER
FRR
GRRR
Behaviors added

In NeoHaskell, the delivery-contact requirement adds a named command and its rules beside the frozen ordering contract. The old checkout keeps its existing behavior. A new cancellation policy likewise gets an explicit slice and contract, with the affected queries and integrations visible in the Event Model.

Stable contracts keep a new requirement from silently changing every existing consumer. Slices bound the implementation work, chapters retain the business context, and the model exposes where a new behavior connects to the rest of the application. NeoHaskell supplies the recurring structure so creating the replacement is cheaper than repeatedly untangling shared code.

Add behavior beside stable contracts
Effort per change
A
B
C
D
E
F
G
Stable contracts
Behaviors added

The roughly level effort per addition is what makes total development effort grow close to linearly: another comparable slice adds another comparable piece of work. This is the development pattern NeoHaskell is designed to support.

Cancellation still has to agree with dispatch about when an order can be cancelled. That agreement belongs in the contracts and rules of the affected slices. The developer can name the dependency, inspect it, and test it instead of discovering it through a broken customer journey.

The NeoHaskell IDE makes the application’s structure visible. Open a feature to see its chapters and slices, then follow the connections between commands, events, queries, and integrations. The mug-shop model can be explored in the actual IDE interface:

NeoHaskell IDE showing the Orders feature, Place order and Cancel order chapters, four slice columns, and the connected command, event, and query declarations.

For a cancellation change, begin with the Cancel order chapter. Locate the command that requests it, the event it produces, and the stock query that consumes that event. Those names identify the corresponding declarations in the source. The same route helps when taking over an existing project or reviewing a change written by an AI agent.

The visual model is derived from the source declarations. When those declarations change, the IDE refreshes the model. A renamed command or a new query connection belongs to the application structure, so it appears in the diagram without somebody maintaining a second drawing by hand.

The specification is part of the code. NeoHaskell’s Event Model DSL declares features, chapters, slices, commands, events, queries, and integrations. The rules beside a slice describe its required behavior, including Given, When, Then cases.

Here is the cancellation chapter from the shop’s model. The example uses the shop’s Order, command, event, and query types, already defined elsewhere:

orders =
feature "Orders" do
chapter "Cancel order" do
slice "Cancel before dispatch" do
entity @Order do
command @CancelOrder do
produces @OrderCancelled
rule "Cancel before dispatch" do
orderId <- requestValue @Uuid
given do
event OrderPlaced {
orderId = orderId,
quantity = 1
}
when CancelOrder { orderId = orderId }
therefore do
event OrderCancelled {
orderId = orderId,
quantity = 1
}
slice "Show restored stock" do
query @AvailableMugs do
readsFrom @Order do
onEvent @OrderPlaced
onEvent @OrderCancelled

The hierarchy in the diagram is the hierarchy in the code. The chapter contains a command slice and a query slice. produces declares the command’s event; readsFrom and onEvent declare which history supplies the query. The stock query listens to both placed and cancelled orders so its answer reflects both changes.

The rule sits beside the command it specifies. requestValue asks the rule runner for a typed example order ID. given supplies the accepted order’s history, when supplies the cancellation command, and therefore is the DSL’s Then: the expected OrderCancelled event. The decision implementation has a concrete case to satisfy.

A second rule covers an already dispatched order: cancellation must be rejected and stock must stay unchanged. The stock-query slice separately checks that an accepted cancellation restores the available count. Each case belongs with the behavior it specifies.

A separate Markdown file or Confluence page can become stale because someone has to update it after changing the application. In NeoHaskell, the declared model and rules already live in the source. A document describing that specification can be derived from those declarations instead of becoming another authority to maintain.