Skip to content

state

A UML state machine diagram (UML 2.5.1, chapter 14): states and pseudostates joined by transitions, composite states with substates or orthogonal regions, entry and exit points on their border. {protocol} in the title makes it a protocol state machine. Diagrist lays it out by itself: layers by the longest path from the initial pseudostate, final states last, back and skip transitions on rails beside the states, loops at a free corner.

This page lists everything a state diagram may contain. The same grammar is available as data with dgr grammar state --json, and the overview explains how lines, texts and attributes are written and lists the codes every kind shares.

diagram state "Title" [subtitle=<text>] [look=<plain|cards>] [direction=<down|right>] [locale=<en|de>]

Every state diagram starts with this line.

PartKindValueMeaning
subtitle=attributea text in double quotes like "Order service"Second line below the title.
look=attributeone of plain, cardsplain (default) draws the UML notation, cards the same layout with states as cards with a toned name field.
direction=attributeone of down, rightdown (default) lays the flow out from top to bottom, right from left to right.
locale=attributeone of en, deLanguage of the texts Diagrist adds to the picture and of the description: en (default) or de.

Example:

diagram state "Title"

Each statement is one line that starts with its keyword. Statements inside blocks are indented below them. Like every kind, state also has use, variant, set and drop, described in the overview.

StatementWhereWhat it does
statetop levelA state: a rounded box with the name, below it a compartment with entry, do and exit, deferred events and internal transitions.
initialtop levelThe initial pseudostate: a filled circle.
finaltop levelA final state: a circle with a dot.
choicetop levelA choice pseudostate: a diamond.
junctiontop levelA junction pseudostate: a small filled circle that joins or splits transitions without a decision of its own.
historytop levelA history pseudostate inside a composite state: a circle with H, with deep H*.
forktop levelA fork pseudostate: a bar across the flow, from one incoming to several outgoing transitions into states, often into the regions of a state.
jointop levelA join pseudostate: a bar across the flow that waits for all its incoming transitions from states.
terminatetop levelA terminate pseudostate: a cross.
entrypointtop levelAn entry point: a small circle on the border of its state.
exitpointtop levelAn exit point: a small circle with a cross on the border of its state.
regiontop levelAn orthogonal region of a state: the regions of a state are active at the same time and stand side by side, separated by dashed lines, the name at the top left.
gotop levelA transition from from to to, labelled trigger [guard] / effect; without all three it is a completion transition.
internaltop levelAn internal transition: a line trigger [guard] / effect in the compartment of its state.
notetop levelA comment on a vertex: a dashed box above it with a tip down to it, below it when lines run above.
adrtop levelAn architecture decision in the bar below the picture: question, the chosen option after =, and the consequence after =>.
state <id> <label> [in <ref>] [entry=<text>] [do=<text>] [exit=<text>] [defer=<text>] [submachine=<text>] [file=<text>] [tone=<choice>] [mark=<ref>] [emph]

A state: a rounded box with the name, below it a compartment with entry, do and exit, deferred events and internal transitions. A state with vertices in it is a composite state, drawn as a frame around them; with submachine= it calls another state machine. Diagrist lays states out in layers from the initial pseudostate to the final state. UML 2.5.1: 14.2.3.4 Simple state.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id that go, in, internal and note use for this state.
<label>argumenta text in double quotes like "Order service"Name of the state.
in <ref>clausethe id of a state or region declared in this diagramThe composite state or the region the vertex lies in; without it, the vertex stands at the top level. UML 2.5.1: 14.2.3.4 Composite state with substates.
entry=attributea text in double quotes like "Order service"Behaviour on entering, shown as entry / .... UML 2.5.1: 14.2.4 Entry, do and exit behavior in the compartment of a state.
do=attributea text in double quotes like "Order service"Behaviour while in the state, do / .... UML 2.5.1: 14.2.4 Entry, do and exit behavior in the compartment of a state.
exit=attributea text in double quotes like "Order service"Behaviour on leaving, exit / .... UML 2.5.1: 14.2.4 Entry, do and exit behavior in the compartment of a state.
defer=attributea text in double quotes like "Order service"Events the state defers, separated by commas; each shows as event / defer. UML 2.5.1: 14.2.4 Deferred event in the compartment of a state.
submachine=attributea text in double quotes like "Order service"Name of the state machine the state calls: the box reads Name : Machine and carries the submachine symbol. Entry and exit points in it are its connection point references. UML 2.5.1: 14.2.3.4 Submachine state calling another state machine.
file=attributea text in double quotes like "Order service"File of the called state machine, relative to this one; named in the description, not checked yet.
tone=attributeone of blue, indigo, purple, maroon, green, teal, slate, red, orange, peach, skyColour of the name field in look=cards; without it slate.
mark=attributethe id of an adr declared in this diagramId of a decision of the decision bar, such as E1; the mark is drawn beside it.
emphflagHighlights the state in the accent colour.

