Workflow Features

Aexol workflows define state machines with transitions, making it easy to model business processes, application flows, and state management.

Basic Syntax

workflow OrderFlow {
    Pending -> Processing
    Processing -> Shipped
    Shipped -> Delivered
}
✨ Edit in Studio

Initial State

Use initial to explicitly set the starting state. If omitted, the first listed state becomes initial.

workflow TaskFlow {
    initial Todo                // Explicit initial state
    Todo -> InProgress
    InProgress -> Done
    Done -> Archived
}
✨ Edit in Studio

States & Transitions

Simple States

workflow ContentFlow {
    initial Draft
    Draft -> Review
    Review -> Published
    Published -> Archived
}
✨ Edit in Studio

Multiple Transitions

A state can transition to multiple targets:

workflow OrderFlow {
    initial Pending
    Pending -> Processing
    Pending -> Cancelled
    Processing -> Shipped
    Processing -> Cancelled
    Shipped -> Delivered
}
✨ Edit in Studio

Bidirectional / Loops

States can transition back to earlier states:

workflow DocumentFlow {
    initial Draft
    Draft -> Review
    Review -> Draft             // Send back for changes
    Review -> Approved
    Approved -> Published
    Published -> Archived
    Archived -> Draft           // Revive from archive
}
✨ Edit in Studio

Complex Workflows

Multi-Path

workflow PaymentFlow {
    initial Pending
    Pending -> Authorized
    Pending -> Failed
    Authorized -> Captured
    Authorized -> Voided
    Captured -> Completed
    Captured -> Refunded
    Refunded -> Completed
    Failed -> Completed
}
✨ Edit in Studio

Approval Flows

workflow ApprovalFlow {
    initial Submitted
    Submitted -> UnderReview
    UnderReview -> Approved
    UnderReview -> Rejected
    UnderReview -> NeedsChanges
    NeedsChanges -> Submitted   // Loop back for revisions
    Rejected -> Closed
    Approved -> Closed
}
✨ Edit in Studio

Code Generation

Workflows generate type-safe state machine classes. Aexol can produce implementations in TypeScript, Python, Rust, Go, and JavaScript. Generated classes include:

Use Studio or the Remote MCP endpoint to generate code from any workflow.

Workflow with Types

Combine workflows with type definitions and visitors for complete business logic:

enum OrderStatus {
    Pending
    Processing
    Shipped
    Delivered
    Cancelled
}

type Order {
    id: string
    customerId: string
    status: OrderStatus
    items: OrderItem[]
    total: number
}

workflow OrderFlow {
    initial Pending
    Pending -> Processing
    Pending -> Cancelled
    Processing -> Shipped
    Processing -> Cancelled
    Shipped -> Delivered
}

visitor OrderManager {
    "create_order" {
        "view_order"
        "cancel_order"
    }
    "process_order" {
        "ship_order"
        "cancel_order"
    }
}
✨ Edit in Studio

Real-World Examples

Blog Publishing

workflow PostFlow {
    initial Draft
    Draft -> Review
    Review -> Draft             // Send back
    Review -> Scheduled
    Scheduled -> Published
    Published -> Archived
    Archived -> Draft           // Revive content
}
✨ Edit in Studio

Task Management

workflow TaskFlow {
    initial Todo
    Todo -> InProgress
    Todo -> Cancelled
    InProgress -> Blocked
    InProgress -> Done
    InProgress -> Cancelled
    Blocked -> InProgress
    Blocked -> Cancelled
}
✨ Edit in Studio

Incident Response

workflow IncidentFlow {
    initial Reported
    Reported -> Triaged
    Triaged -> Assigned
    Assigned -> InProgress
    InProgress -> Resolved
    Resolved -> Verified
    Verified -> Closed
    Closed -> Reopened       // Reopening
    Reopened -> Assigned
    Assigned -> Escalated    // Escalation path
    Escalated -> Assigned
}
✨ Edit in Studio

Best Practices

GuidelineGoodAvoid
Descriptive statesAwaitingPaymentState1, State2
Explicit initial stateinitial TodoLetting it default
Model all transitionsPending -> Cancelled tooOnly the happy path
Focused workflowsSeparate OrderFlow + ShippingFlowOne 20-state monolith
Align with enumsTaskStatus.Todo matches state TodoMismatched naming

Validation

Aexol validates:


See Also