Use cases
Every part of a use case, what it is for, and how to write it well.
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.
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.coThe parts
| Part | Required | What it is for |
|---|---|---|
id | yes | A stable name in kebab-case. Code, commits, events and traces use it; renaming the title never changes it. |
title | yes | What people call it, in their words. |
actor | yes | Who starts it: one actor of the map. A case started by another system or by the clock has a system actor. |
goal | yes | One sentence: what the actor wants. If it needs two sentences, it is probably two cases. |
starts | yes | How it starts: in_app, external, scheduled or event, each with its own fields (How a case starts). |
where | no | Only 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. |
preconditions | no | What must be true before it can start. |
steps | no | What happens, in order, in plain words. A step can start with another actor: staff: confirms the order. |
input | no | What it receives, as typed fields (Types). For external starts this is the body the other app sends. |
outcomes | yes | How it ends well: each outcome has a name in PascalCase and a typed payload (Outcomes and events). At least one. |
failures | no | How it ends when something expected goes wrong. Failures are outcomes too: a name, when it happens, and what to tell the person. |
data | no | The tables it reads and writes. With Sypnorm this comes from the code. |
allowed | no | The actors allowed to run it. |
ai | no | The Sypnia AI tasks it calls: ai: { tasks: [allergen-answer] }. |
files | no | The Sypnia Files buckets it reads and writes: files: { writes: [receipts] }. |
mail | no | The Sypnia Mail templates it sends: mail: { sends: [order-ready] }. |
loop | no | Only to close a cycle of events on purpose: loop: { bounded: true, max: 3, until: "…" } (Loops). |
retries | no | For a case that starts on an event: how many attempts before dead letters: 5 by default, 1 to 20 (Delivery). |
status | no | idea, approved, building, live or retired. |
owner, notes | no | Who 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:
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:
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:
| Type | Means |
|---|---|
string, text | a short text, a long text |
int, number, money | a whole number, any number, an amount in the smallest unit of the currency |
bool | true or false |
uuid, email, url | an id, an e-mail address, an address |
date, datetime, duration | a 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 word | that 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.