Aexol Language

DocsAexol LanguageWorkflows & Recipes

Aexol workflows define state machines with transitions. Plus ready-to-use recipes for common patterns.

Workflows & Recipes

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

Basic Syntax

A workflow consists of states and transitions between them:

workflow OrderFlow {
  initial: pending
  pending -> processing
  processing -> shipped
  shipped -> delivered
}
✨ Edit in Studio

Initial State

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

workflow TaskFlow {
  initial: todo
  todo -> in_progress
  in_progress -> done
  done -> archived
}
✨ Edit in Studio

Transition Conditions

Add when clauses to make transitions conditional:

workflow OrderFlow {
  initial: pending
  pending -> processing when payment_confirmed
  pending -> cancelled when timeout
  processing -> shipped when items_packed
}
✨ Edit in Studio

Multiple Transitions and Bidirectional Flows

States can have multiple outgoing transitions, and flows can move in both directions:

workflow DocumentFlow {
  initial: draft
  draft -> review
  review -> draft              // Can return to draft
  review -> approved
  approved -> published
  published -> archived
  archived -> draft            // Can revive from archive
}
✨ Edit in Studio

Workflows with Types

Combine workflows with type definitions 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
}
✨ Edit in Studio

Code Generation

Aexol generates type-safe state machine classes from your workflow definitions in TypeScript, Python, Rust, Go, and JavaScript. Each generated class includes:

  • An enum with all states
  • canTransitionTo(state) — check if a transition is valid
  • transitionTo(state) — execute a transition
  • getCurrentState() — read current state
  • Automatic initial state from your initial declaration

Use Studio to generate code from any workflow.


Recipes

Ready-to-use patterns for common scenarios. Copy and adapt these to jump-start your workflow definitions.

Todo App

type Task {
  id: string
  title: string
  description: string
  status: TaskStatus
  assigneeId: string
}

enum TaskStatus {
  todo
  in_progress
  done
}

workflow TaskFlow {
  initial: todo
  todo -> in_progress when started
  in_progress -> done when completed
  in_progress -> todo when reverted
}

visitor TaskManager {
  "create tasks"
  "view tasks"
  "edit tasks"
  "assign tasks"
}
✨ Edit in Studio

E-Commerce Order Flow

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

enum OrderStatus {
  pending
  payment_received
  processing
  shipped
  delivered
  cancelled
}

workflow OrderProcessing {
  initial: pending
  pending -> payment_received when payment_confirmed
  payment_received -> processing
  processing -> shipped when items_packed
  shipped -> delivered when customer_confirms
  pending -> cancelled when timeout
  payment_received -> cancelled when refund_requested
}
✨ Edit in Studio

Document Approval

type Document {
  id: string
  title: string
  content: string
  authorId: string
  status: DocumentStatus
  reviewers: string[]
}

enum DocumentStatus {
  draft
  pending_review
  approved
  rejected
  published
}

workflow DocumentApproval {
  initial: draft
  draft -> pending_review when submitted
  pending_review -> approved when all_reviewers_approve
  pending_review -> rejected when reviewer_rejects
  rejected -> draft when author_revises
  approved -> published when author_publishes
}
✨ Edit in Studio

Support Ticket System

type Ticket {
  id: string
  customerId: string
  subject: string
  description: string
  priority: Priority
  status: TicketStatus
  assignedTo: string
}

enum Priority { low medium high urgent }

enum TicketStatus {
  open
  assigned
  in_progress
  waiting_customer
  resolved
  closed
}

workflow TicketLifecycle {
  initial: open
  open -> assigned when agent_assigned
  assigned -> in_progress when agent_starts
  in_progress -> waiting_customer when info_needed
  waiting_customer -> in_progress when customer_responds
  in_progress -> resolved when issue_fixed
  resolved -> closed when customer_confirms
  resolved -> in_progress when customer_reopens
}
✨ Edit in Studio

User Onboarding

type UserAccount {
  id: string
  email: string
  name: string
  status: OnboardingStatus
  completedSteps: string[]
}

enum OnboardingStatus {
  invited
  email_verified
  profile_created
  preferences_set
  tutorial_completed
  active
}

workflow OnboardingFlow {
  initial: invited
  invited -> email_verified when email_confirmed
  email_verified -> profile_created when profile_saved
  profile_created -> preferences_set when preferences_saved
  preferences_set -> tutorial_completed when tutorial_finished
  tutorial_completed -> active when account_activated
  email_verified -> invited when email_expired
}

visitor NewUser {
  "verify email"
  "create profile"
  "set preferences"
  "complete tutorial"
}
✨ Edit in Studio

Payment Processing

type Payment {
  id: string
  orderId: string
  amount: number
  currency: string
  status: PaymentStatus
}

enum PaymentStatus {
  pending
  processing
  succeeded
  failed
  refunded
  disputed
}

