State machine

States and the labelled transitions between them, from start to end.

1 state machine example

Content approval states

The lifecycle of a document from draft through review to published or rejected.

Every transition is labelled with the event that triggers it, because that is what a state machine is for. The rejection path is drawn in the accent so a reader notices where work bounces back.

Open in the editor

What is a state machine diagram?

A state machine diagram, or state diagram, shows the states an object can be in and the events that move it from one state to another. It is part of UML, where it is called a state machine diagram, and is based on finite-state machines and Harel statecharts.

Read it from the filled start circle. Rounded boxes are states, arrows are transitions labeled with the event that triggers them, and a ringed circle marks the end.

When to use a state machine diagram

  • Use it to define a lifecycle, such as content moving from draft to review, approved and published.
  • Use it before coding order, payment or ticket statuses, to catch impossible or missing transitions.
  • If the focus is the sequence of steps people take rather than the states of one thing, use a flowchart.

How to make a good state machine diagram

  1. Name states as conditions ("In review") and transitions as events ("submit", "reject").
  2. Check that every state has a way out, unless it is a final state.
  3. Add guard conditions in brackets when the same event can lead to different states.
  4. Keep one diagram per object; do not mix the states of an order and a payment.