tarfin-labs/event-machine
| Install | |
|---|---|
composer require tarfin-labs/event-machine |
|
| Latest Version: | 9.21.0 |
| PHP: | ^8.3|^8.4|^8.5 |
| Laravel: | 11 · 12 · 13 |
| Older releases: | 10 |
| License: | MIT |
| Last Updated: | Oct 5, 2026 |
| Links: | GitHub · Packagist |
Event-driven state machines for Laravel
Documentation · Installation · Why EventMachine?
Why EventMachine?
Your business logic deserves better than nested if-statements.
EventMachine brings the power of finite state machines to Laravel, inspired by XState. Define your states, transitions, and behaviors declaratively - and let the machine handle the complexity.
The Problem
// Without state machines: scattered conditionals, hidden rules, impossible to test
if ($order->status === 'pending' && $user->can('approve') && !$order->isExpired()) {
if ($order->total > 10000 && !$order->hasSecondApproval()) {
// More nested logic...
}
}
The Solution
// With EventMachine: clear states, explicit transitions, testable behaviors
MachineDefinition::define(
config: [
'initial' => 'pending',
'states' => [
'pending' => [
'on' => [
'APPROVE' => [
'target' => 'approved',
'guards' => [CanApproveGuard::class, NotExpiredGuard::class],
],
],
],
'approved' => [
'entry' => NotifyCustomerAction::class,
],
],
],
);
Key Benefits
| Feature | Description |
|---|---|
| Event Sourced | Every transition persisted. Full audit trail. Replay history. |
| Behaviors | Guards validate, calculators compute, actions execute. |
| Parallel Dispatch | True parallel execution via Laravel queues. 5s + 2s = 5s, not 7s. |
| Testable | Fake any behavior. Assert states. Verify transitions. |
| Type-Safe Context | Spatie Data powered. Validated. IDE autocompletion. |
| Archival | Compress millions of events. Restore any machine instantly. |
| Laravel Native | Eloquent, DI, Artisan commands. Built for Laravel. |
Installation
composer require tarfin-labs/event-machine
php artisan vendor:publish --tag="event-machine-migrations"
php artisan migrate
AI Agent Skill
EventMachine ships with an official Agent Skill so AI coding agents can write correct, idiomatic EventMachine code — it loads naming conventions, best practices, testing patterns, and the full VitePress documentation on demand.
Install via npx skills — works with 45+ agents including Claude Code, Cursor, GitHub Copilot, Cline, Codex, OpenCode, Gemini CLI, Warp, Amp, and many others:
npx skills add tarfin-labs/event-machine#plugin-dist
The CLI detects your installed agents and wires the skill into the right location. The plugin-dist branch is a self-contained, materialized snapshot published automatically on every release tag.
What the skill loads:
- Immediately (when the skill triggers): naming conventions, 13 best-practice summaries, core concepts, quick-start snippets, testing API cheat-sheet, Laravel integration map, delegation/parallel gotcha tables.
- On demand (when the agent needs deeper detail): curated cheat-sheets under
references/and the full 87-page documentation underdocs/.
Read the full skill guide at eventmachine.dev/getting-started/agent-skill.
Support Policy
Only the latest major version (currently v7) receives bug fixes and security patches. All previous versions are end of life. See the Upgrading Guide for step-by-step migration from any version.
Eloquent Integration
class Order extends Model
{
use HasMachines;
protected $casts = [
'machine' => MachineCast::class.':'.OrderMachine::class,
];
}
// Use it naturally
$order = Order::create();
$order->machine->send(['type' => 'SUBMIT']);
$order->machine->send(['type' => 'APPROVE']);
$order->machine->state->matches('approved'); // true
$order->machine->state->history->count(); // 3 events tracked
Documentation
For guards, actions, calculators, hierarchical states, parallel dispatch, validation, testing, and more:
Credits
- Yunus Emre Deligöz
- Fatih Aydın
- Yunus Emre Nalbant
- Faruk Can
- Turan Karatuğ
- Yılmaz Demir
- Maybe you? Contribute →
License
MIT License. See LICENSE for details.
Related Packages
Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox...
A database-backed alternative to Horizon & Laravel Queues — durable jobs, sophis...
Database-driven state machine and workflow engine for Laravel. Multi-step approv...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 9.21.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.20.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.19.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.18.1 | ^8.3| | ^11.0.8| | MIT | |
| 9.18.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.17.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.16.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.15.2 | ^8.3| | ^11.0.8| | MIT | |
| 9.15.1 | ^8.3| | ^11.0.8| | MIT | |
| 9.15.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.14.1 | ^8.3| | ^11.0.8| | MIT | |
| 9.14.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.13.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.12.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.11.1 | ^8.3| | ^11.0.8| | MIT | |
| 9.11.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.10.4 | ^8.3| | ^11.0.8| | MIT | |
| 9.10.3 | ^8.3| | ^11.0.8| | MIT | |
| 9.10.2 | ^8.3| | ^11.0.8| | MIT | |
| 9.10.1 | ^8.3| | ^11.0.8| | MIT | |
| 9.10.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.9.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.8.6 | ^8.3| | ^11.0.8| | MIT | |
| 9.8.5 | ^8.3| | ^11.0.8| | MIT | |
| 9.8.4 | ^8.3| | ^11.0.8| | MIT | |
| 9.8.3 | ^8.3| | ^11.0.8| | MIT | |
| 9.8.2 | ^8.3| | ^11.0.8| | MIT | |
| 9.8.1 | ^8.3| | ^11.0.8| | MIT | |
| 9.8.0 | ^8.3| | ^11.0.8| | MIT | |
| 9.7.3 | ^8.3| | ^11.0.8| | MIT |
Showing the latest 30 of 112. See every release on Packagist