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 Source | Mermaid Output |
|---|---|
initial: StateName | [*] --> StateName (initial state) |
evolve(From, Event) -> To | From --> To : Event |
terminal: State | State --> [*] |
Self-transitions (evolve(A, E) -> A) produce A --> A : E.
Conventions
- Declaration order preserved: Transitions appear in the same order as
evolveclauses in the source.dddfile. - 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.