Skip to content

Use cases

Every part of a use case, what it is for, and how to write it well.

Applies to EngineCloud
View as Markdown
On this page
  1. The parts
  2. Every case ends in a declared outcome
  3. Outcomes and failures, short and long
  4. Types
  5. Writing a good use case

A use case is the unit of the map. It is written in plain words first; the technical parts come later, from a programmer, the coding agent or the code itself.

cases/orders/order-for-tomorrow.case.yaml
id: order-for-tomorrow
title: Order for tomorrow
actor: customer
goal: Get bread reserved for tomorrow morning
starts: in_app
where: shop.order-for-tomorrow          # Shop › Order for tomorrow
preconditions:
  - The bakery bakes tomorrow
steps:
  - The customer picks products and quantities
  - The system checks what is left for tomorrow and reserves it
  - The customer gets a pick-up code
input:
  items: [{ product_id: uuid, qty: int }]
  pickup_at: datetime
outcomes:
  OrderPlaced: { order_id: uuid, ready_at: datetime }
failures:
  SoldOut: «That bread is sold out for tomorrow. Pick another?»
  Closed:
    when: the bakery does not bake that day
    tell: «We don't bake that day. Try the next one.»
data:
  reads: [product, bake_day]
  writes: [order, order_item]
allowed: [customer]
status: approved
owner: ana@laespiga.co

The parts

PartRequiredWhat it is for
idyesA stable name in kebab-case. Code, commits, events and traces use it; renaming the title never changes it.
titleyesWhat people call it, in their words.
actoryesWho starts it: one actor of the map. A case started by another system or by the clock has a system actor.
goalyesOne sentence: what the actor wants. If it needs two sentences, it is probably two cases.
startsyesHow it starts: in_app, external, scheduled or event, each with its own fields (How a case starts).
wherenoOnly for in_app: the place in the app where it happens, such as shop.order-for-tomorrow. Its path, «Shop › Order for tomorrow», is worked out from the navigation map.
preconditionsnoWhat must be true before it can start.
stepsnoWhat happens, in order, in plain words. A step can start with another actor: staff: confirms the order.
inputnoWhat it receives, as typed fields (Types). For external starts this is the body the other app sends.
outcomesyesHow it ends well: each outcome has a name in PascalCase and a typed payload (Outcomes and events). At least one.
failuresnoHow it ends when something expected goes wrong. Failures are outcomes too: a name, when it happens, and what to tell the person.
datanoThe tables it reads and writes. With Sypnorm this comes from the code.
allowednoThe actors allowed to run it.
ainoThe Sypnia AI tasks it calls: ai: { tasks: [allergen-answer] }.
filesnoThe Sypnia Files buckets it reads and writes: files: { writes: [receipts] }.
mailnoThe Sypnia Mail templates it sends: mail: { sends: [order-ready] }.
loopnoOnly to close a cycle of events on purpose: loop: { bounded: true, max: 3, until: "…" } (Loops).
retriesnoFor a case that starts on an event: how many attempts before dead letters: 5 by default, 1 to 20 (Delivery).
statusnoidea, approved, building, live or retired.
owner, notesnoWho answers for it, and anything else worth saying.

data, ai, files and mail say what the case uses from the other products. The check compares each list with what really happens, in the code and in production: something used and not listed, or listed and never used, is reported.

Every case ends in a declared outcome

A run of a case ends in exactly one of its outcomes or failures, never in silence. The words a person reads, the types in the code and what Telemetry counts all come from that list. An error nobody declared (a bug, a database that does not answer) is not an outcome: it is reported to Telemetry as an error, and a run started by an event goes to its dead letters after its retries.

Outcomes and failures, short and long

The short form is the one most cases need:

YAML
outcomes:
  OrderPlaced: { order_id: uuid, ready_at: datetime }
failures:
  SoldOut: «That bread is sold out for tomorrow. Pick another?»

The long form adds words for people and a payload to a failure:

YAML
outcomes:
  OrderPlaced:
    says: The bread is reserved until 10 am tomorrow
    payload: { order_id: uuid, ready_at: datetime }
failures:
  SoldOut:
    when: a product sold out while ordering
    tell: «That bread is sold out for tomorrow. Pick another?»
    payload: { product_id: uuid }

An outcome with a payload key is in the long form; otherwise every key is a field of the payload. Failures may also be written as a list (- name: SoldOut, when, tell); both forms mean the same.

Types

Payloads and inputs use a small set of types, the same in every language Sypnorm generates code for:

TypeMeans
string, texta short text, a long text
int, number, moneya whole number, any number, an amount in the smallest unit of the currency
booltrue or false
uuid, email, urlan id, an e-mail address, an address
date, datetime, durationa day, a moment with its time zone, a span of time (2h)
[type], { field: type }a list, an object
type?optional
one_of(a, b)one of these words
any other wordthat exact value, always (channel: whatsapp)

Inside a YAML flow mapping, { channel: one_of(sms, call) }, YAML itself splits the value at the comma; the reader joins the pieces back, so it means what it says. Quoting it, channel: "one_of(sms, call)", avoids the question.

Writing a good use case

  • One actor, one goal. «Customer orders and staff confirms» is two cases joined by an event or a journey.
  • Steps say what, not how. «The system reserves the products», not «INSERT into reservation».
  • Name every ending. An outcome named in the map is something you can count, and a failure named in the map is a message a real person will read. One found in production is a bug.
  • Name outcomes in the past tense. OrderPlaced, RainExpected, BakerTold: something that already happened.
  • Keep the id when the meaning stays. Change the title freely; change the id only when it becomes a different case.
  1. The parts
  2. Every case ends in a declared outcome
  3. Outcomes and failures, short and long
  4. Types
  5. Writing a good use case

    Search pages, sections and terms