Examples:

state open "Open" entry="set deadline"
state check "Check" submachine="Credit check"
initial <id> [label] [in <ref>]

The initial pseudostate: a filled circle. Each region, the top level included, has at most one; its transition has neither trigger nor guard. UML 2.5.1: 14.2.3 Initial pseudostate.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id that go uses for this vertex.
[label]optional argumenta text in double quotes like "Order service"Name shown small beside the symbol.
in <ref>clausethe id of a state or region declared in this diagramThe composite state or the region the vertex lies in; without it, the vertex stands at the top level. UML 2.5.1: 14.2.3.4 Composite state with substates.

Example:

initial start
final <id> [label] [in <ref>]

A final state: a circle with a dot. No transition leaves it. Diagrist puts final states into the last layer. UML 2.5.1: 14.2.3 Final state.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id that go uses for this vertex.
[label]optional argumenta text in double quotes like "Order service"Name shown small beside the symbol.
in <ref>clausethe id of a state or region declared in this diagramThe composite state or the region the vertex lies in; without it, the vertex stands at the top level. UML 2.5.1: 14.2.3.4 Composite state with substates.

Example:

final end
choice <id> [label] [in <ref>]

A choice pseudostate: a diamond. Its outgoing transitions carry guards, one of them when=else. UML 2.5.1: 14.2.3 Choice pseudostate.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id that go uses for this vertex.
[label]optional argumenta text in double quotes like "Order service"Name shown small beside the symbol.
in <ref>clausethe id of a state or region declared in this diagramThe composite state or the region the vertex lies in; without it, the vertex stands at the top level. UML 2.5.1: 14.2.3.4 Composite state with substates.

Example:

choice paid
junction <id> [label] [in <ref>]

A junction pseudostate: a small filled circle that joins or splits transitions without a decision of its own. UML 2.5.1: 14.2.3 Junction pseudostate.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id that go uses for this vertex.
[label]optional argumenta text in double quotes like "Order service"Name shown small beside the symbol.
in <ref>clausethe id of a state or region declared in this diagramThe composite state or the region the vertex lies in; without it, the vertex stands at the top level. UML 2.5.1: 14.2.3.4 Composite state with substates.

Example:

junction merge
history <id> [label] [in <ref>] [deep]

A history pseudostate inside a composite state: a circle with H, with deep H*. Entering it resumes the substate last active. UML 2.5.1: 14.2.3 Shallow and deep history pseudostates.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id that go uses for this pseudostate.
[label]optional argumenta text in double quotes like "Order service"Name shown small beside the symbol.
in <ref>clausethe id of a state or region declared in this diagramThe composite state or the region the vertex lies in; without it, the vertex stands at the top level. UML 2.5.1: 14.2.3.4 Composite state with substates.
deepflagDeep history: resumes the innermost substates too, drawn H*.

Example:

history resume in active deep
fork <id> [label] [in <ref>]

A fork pseudostate: a bar across the flow, from one incoming to several outgoing transitions into states, often into the regions of a state. UML 2.5.1: 14.2.3 Fork pseudostate.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id that go uses for this vertex.
[label]optional argumenta text in double quotes like "Order service"Name shown small beside the symbol.
in <ref>clausethe id of a state or region declared in this diagramThe composite state or the region the vertex lies in; without it, the vertex stands at the top level. UML 2.5.1: 14.2.3.4 Composite state with substates.

Example:

fork split
join <id> [label] [in <ref>]

A join pseudostate: a bar across the flow that waits for all its incoming transitions from states. UML 2.5.1: 14.2.3 Join pseudostate.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id that go uses for this vertex.
[label]optional argumenta text in double quotes like "Order service"Name shown small beside the symbol.
in <ref>clausethe id of a state or region declared in this diagramThe composite state or the region the vertex lies in; without it, the vertex stands at the top level. UML 2.5.1: 14.2.3.4 Composite state with substates.

