Skip to content

Generate State Machine Diagrams

The compiler generates Mermaid diagrams from .ddd files. Each diagram type operates on the validated AST — no additional configuration is needed.

What You Get

Each decider produces one stateDiagram-v2 diagram showing states, transitions, and terminal markers.

Example

Given this .ddd decider:

decider User {
commands: Register, Deactivate
events: Registered, Deactivated
state: Unregistered | Active | Inactive
initial: Unregistered
terminal: Inactive
evolve(Unregistered, Registered) -> Active
evolve(Unregistered, Deactivated) -> Inactive
evolve(Active, Registered) -> Active
evolve(Active, Deactivated) -> Inactive
}

The generator produces:

stateDiagram-v2
[*] --> Unregistered
Unregistered --> Active : Registered
Unregistered --> Inactive : Deactivated
Active --> Active : Registered
Active --> Inactive : Deactivated
Inactive --> [*]

Prerequisites

A valid .ddd file with evolve clauses and (optionally) terminal and initial declarations.

Mapping Reference

DSL SourceMermaid Output
initial: StateName[*] --> StateName (initial state)
evolve(From, Event) -> ToFrom --> To : Event
terminal: StateState --> [*]

Self-transitions (evolve(A, E) -> A) produce A --> A : E.

Conventions

  • Declaration order preserved: Transitions appear in the same order as evolve clauses in the source .ddd file.
  • Initial state: The state declared in initial: is the initial state ([*] -->).
  • Terminal states: Only states listed in terminal: produce end markers (--> [*]). States not listed as terminal do not.
  • State names: The grammar enforces identifiers matching [_a-zA-Z][\w]*, which is valid Mermaid syntax. No escaping is needed.

Output

Diagram files use the .mmd extension and are written to the configured output directory, never mixed with .ddd source files.