Complete Diagram Guide
by Peta Team
Complete Diagram Guide
Share this page
State Diagrams
State diagrams visualize the lifecycle of objects, showing how they transition between different states. They're perfect for modeling workflows, lifecycles, and state machines.
Basic Syntax
The fundamental syntax for state diagrams shows state transitions with events:
This creates a transition from State A to State B triggered by an event.
State Syntax
Creating States
States are created simply by naming them:
The renderer automatically:
- Creates state boxes
- Draws transitions with arrows
- Labels transitions with events
Transition Syntax
Basic Transitions
Use `->` to create transitions:
RST
1
2 FromState -> ToState : event
Components:
- FromState: The source state
- Arrow: `->` indicates a transition
- ToState: The destination state
- Event: The trigger for the transition (optional)
Example:
Multiple States
Linear Flow
Sequential state changes:
Branching Paths
Multiple transitions from one state:
Complex Lifecycles
Complete Workflow
Show full lifecycle:
State Machines
Model complex state machines:
Practical Examples
User Session
Traffic Light
Payment Processing
Ticket Lifecycle
Tips and Best Practices
- Clear state names: Use descriptive, concise names
- Logical flow: Arrange states in logical order
- Meaningful events: Describe what triggers each transition
- Complete lifecycle: Include all possible states
- Handle all paths: Show all possible transitions
State Design Guidelines
State Characteristics
Good states:
- Mutually exclusive (an object is in only one state at a time)
- Clearly defined (no ambiguity about what the state means)
- Meaningful (represent real-world conditions)
- Stable (don't change too frequently)
Event Characteristics
Good events:
- Clear triggers (what causes the transition)
- Atomic (can't be broken down further)
- Timely (occur at a specific moment)
- Relevant (meaningful to the system)
Common Patterns
Simple Lifecycle
Approval Process
Retry Logic
Next Steps
Now that you understand all five diagram types, let's explore advanced features and best practices in the next chapter.