Stately Studio
Stately Studio is a visual editor for creating, editing, and analyzing state machines. It provides:- Visual state machine design and editing
- Automatic layout and diagram generation
- Live simulation and testing
- Export to XState v5 code
- Collaboration features
- Version history
- Documentation generation
Stately Studio is available at state.new and is free for public machines.
Creating Machines Visually
You can design state machines entirely in Stately Studio:- Go to state.new
- Create a new machine
- Add states by clicking the canvas
- Add transitions by dragging between states
- Configure context, actions, and guards in the inspector
- Export to XState code
Importing Existing Machines
You can import existing XState code into Stately Studio:- Copy your machine code
- Open Stately Studio
- Click “Import” and paste your code
- The visual diagram is generated automatically
Live Simulation
Stately Studio allows you to simulate your state machine in real-time:- Send events to see transitions
- Inspect context values
- View action execution order
- Test guards and conditions
- Explore all possible states
Visual Features
State Types
Stately Studio visually distinguishes different state types:- Atomic states - Single box
- Compound states - Box containing child states
- Parallel states - Dashed border indicating simultaneous regions
- Final states - Double border
- History states - Circle with H
Transitions
- Solid arrows - External transitions (exit and re-enter)
- Curved arrows - Internal transitions (stay in state)
- Eventless transitions - Dashed arrows (always taken)
- Guarded transitions - Diamond indicator
Context and Actions
View and edit:- Context schema with types
- Entry and exit actions
- Transition actions
- Action parameters
Generating Diagrams from Code
XState provides utilities to generate diagrams from machines using the graph module (graph/graph.ts:1-100):
Directed Graph Format
ThetoDirectedGraph() function returns an object with:
-
nodes- Array of state nodes with properties:id- Unique state identifiertype- State type (atomic, compound, parallel, final)data- Additional state metadata
-
edges- Array of transitions with properties:source- Source state IDtarget- Target state IDevent- Event that triggers transitionguards- Guard conditionsactions- Actions executed on transition
Integration with Visualization Libraries
You can use the directed graph format with visualization libraries:D3.js Example
Mermaid Example
Convert to Mermaid diagram format:VS Code Extension
The Stately VS Code extension provides:- Inline visualization of machines in your code
- Syntax highlighting
- Autocomplete for states and events
- Quick navigation between states
- Error detection
Stately Inspector
The@statelyai/inspect package enables runtime visualization:
- See all state transitions in real-time
- Inspect context changes
- View event history
- Monitor actor hierarchy
- Export session recordings
See the Inspection guide for detailed setup instructions.
Documentation Generation
Stately Studio automatically generates documentation from your machines:- State descriptions
- Event catalogs
- Transition tables
- Context schemas
- Action references
- Markdown
- HTML
- Interactive site
Collaboration Features
Stately Studio supports team collaboration:- Real-time editing - Multiple users can edit simultaneously
- Comments - Add notes to states and transitions
- Version history - Track changes over time
- Sharing - Share machines via URL
- Teams - Organize machines by team/project
Best Practices
Start with the visual editor
Start with the visual editor
For complex machines, design visually first, then export to code. This helps catch logical errors early.
Keep diagrams clean
Keep diagrams clean
Use state descriptions instead of long state names. Group related states in compound states.
Use consistent naming
Use consistent naming
Follow naming conventions for states (PascalCase) and events (SCREAMING_SNAKE_CASE) across your team.
Document guards and actions
Document guards and actions
Add descriptions to guards and actions in Stately Studio to improve team understanding.
Export Formats
Stately Studio supports exporting to:- XState v5 - TypeScript/JavaScript
- JSON - Machine definition as JSON
- PNG/SVG - Static diagrams
- Mermaid - Mermaid diagram syntax
- Stately Sky - Deployed executable machines