Skill

applying-domain-event-publisher

Apply when creating, refactoring, changing, planning (plan mode) or reviewing domain event publishing.

From kotlin-patterns
Install
1
Run in your terminal
$
npx claudepluginhub allousas/claude-code-plugins --plugin kotlin-patterns
Tool Access

This skill uses the workspace's default tool permissions.

Supporting Assets
View in Repository
examples.md
Skill Content

What it is

A pattern that introduces an abstraction for publishing domain events, allowing the domain or application layer to emit events without depending on messaging infrastructure.

Purpose

Publish domain events after state changes to notify other parts of the system about what happened, while keeping the domain layer decoupled from messaging infrastructure.

Typical Flow

  1. Application service executes a domain operation (create, update, delete)
  2. Application service calls domainEventPublisher.publish after successful state change
  3. Domain event is published to in-process handlers through an in-memory dispatcher
  4. Event handlers/listeners react to the event synchronously (outbox pattern, metrics, logging, etc.)

Guidelines

DO:

  • Publish events in the application service after the state change succeeds
  • Define a DomainEvent interface or base class for all events
  • Use In-Memory event dispatcher for passing the event to the different in-process handlers
  • Use a Separate Handler to handle the domain event
  • Handle metrics, logging or publishing to kafka (or tx-outbox) side-effects for domain events with this pattern and handlers

DON'T:

  • Use For cross-service/process events - decouple asynchronous processing using messaging or queues (e.g. Kafka, SQS)
  • Publish events from inside domain entities - the application service decides when to publish
  • Publish events before the state change is persisted (risk of publishing without actual change)
  • Use events for request/response communication - events are fire-and-forget notifications

Examples

Please use always these examples as reference: examples.md

Similar Skills
cache-components

Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). **PROACTIVE ACTIVATION**: Use this skill automatically when working in Next.js projects that have `cacheComponents: true` in their next.config.ts/next.config.js. When this config is detected, proactively apply Cache Components patterns and best practices to all React Server Component implementations. **DETECTION**: At the start of a session in a Next.js project, check for `cacheComponents: true` in next.config. If enabled, this skill's patterns should guide all component authoring, data fetching, and caching decisions. **USE CASES**: Implementing 'use cache' directive, configuring cache lifetimes with cacheLife(), tagging cached data with cacheTag(), invalidating caches with updateTag()/revalidateTag(), optimizing static vs dynamic content boundaries, debugging cache issues, and reviewing Cache Component implementations.

138.5k
Stats
Parent Repo Stars1
Parent Repo Forks0
Last CommitFeb 24, 2026