Complete Diagram Guide

by Peta Team

Complete Diagram Guide

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:

Basic State Diagram event State A State B

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:

State Transition power on power off Off On

Multiple States

Linear Flow

Sequential state changes:

Branching Paths

Multiple transitions from one state:

Branching States pass fail retry abort Decision Success Failure Retry Abort

Complex Lifecycles

Complete Workflow

Show full lifecycle:

Document Lifecycle submit approve reject publish archive revise Draft Review Approved Rejected Published Archived

State Machines

Model complex state machines:

Order State Machine payment received validated processed customer request delivered feedback received refund processed Created Pending Processing Shipped Cancelled Delivered Complete Refunded

Practical Examples

User Session

User Session Lifecycle login activity timeout activity logout session expired Anonymous Logged In Active Logged Out

Traffic Light

Traffic Light System timer timer timer emergency Red Green Yellow

Payment Processing

Payment Processing submit success decline timeout retry retry max retries refund request Initiated Processing Completed Failed Cancelled Retrying Refunded

Ticket Lifecycle

Support Ticket Lifecycle assigned fixed complex reassigned confirmed issue persists new info duplicate Open In Progress Resolved Escalated Closed Reopened

Tips and Best Practices

  1. Clear state names: Use descriptive, concise names
  2. Logical flow: Arrange states in logical order
  3. Meaningful events: Describe what triggers each transition
  4. Complete lifecycle: Include all possible states
  5. 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

Simple Lifecycle activate deactivate archive Created Active Inactive Archived

Approval Process

Approval Process submit approve reject publish revise Draft Pending Review Approved Rejected Published

Retry Logic

Retry Logic completed failed retry max retries give up Attempting Success Retrying Failed Aborted

Next Steps

Now that you understand all five diagram types, let's explore advanced features and best practices in the next chapter.