stateDiagram-v2
[*] --> Draft
Draft --> InReview : submit
state InReview {
[*] --> Reading
Reading --> Deciding
Deciding --> [*]
}
InReview --> Draft : request changes
InReview --> Published : approve
note right of InReview : Reviewers work inside this state
Published --> [*]
What is a State Diagram?
A state diagram, also called a state machine diagram, is a map of modes. Each node is a state. Each arrow is a transition, usually labeled with the event that causes it. [*] is the start, and an arrow back to [*] is the end. stateDiagram-v2 is the syntax to use: it supports notes, choices, and composite states. Reach for a state diagram when an order, a connection, or a screen has a small set of legal modes and illegal combinations would be a bug.
When to use it
Use a state diagram for order lifecycles, connection status, and UI modes. Use a flowchart when you are describing a procedure with branches, not the mode of an object. Use a sequence diagram when the interesting part is the messages, not the resulting state.
Use [*] for both. [*] --> Idle draws the initial transition. Idle --> [*] draws a final transition. A machine can end from more than one state.
Add a colon and the event after the arrow: Draft --> InReview : submit. Keep the label short. It is the trigger, not a sentence about what the next state is called.
Write state Parent { } and put child states inside the braces. Nested states describe what happens while the parent state is active, such as the steps inside a review.
Use a state diagram when an object has modes and events that move it between those modes. Use a flowchart when you are walking through a procedure and the decisions a person or job makes along the way.
Yes. That is the normal way to show a fork in the lifecycle, such as Paid --> Refunded and Paid --> [*]. Each arrow needs its own event label so the reader knows which one fires.
Ready to create your own state diagram?
Open the editor with this example pre-loaded and start customizing.