Skip to content

Keyword Reference

Complete reference for all keywords in EventFlow.

Structure Keywords

machine:

Defines a machine (actor) in the system.

flow
machine: @order

The machine name must be prefixed with @.

system:

Defines a multi-machine system.

flow
system: e-commerce checkout

scenario:

Defines a feature or capability of a machine.

flow
scenario: checkout flow

A scenario groups related event handlers together.

uses:

Imports machines into a system from separate files.

flow
system: checkout

uses:
  @order from "./order.flow"
  @payment from "./payment.flow"

Event Keywords

on

Defines an internal event handler.

flow
on :payment_success from @payment
  order moves to #paid

Internal events can only be triggered by other machines.

on>

Defines a public/API event handler.

flow
on> :checkout from @customer
  order moves to #processing

API events can be triggered externally (e.g., via HTTP).

from

Specifies the sender of an event.

flow
on :payment_success from @payment
  // Only handles events from @payment

Optional - without from, accepts from any sender:

flow
on :status_update
  // Accepts from any source

emit

Sends an event to another machine.

flow
emit :payment_request to @payment

to

Specifies the target of an emitted event.

flow
emit :notification to @customer

with / with:

Attaches data to an emitted event.

Inline:

flow
emit :payment_request to @payment
  with $order_id, $total

Table format:

flow
emit :order_details to @warehouse
  with:
    | field    | value      |
    | order_id | $order_id  |
    | items    | $items     |

With types:

flow
emit :payment_request to @payment
  with:
    | field    | type   | value     |
    | order_id | string | $order_id |
    | amount   | number | $total    |

Test Keywords

given:

Declarative test setup. Describes the initial state.

Scenario-level:

flow
scenario: checkout

  given:
    @customer is logged in
    cart has items
    $total: number is 1200

Event-level:

flow
on> :checkout from @customer

  given:
    $discount_code is "SUMMER20"

  ? discount is valid
    apply discount

expect:

Defines assertions to verify outcomes.

Event-level:

flow
on> :checkout from @customer
  order moves to #processing

  expect:
    = order is in #processing

Scenario-level:

flow
scenario: complete purchase

  on> :checkout ...
  on :payment_success ...

  expect:
    = order is in #paid
    = @customer received :confirmation

Guard Keywords

otherwise

Default case when no guards match.

flow
? $total > 1000
  priority becomes "high"
? $total > 100
  priority becomes "medium"
otherwise
  priority becomes "low"

Equivalent to empty ?:

flow
? $total > 100
  apply discount
?
  no discount

Scheduled Event Keywords

triggered:

Specifies when a scheduled event should fire.

flow
on :cleanup
  triggered: every day at 00:00

  for each item in #expired
    delete item

Schedule patterns:

flow
triggered: every day at 00:00
triggered: every hour
triggered: every monday at 09:00
triggered: every 30 minutes
triggered: every month on 1st at 00:00

for each

Iterates over aggregates. Required with triggered:.

flow
on :send_reminders
  triggered: every day at 09:00

  for each order in #pending
    ? created more than 12 hours ago
      emit :reminder to @customer

Can target multiple states:

flow
for each order in #pending, #processing
  send status update

Context Keywords

becomes

Sets a context value.

flow
$total becomes 100
$status becomes "active"

increases by / decreases by

Arithmetic operations.

flow
$total increases by 25
$balance decreases by $amount

adds / removes

Collection operations.

flow
$items adds "Laptop"
$items removes "Mouse"

clears

Empties a collection.

flow
$items clears
$cart clears

is

Used in given: to set initial values.

flow
given:
  $total: number is 100
  order is in #pending

State Keywords

State transition verbs

All equivalent:

  • moves to
  • transitions to
  • enters
  • becomes
  • changes to
flow
order moves to #paid
order transitions to #approved
payment enters #processing
ticket becomes #closed

is in / is not in

Checks current state.

flow
? order is in #pending
  process order

? order is not in #cancelled
  allow modification

Test File Keywords

test:

Defines a test file for a machine or system.

flow
test: @order
test: system checkout

for scenario:

Targets a specific scenario for testing.

flow
test: @order

  for scenario: checkout
    // tests for checkout scenario

for :event:

Targets transition tests for a specific event handler.

flow
for :checkout:
  empty cart rejected:
    with scenario:
      cart is empty
    = @customer received :error

for :event to @actor:

For system tests, targets an event to a specific machine.

flow
for :checkout to @order:
  guest rejected:
    // test variations

with scenario:

Overrides scenario-level given block.

flow
with scenario:
  cart is empty
  @customer is not logged in

with event:

Overrides event data/payload.

flow
with event:
  payment_method is "bank_transfer"

with given:

Overrides event-level given block.

flow
with given:
  shipping_address is invalid

with context:

Overrides context variables.

flow
with context:
  $total is 5000
  $retry_count is 2

assume:

Controls guard/action behavior for the test.

flow
assume:
  ? cart is valid = false
  process payment throws "Error"
  send email returns { status: "sent" }

observe:

Watches actions without changing behavior.

flow
observe:
  send confirmation email
  update inventory

= send confirmation email was called
= update inventory was not called

after

Specifies divergence point in scenario tests.

flow
payment fails:
  after :checkout
  receive :payment_failed
  = order is in #failed

receive

Specifies event received after divergence.

flow
after :checkout
receive :payment_failed from @payment

then

Continues event sequence after divergence.

flow
after :checkout
receive :payment_failed from @payment
then :payment_success from @payment
= order is in #paid

Complete Keyword List

KeywordPurpose
machine:Define a machine/actor
system:Define a multi-machine system
scenario:Define a feature/capability
uses:Import machines into system
onInternal event handler
on>Public/API event handler
fromEvent source filter
emitSend event
toEvent target
with / with:Event data
given:Test setup (declarative)
expect:Assertions block
otherwiseDefault guard case
triggered:Schedule for recurring events
for eachIterate over aggregates
becomesSet context value
increases byAdd to number
decreases bySubtract from number
addsAdd to collection
removesRemove from collection
clearsEmpty collection
isInitial value (in given)
moves toState transition
is inState check
test:Define test file
for scenario:Target scenario in tests
for :event:Target transition test
with scenario:Override scenario given
with event:Override event data
with given:Override event given
with context:Override context
assume:Control behavior
observe:Watch actions
afterDivergence point
receiveAlternative event
thenContinue sequence

Released under the MIT License.