Example:

join done
terminate <id> [label] [in <ref>]

A terminate pseudostate: a cross. The state machine ends at once. UML 2.5.1: 14.2.3 Terminate pseudostate.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id that go uses for this vertex.
[label]optional argumenta text in double quotes like "Order service"Name shown small beside the symbol.
in <ref>clausethe id of a state or region declared in this diagramThe composite state or the region the vertex lies in; without it, the vertex stands at the top level. UML 2.5.1: 14.2.3.4 Composite state with substates.

Example:

terminate abort
entrypoint <id> [label] [in <ref>]

An entry point: a small circle on the border of its state. A transition from outside ends at it and continues inside; on a submachine state the way inside lies in the called machine. UML 2.5.1: 14.2.3 Entry point on the border of a state.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id that go uses for this point.
[label]optional argumenta text in double quotes like "Order service"Name shown small outside the circle.
in <ref>clausethe id of a state declared in this diagramThe composite or submachine state on whose border the point sits. Required.

Example:

entrypoint fresh "New customer" in check
exitpoint <id> [label] [in <ref>]

An exit point: a small circle with a cross on the border of its state. A transition from inside ends at it and continues outside. UML 2.5.1: 14.2.3 Exit point on the border of a state.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id that go uses for this point.
[label]optional argumenta text in double quotes like "Order service"Name shown small outside the circle.
in <ref>clausethe id of a state declared in this diagramThe composite or submachine state on whose border the point sits. Required.

Example:

exitpoint rejected "Rejected" in check
region <id> [label] [in <ref>]

An orthogonal region of a state: the regions of a state are active at the same time and stand side by side, separated by dashed lines, the name at the top left. Vertices come in with in; each region has its own initial pseudostate unless a fork enters it. UML 2.5.1: 14.2.3.2 Orthogonal regions of a state, separated by dashed lines.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id that in uses for this region.
[label]optional argumenta text in double quotes like "Order service"Name of the region, shown at its top left.
in <ref>clausethe id of a state declared in this diagramThe state the region belongs to. Required.

Example:

region payment "Payment" in processing
go <from> <arrow> <to> [on=<text>] [when=<text>] [do=<text>] [post=<text>] [emph]

A transition from from to to, labelled trigger [guard] / effect; without all three it is a completion transition. when=else is the else branch of a choice. A transition of a state to itself is a loop at its freest corner. In a protocol state machine ({protocol} in the title) it reads [precondition] operation / [postcondition]. UML 2.5.1: 14.2.3.8 Transition with trigger, guard and effect, 14.2.3.8 Completion transition without trigger.

Written at the top level.

PartKindValueMeaning
<from>argumentthe id of a state, initial, final, choice, junction, history, fork, join, terminate, entrypoint or exitpoint declared in this diagramThe vertex the transition leaves.
<arrow>argumentone of the arrows -> transition, with an open arrowhead at toThe arrow of a transition.
<to>argumentthe id of a state, initial, final, choice, junction, history, fork, join, terminate, entrypoint or exitpoint declared in this diagramThe vertex the transition enters.
on=attributea text in double quotes like "Order service"Trigger: the events that fire the transition, separated by commas. A time event is written after(30 days), a change event when(stock empty). In a protocol state machine the operation called. UML 2.5.1: 14.2.3.8 Transition with trigger, guard and effect.
when=attributea text in double quotes like "Order service"Guard, written without brackets; else is the predefined else branch. UML 2.5.1: 14.2.3.8 Predefined guard else.
do=attributea text in double quotes like "Order service"Effect: the behaviour the transition runs, shown after /.
post=attributea text in double quotes like "Order service"Postcondition of a protocol transition, written without brackets. UML 2.5.1: 14.4.3 Protocol transition with precondition and postcondition.
emphflagHighlights the line in the accent colour.

The values of arrow and what they mean:

ValueMeaning
->transition, with an open arrowhead at to

Examples:

go open -> paid on="pay" when="amount covered" do="send receipt"
go choice -> open when=else
go open -> cancelled on="after(14 days)"
internal <state> [on=<text>] [when=<text>] [do=<text>]

