state-machine
Installation
SKILL.md
Aggregate lifecycles
What belongs in a machine
One question: does the field have legal moves?
A status where PAID may only follow PLACED, and SHIPPED only PAID, has legal moves — the rules exist whether or not anyone wrote them down,
and they are currently spread across whichever use cases happen to touch the field. A lastSeenAt has no legal moves; it is derived data, and
wrapping it in a machine buys nothing.
Two more that look like lifecycles and are not:
- A boolean.
isArchivedtoggling both ways is not worth a machine. Two states with a move each is more ceremony thancopy(archived = true). - A field the client sets freely. If any value may follow any other, there is nothing to declare. That is a validation problem — load
ktor-toolkit:validation.
Before writing one, ask
Getting the graph wrong ships as a 409 on a legitimate request, and the toolkit cannot guess a lifecycle. Ask directly: