Development › Events

Events

Events are a first-class integration mechanism for this architecture.

#Event kinds

KindLocationUse when
Domain eventsModules/{M}/Domain/EventsSomething meaningful happened inside a bounded context
Integration eventsMessaging / Kafka topicsOther modules or services must react asynchronously
Application eventsLaravel listeners (sparingly)UI/side concerns that stay in-process

#Metadata contract

Domain events extend App\Messaging\Events\AbstractDomainEvent and implement App\Messaging\Contracts\DomainEvent:

event_id
event_type
aggregate_id
aggregate_type
occurred_at
version
producer
correlation_id
causation_id
payload

#Creating a domain event

php artisan make:domain-event OrderCreated --module=Orders

Publish via the EventBus contract from an Action:

class="tk-v">$this->eventBus->publish(new OrderCreated(class="tk-v">$order));

#Publishing strategy

  1. In-process — useful for modular monolith listeners
  2. Kafka — for async fan-out and microservice boundaries
  3. Outbox — for critical “DB commit + event” consistency (see kafka.md)

Do not publish events from Controllers. Publish from Application Actions after the business operation succeeds (or via outbox in the same DB transaction).

#Naming

Prefer stable dotted types:

orders.order.created
orders.order.paid
payments.payment.failed

Keep payloads versionable and free of internal Eloquent models.

#Consumers

php artisan make:consumer OrderCreatedConsumer --module=Orders

Consumers must be idempotent (see IdempotencyStore).

Edit this page on GitHub