An internal transition: a line trigger [guard] / effect in the compartment of its state. The state is neither left nor entered again, so no entry or exit behaviour runs. UML 2.5.1: 14.2.4 Internal transition in the compartment of a state.

Written at the top level.

PartKindValueMeaning
<state>argumentthe id of a state declared in this diagramThe state whose compartment shows the transition.
on=attributea text in double quotes like "Order service"Trigger: the events that fire the transition, separated by commas. A time event is written after(30 days), a change event when(stock empty). In a protocol state machine the operation called. UML 2.5.1: 14.2.3.8 Transition with trigger, guard and effect.
when=attributea text in double quotes like "Order service"Guard, written without brackets.
do=attributea text in double quotes like "Order service"Effect, shown after /.

Example:

internal open on="change item" do="recalculate"
note <text> [on <ref>]

A comment on a vertex: a dashed box above it with a tip down to it, below it when lines run above. UML 2.5.1: 7.2.3.2 Comment (note).

Written at the top level.

PartKindValueMeaning
<text>argumenta text in double quotes like "Order service"What the note says, in one line.
on <ref>clausethe id of a state, initial, final, choice, junction, history, fork, join, terminate, entrypoint or exitpoint declared in this diagramThe vertex the note belongs to. Required.

Example:

note "Only for new customers" on check
adr <id> <question> <equals> <choice> [then] [consequence] [open=<text>]

An architecture decision in the bar below the picture: question, the chosen option after =, and the consequence after =>. mark= with its id puts the mark into the picture.

Written at the top level.

PartKindValueMeaning
<id>argumentan identifier like api (letters, digits, _ and -, starting with a letter)Id of the decision, such as E1; mark=E1 refers to it.
<question>argumenta text in double quotes like "Order service"The question that was decided.
<equals>argumentone of the arrows =Separates the question from the choice.
<choice>argumenta text in double quotes like "Order service"The chosen option.
[then]optional argumentone of the arrows =>Introduces the consequence.
[consequence]optional argumenta text in double quotes like "Order service"What follows from the choice.
open=attributea text in double quotes like "Order service"Who still decides an open question; the card is drawn dashed.

Example:

adr E1 "How do the services coordinate?" = "Events over Kafka" => "No central coordinator"

Besides the codes of the language and the kernel, listed in the overview, the rules of state report these. An error stops the build; a warning is printed and the picture is still drawn.

