Skip to content
State machine (FSM) templates

Order Lifecycle — the Reference Machine

The one to copy. Every state is reachable from the declared initial state, every transition names states that exist, every fork carries a guard that distinguishes it, every non-final state has a way out, and a run can reach a final state. Retries and cancellations are ordinary cycles and the engine says nothing about them, because a loop is not a defect. Reports clean, and every one of the ten checks says what it covered.

Template previewState machine (FSM)
Order lifecycle8 states · 9 transitions · 7 eventscheckoutpayment [authorised] / capturepayment [declined] / notifytimeoutpickdispatch / send trackingdeliveredcancel [not dispatched] / refundcancel [not dispatched] / refundCartAwaiting paymentPaidPackedShippedDeliveredCancelledRefundedAll 8 states are reachable and every transition names states that exist.OKAll 8 states are reachable from `Cart`.OKEvery run from `Cart` can reach a final state.OKAll 9 transitions name states that exist, so every arrow in the figure is drawn.

Make it your own.

title "Order lifecycle"

state Cart
state Pending      label "Awaiting payment"
state Paid
state Packed
state Shipped
state Delivered    final
state Cancelled    final
state Refunded     final

initial Cart

transition Cart    -> Pending   on "checkout"
transition Pending -> Paid      on "payment" [authorised] / capture
transition Pending -> Pending   on "payment" [declined] / notify
transition Pending -> Cancelled on "timeout"
transition Paid    -> Packed    on "pick"
transition Packed  -> Shipped   on "dispatch" / send tracking
transition Shipped -> Delivered on "delivered"
transition Paid    -> Refunded  on "cancel" [not dispatched] / refund
transition Packed  -> Refunded  on "cancel" [not dispatched] / refund