workflow PaymentFlow {
  initial: pending
  pending -> processing when payment_submitted
  processing -> succeeded when payment_confirmed
  processing -> failed when payment_declined
  failed -> pending when retry_allowed
  succeeded -> refunded when refund_issued
  succeeded -> disputed when customer_disputes
}
✨ Edit in Studio

Inventory Management

type InventoryItem {
  id: string
  sku: string
  name: string
  quantity: number
  status: InventoryStatus
  warehouseId: string
}

enum InventoryStatus {
  in_stock
  low_stock
  out_of_stock
  reserved
  damaged
  returned
}

workflow InventoryFlow {
  initial: in_stock
  in_stock -> low_stock when quantity_below_threshold
  low_stock -> out_of_stock when quantity_zero
  low_stock -> in_stock when restocked
  out_of_stock -> in_stock when restocked
  in_stock -> reserved when order_placed
  reserved -> in_stock when order_cancelled
  reserved -> low_stock when order_shipped
  in_stock -> damaged when damage_reported
  damaged -> returned when return_authorized
}

agent InventoryBot {
  "reserve stock"
  "release stock"
  "update stock levels"
  "alert low stock"
}
✨ Edit in Studio

Appointment Booking

type Appointment {
  id: string
  customerId: string
  serviceId: string
  dateTime: datetime
  status: AppointmentStatus
  notes: string
}

enum AppointmentStatus {
  requested
  confirmed
  rescheduled
  in_progress
  completed
  cancelled
  no_show
}

workflow AppointmentFlow {
  initial: requested
  requested -> confirmed when provider_accepts
  requested -> cancelled when customer_cancels
  confirmed -> rescheduled when time_changed
  confirmed -> in_progress when appointment_starts
  confirmed -> cancelled when customer_cancels
  confirmed -> no_show when customer_missed
  in_progress -> completed when service_finished
  no_show -> requested when customer_reschedules
}

visitor Customer {
  "request appointment"
  "view appointments"
  "cancel appointment"
  "reschedule appointment"
}
✨ Edit in Studio

Course Enrollment

type Enrollment {
  id: string
  studentId: string
  courseId: string
  status: EnrollmentStatus
  progress: number
  grade: string
}

enum EnrollmentStatus {
  pending
  enrolled
  in_progress
  completed
  failed
  withdrawn
}

workflow EnrollmentFlow {
  initial: pending
  pending -> enrolled when payment_confirmed
  pending -> withdrawn when student_cancels
  enrolled -> in_progress when course_started
  in_progress -> completed when all_modules_finished_and_passing
  in_progress -> failed when final_grade_below_threshold
  in_progress -> withdrawn when student_withdraws
  failed -> enrolled when student_retakes
}

agent EnrollmentBot {
  "process enrollment"
  "track progress"
  "send reminders"
  "issue certificates"
}
✨ Edit in Studio

CI/CD Pipeline

type Build {
  id: string
  commitHash: string
  branch: string
  status: BuildStatus
  logs: string
}

enum BuildStatus {
  queued
  building
  testing
  deploying
  succeeded
  failed
  cancelled
}

workflow CICDPipeline {
  initial: queued
  queued -> building when runner_available
  building -> testing when build_succeeds
  building -> failed when build_fails
  testing -> deploying when tests_pass
  testing -> failed when tests_fail
  deploying -> succeeded when deploy_succeeds
  deploying -> failed when deploy_fails
  queued -> cancelled when user_cancels
}
✨ Edit in Studio

Recipe Comparison

RecipeComplexityStatesTransitionsBest For
Todo AppLow33Simple task tracking
User OnboardingMedium65Multi-step registration flows
CI/CD PipelineMedium78DevOps automation
Appointment BookingMedium78Service scheduling
Course EnrollmentMedium67Learning management systems
Payment ProcessingMedium66Financial transactions
Document ApprovalMedium55Review and publishing flows
Support Ticket SystemMedium-High67Customer service platforms
E-Commerce Order FlowMedium-High66Online retail
Inventory ManagementHigh68Warehouse and supply chain

Best Practices

  • Keep states minimal — each state should represent a distinct, meaningful stage; don't model transient moments
  • Name states clearly — use awaiting_payment not state3; names are your documentation
  • Model conditions explicitly — every transition should have a clear when condition that reflects a real-world trigger
  • Separate concerns — split large workflows into smaller, focused ones rather than cramming everything into a single flow
  • Align workflows with enums — when a type has a status field, its enum values should mirror the workflow states
  • Use agents for automation — let agents like NotificationService or InventoryBot react to transitions rather than embedding side effects in the workflow

Quick Start Tips

  1. Start by listing all the states your process goes through
  2. Draw the transitions on paper or a whiteboard first — it reveals gaps and dead ends
  3. Add when conditions to each transition to make the intent explicit
  4. Create an enum that mirrors your states, then use it in a type
  5. Define visitors to model who can trigger which transitions
  6. Add agents for any automated side effects (notifications, stock updates, logging)

See Also

  • Language Reference — Full workflow syntax and all language features
  • Advanced Types — Arrays, circular references, and complex data structures
  • Tutorial — Build a complete specification step by step