CodeSeverityWhat it checks
U440errorNo transition leaves a final state or a terminate pseudostate, and none enters an initial pseudostate: it is an entry only. UML 2.5.1: 14.2.3 Final state, 14.2.3 Initial pseudostate, 14.2.3 Terminate pseudostate.
U441errorEach pseudostate has its number of ways in and out: initial and history at most one out, a fork one in and at least two out, a join at least two in and one out, choice and junction at least one each. UML 2.5.1: 14.2.3 Initial pseudostate, 14.2.3 Shallow and deep history pseudostates, 14.2.3 Fork pseudostate, 14.2.3 Join pseudostate, 14.2.3 Choice pseudostate, 14.2.3 Junction pseudostate.
U442errorThe transition from an initial pseudostate and the branches of fork and join have neither trigger nor guard; transitions leaving other pseudostates have no trigger. UML 2.5.1: 14.2.3.8 Transition with trigger, guard and effect.
U443errorA region, the top level included, has at most one initial pseudostate, one shallow and one deep history. UML 2.5.1: 14.2.3 Initial pseudostate, 14.2.3 Shallow and deep history pseudostates.
U444errorA history pseudostate remembers the active substate of a composite state, so it lies in one. UML 2.5.1: 14.2.3 Shallow and deep history pseudostates.
U445errorNesting with in forms no cycle, and an internal transition names its trigger: it fires on an event without leaving the state. UML 2.5.1: 14.2.3.4 Composite state with substates, 14.2.4 Internal transition in the compartment of a state.
U446errorThe branches of a fork end at states, the branches of a join start at states. UML 2.5.1: 14.2.3 Fork pseudostate, 14.2.3 Join pseudostate.
U447errorThe else branch applies when no other guard holds; two of them at one vertex contradict each other. UML 2.5.1: 14.2.3.8 Predefined guard else.
U448errorA region belongs to a state; a state with regions keeps its substates in them; a transition never crosses the border between two regions of one state, they run at the same time; and the branches of a fork or join lie in different regions. UML 2.5.1: 14.2.3.2 Orthogonal regions of a state, separated by dashed lines, 14.2.3 Fork pseudostate, 14.2.3 Join pseudostate.
U449errorEntry and exit points sit on the border of a state. An entry point is reached from outside and leads inside, an exit point the other way round. UML 2.5.1: 14.2.3 Entry point on the border of a state, 14.2.3 Exit point on the border of a state.
U460errorEntry and exit points belong to a composite state, or as connection point references to a submachine state; a simple state has none. UML 2.5.1: 14.2.3 Entry point on the border of a state, 14.2.3 Exit point on the border of a state, 14.2.3.4 Submachine state calling another state machine.
U461errorA submachine state calls another state machine and has no substates or regions of its own. At its points, transitions from outside end at the entry point and start at the exit point; the way inside lies in the called machine. UML 2.5.1: 14.2.3.4 Submachine state calling another state machine.
U462errorA time event after(duration) and a change event when(condition) are triggers: they stand in on= with parentheses. In the guard when= they would be a condition, not an event. UML 2.5.1: 13.3.3 Time event as a trigger, after(…), 13.3.3 Change event as a trigger, when(…).
U463errorA protocol state machine ({protocol} in the title) says which calls are allowed in which order. Its states have no entry, do or exit behaviour, its transitions no effect, and it has no history. UML 2.5.1: 14.4.3 Protocol state machine, 14.4.3 Protocol transition with precondition and postcondition.
U464errorOnly the transition of a protocol state machine has a postcondition post=. UML 2.5.1: 14.4.3 Protocol transition with precondition and postcondition.
U465errorA note in a state machine diagram is a comment on one vertex: it names it with on. UML 2.5.1: 7.2.3.2 Comment (note).
U940warningA state machine starts at an initial pseudostate at the top level, and an initial pseudostate leads somewhere. A machine drawn as one state with its own entry and exit points starts at the caller instead. UML 2.5.1: 14.2.3 Initial pseudostate.
U941warningEvery state can be reached from the initial pseudostate: entering a composite state reaches its inside, and being in a substate means being in its parents too. UML 2.5.1: 14.2.3.4 Simple state.
U942warningA simple state that no transition leaves, neither itself nor a parent nor an exit point of it, is a dead end; usually a transition to a final state is missing. UML 2.5.1: 14.2.3.4 Simple state, 14.2.3 Final state.
U943warningEvery way out of a choice has a guard and one of them is else, so the machine never gets stuck there; else belongs to a choice or junction. UML 2.5.1: 14.2.3 Choice pseudostate, 14.2.3.8 Predefined guard else.
U944warningTwo ways out of a state on the same trigger need guards that tell them apart; otherwise the machine is not deterministic. UML 2.5.1: 14.2.3.8 Transition with trigger, guard and effect.
U945warningA transition of a state to itself leaves and enters it again and runs its exit and entry behaviour; an internal transition does not. UML 2.5.1: 14.2.4 Internal transition in the compartment of a state, 14.2.4 Entry, do and exit behavior in the compartment of a state.
U946warningA transition that ends at the frame of a composite state enters it at its initial pseudostate; without one it is not clear where it continues. States with regions are checked per region. UML 2.5.1: 14.2.3.4 Composite state with substates, 14.2.3 Initial pseudostate.
U947warningWhat a fork splits, a join usually brings together again. UML 2.5.1: 14.2.3 Fork pseudostate, 14.2.3 Join pseudostate.
U948warningEach region of a state starts at its own initial pseudostate, unless every way into the state enters the region explicitly, as the branches of a fork do. UML 2.5.1: 14.2.3.2 Orthogonal regions of a state, separated by dashed lines, 14.2.3 Initial pseudostate.
U949warningAn entry or exit point has a way in and a way out. On a submachine state only the outside counts, and on the frame of a machine drawn with its own points the outside lies with the caller. UML 2.5.1: 14.2.3 Entry point on the border of a state, 14.2.3 Exit point on the border of a state.
U960warningA state that defers an event and fires a transition on it in the same state: the transition wins and the deferral says nothing. UML 2.5.1: 14.2.4 Deferred event in the compartment of a state.
U961warningA deferred event waits for a later state that fires a transition on it; without one it waits forever. UML 2.5.1: 14.2.4 Deferred event in the compartment of a state.