specification by example

Distill

Requirements are expressed as scenarios.

A scenario represents the system's behavior from the user's perspective and follows the Given-When-Then structure to create a testable specification.

The specification is written as executable tests, which are automated and run continuously. These tests cover a full range of scenarios, from happy paths to error cases.

Professional Distillation Services

Transform your requirements into executable specifications with our Specification by Example workshops and BDD implementation services.

Success Scenario(s)

Focus on a single command!

For the ChangeMenu command to succeed, you need to specify the required preconditions/events. In this case RestaurantCreated / Exists is a precondition.

RestaurantCreated / Exists might not be the only precondition. For example, "The menu must be in a modifiable state (e.g., not locked due to an active promotion or regulations)"

specification by example
lib/domain_test.ts
Deno.test(function changeRestaurantMenuDeciderTest() {
  const changeRestaurantMenuCommand: RestaurantCommand = restaurantCommandSchema
    .parse(
      JSON.parse(changeRestaurantMenuCommandJson),
    );

  const restaurantCreatedEvent: RestaurantEvent = restaurantEventSchema
    .parse(
      JSON.parse(restaurantCreatedEventJson),
    );

  const restaurantMenuChangedEvent: RestaurantEvent = restaurantEventSchema
    .parse(
      JSON.parse(restaurantMenuChangedEventJson),
    );

  DeciderSpecification.for(restaurantDecider)
    .given([restaurantCreatedEvent])
    .when(changeRestaurantMenuCommand)
    .then([restaurantMenuChangedEvent]);
});
specification by example
lib/domain_test.ts
Deno.test(function changeRestaurantMenuDeciderTest() {
  const changeRestaurantMenuCommand: RestaurantCommand = restaurantCommandSchema
    .parse(
      JSON.parse(changeRestaurantMenuCommandJson),
    );

  const restaurantMenuNotChangedEvent: RestaurantEvent = restaurantEventSchema
    .parse(
      JSON.parse(restaurantMenuNotChangedEventJson),
    );

  DeciderSpecification.for(restaurantDecider)
    .given([])
    .when(changeRestaurantMenuCommand)
    .then([restaurantMenuNotChangedEvent]);
});

Error Scenario(s)

Focus on a single command!

Define all the possible reasons why ChangeMenu command can fail. In this case RestaurantCreated / Exists is missing as a precondition.

RestaurantCreated / Exists might not be the only missing precondition. For example, "The menu must be in a modifiable state (e.g., not locked due to an active promotion or regulations)"

Bring structure to AI coding

AI coding often feels like a blur of prompts and patches. But what if we could apply the same mature engineering practices/spec-driven development?

Imagine pairing these practices with tools like Kiro, where AI agents plug into MCP servers and APIs. Instead of ad-hoc coding, you guide the flow with specs.

This is spec-driven AI development: complexity tamed, structure preserved.

specification by example

Demo Applications

LanguageSource Code
Kotlin (Spring)
Kotlin (Ktor)
TypeScript
Rust (Actix-Web Server)
Rust (PostgreSQL Extension)