Skip to content

File Structure Syntax

Complete syntax patterns for EventFlow file organization.

Basic File Structure

flow
machine: @machine_name

scenario: scenario name

  given:
    // setup

  on :event from @actor (api)
    // actions
    // guards
    // emit
    expect:
      // assertions

  on :event from @actor
    // ...

  expect:
    // scenario assertions

Machine Definition

flow
machine: @name

Examples:

flow
machine: @order
machine: @payment
machine: @customer

System Definition

flow
system: system name

uses:
  @machine1 from "./path/to/machine1.flow"
  @machine2 from "./path/to/machine2.flow"

machine: @machine3
  // Can also define inline

Scenario Definition

flow
scenario: descriptive name

  // optional given
  given:
    // setup

  // event handlers
  on :event from @actor (api)
    // ...

  // optional assertions
  expect:
    // ...

Given Blocks

Scenario-Level

flow
scenario: name

  given:
    @actor is in state
    $variable: type is value
    collection contains items

Event-Level

flow
on :event from @actor (api)

  given:
    additional setup

Table Data

flow
given:
  cart contains:
    | product | price | quantity |
    | Laptop  | 1200  | 1        |
    | Mouse   | 25    | 2        |

Expect Blocks

Event-Level Assertions

flow
on :event from @actor (api)
  // actions

  expect:
    = assertion1
    = assertion2

Scenario-Level Assertions

flow
scenario: name

  on :event1 from @customer (api) ...
  on :event2 ...

  expect:
    = final assertions

Comments

flow
// Single line comment

/*
  Multi-line
  comment
*/

action // Inline comment

Indentation

EventFlow uses indentation for nesting. Use consistent spaces (2 or 4):

flow
machine: @order                    // Level 0

scenario: checkout                 // Level 1

  given:                           // Level 2
    @customer is logged in         // Level 3

  on :checkout from @customer (api)    // Level 2
    ? cart is valid                // Level 3
      order moves to #processing   // Level 4
      emit :request to @payment    // Level 4

    otherwise                      // Level 3
      emit :error to @customer     // Level 4

  expect:                          // Level 2
    = order is in #processing      // Level 3

Released under the MIT License.