/protean:add-eventfrom protean
Adds a complete event flow to a Protean aggregate: creates a domain event, aggregate method with self.raise_(), and event handler for side effects like notifications or cross-aggregate sync.
Ships in protean. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This workflow adds a complete event flow to an existing aggregate. It creates these artifacts, which work together:
OrderPlaced)self.raise_()| Artifact | Role | File location |
|---|---|---|
| Event class | Captures what happened (immutable fact) | <aggregate_folder>/<event_name_snake>.py |
| Aggregate method | Performs state change, raises the event | <aggregate_folder>/<aggregate>.py (existing file) |
| Event Handler | Reacts to event, orchestrates side effects | Same file as event (same-aggregate) or <aggregate_folder>/handle_<event_name_snake>.py (cross-aggregate), always in the source aggregate's folder |
| Command + command handler (cross-aggregate) | Carries the change to the target aggregate, which does the write | <target_folder>/<command_name_snake>.py |
Before generating, ensure you know the following. If any item is unknown, ask the user before proceeding.
OrderPlaced, PaymentConfirmed, UserRegistered)Follow the patterns in event.
Key points for this workflow:
OrderPlaced, PaymentConfirmed, UserRegisteredpart_of="AggregateName" (string, not class reference)HasOne/HasMany__version__ = 1 for schema evolution@domain.event(part_of="Order")
class OrderPlaced:
order_id: Identifier(required=True)
customer_id: String(required=True)
product_id: Identifier(required=True)
quantity: Integer(required=True)
total_amount: Decimal(precision=19, scale=4, required=True)
Follow the patterns in aggregate.
Key points for this workflow:
self.raise_(EventClass(...)) to raise the eventself.raise_() call to itraise_() is called@domain.aggregate
class Order:
order_id: Identifier(identifier=True)
customer_id: String(required=True)
product_id: Identifier(required=True)
quantity: Integer(required=True)
status: String(default="draft")
total_amount: Decimal(precision=19, scale=4, required=True)
confirmation_number: String()
tracking_number: String()
def place(self):
if self.status != "draft":
raise ValueError("Order already placed")
self.status = "placed"
self.raise_(OrderPlaced(
order_id=self.order_id,
customer_id=self.customer_id,
product_id=self.product_id,
quantity=self.quantity,
total_amount=self.total_amount,
))
Follow the patterns in event-handler.
Key points for this workflow:
part_of=AggregateClass when the class is in scope. A string reference also works and resolves at init@handle(EventClass) decorator on handler methods@domain.event_handler(part_of=Order) for an Order eventcurrent_domain.process(...). The command is part_of the target aggregate, and the target's command handler does the writeThe cross-aggregate example below needs a target aggregate. Here Inventory tracks stock per product:
@domain.aggregate
class Inventory:
product_id: Identifier(required=True)
in_stock: Integer(required=True)
applied_order_ids: List(content_type=String)
def reduce_stock(self, order_id: str, quantity: int):
if quantity > self.in_stock:
raise ValueError(f"Insufficient stock: have {self.in_stock}, need {quantity}")
self.in_stock -= quantity
self.applied_order_ids = [*self.applied_order_ids, order_id]
# Same-aggregate handler
@domain.event_handler(part_of=Order)
class OrderEventHandler:
@handle(OrderPlaced)
def on_order_placed(self, event: OrderPlaced):
order = domain.repository_for(Order).get(event.order_id)
order.confirmation_number = f"CONF-{event.order_id}"
domain.repository_for(Order).add(order)
# Cross-aggregate handler: still in Order's cluster, hands off with a command
@domain.event_handler(part_of=Order)
class InventorySyncHandler:
@handle(OrderPlaced)
def on_order_placed(self, event: OrderPlaced):
current_domain.process(
ReduceStock(
order_id=event.order_id,
product_id=event.product_id,
quantity=event.quantity,
)
)
Follow the patterns in command and command-handler.
The command is part_of the target aggregate. It carries the source's id (here order_id), so a redelivered event reissues the same command. Reducing stock is an update, so Inventory keeps a list of the order ids it has applied, and its command handler returns early for one it has seen:
@domain.command(part_of="Inventory")
class ReduceStock:
order_id: Identifier(required=True)
product_id: Identifier(required=True)
quantity: Integer(required=True)
@domain.command_handler(part_of=Inventory)
class InventoryCommandHandler:
@handle(ReduceStock)
def reduce_stock(self, command: ReduceStock):
repo = current_domain.repository_for(Inventory)
inventory = repo.find_by(product_id=command.product_id)
if command.order_id in inventory.applied_order_ids:
return # already applied; a redelivered event must not reduce twice
inventory.reduce_stock(command.order_id, command.quantity)
repo.add(inventory)
Inventory.reduce_stock lowers the stock and appends the order id to applied_order_ids: List(content_type=String). When the command creates an aggregate, give the new aggregate an id taken from the event and skip the add when repository.get finds it (see split-aggregate). For a flow with several causally dependent steps, use a process manager.
For synchronous processing (recommended for testing and simple flows):
domain.config["event_processing"] = "sync"
domain.config["command_processing"] = "sync" # for the cross-aggregate command
For asynchronous processing (production with message broker):
domain.config["event_processing"] = "async"
domain.config["command_processing"] = "async"
Colocate event definitions with their aggregate. Event handlers live with the aggregate that owns the event. Commands and command handlers live with the aggregate they change:
src/myapp/order/
├── order.py # Aggregate (with raise_() calls)
├── order_placed.py # OrderPlaced event + same-aggregate handler (if any)
├── handle_order_placed.py # Cross-aggregate handler (issues ReduceStock)
├── order_shipped.py # OrderShipped event
└── order_api.py # API endpoints
src/myapp/inventory/
├── inventory.py # Inventory aggregate
├── reduce_stock.py # ReduceStock command + its command handler
└── inventory_api.py
Naming conventions:
<event_name_snake>.py (e.g., order_placed.py)handle_<event_name_snake>.py in the source aggregate's folder<command_name_snake>.py in the target aggregate's folderWhen the aggregate already has an event handler, add the new @handle method to the existing handler class. Multiple @handle methods in one handler class is fine.
@domain.event(part_of="Order")
class OrderShipped:
order_id: Identifier(required=True)
@domain.event_handler(part_of=Order)
class OrderEventHandler:
@handle(OrderPlaced)
def on_order_placed(self, event: OrderPlaced): ...
@handle(OrderShipped)
def on_order_shipped(self, event: OrderShipped):
order = domain.repository_for(Order).get(event.order_id)
order.tracking_number = f"TRACK-{event.order_id}"
domain.repository_for(Order).add(order)
part_of="String": Handlers usually pass the class, part_of=ClassRef, and a string works on a handler tooOrderPlaced), commands are imperative (PlaceOrder)self.raise_() after the aggregate state is updated. An event-sourced aggregate is the exception: it raises the event first, and @apply changes the state (see the event-sourced-aggregate skill)domain.config["event_processing"] = "sync"self.raise_() within aggregate methodspart_of the target aggregate and reacts to the source's event is what check reports as EVENT_HANDLER_FOREIGN_EVENT. Keep the handler in the source's cluster and issue a commanduuid4() per delivery writes the change twice. Take the id from the eventcheck and resolve what it reportsassets/add_event_cross_aggregate.py (opens in a new tab)assets/add_event_multiple_events.py (opens in a new tab)assets/add_event_same_aggregate.py (opens in a new tab)references/cross-aggregate-flow.md (opens in a new tab)references/multiple-events-flow.md (opens in a new tab)references/same-aggregate-flow.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub proteanhq/protean --plugin protean39 skills in this plugin
/add-commandAdd a complete command flow to an existing aggregate. It creates a command class, a FastAPI API endpoint, and a command handler with repository logic. This is the primary workflow for adding write operations to a Protean domain. Use when the user wants to "add a command", "add an action", "add an operation", "expose a write endpoint", "create a command flow", "wire up a POST endpoint", "add a new operation to an aggregate", or describes an action like "I want users to be able to [verb] a [thing]" (e.g., "place an order", "register a user", "cancel a reservation"). This workflow composes the command, command-handler, and api-endpoint element skills./add-domain-service-flowBuild a domain service flow in Protean for business logic that spans two or more aggregates. Domain services are stateless, encapsulate cross-aggregate business rules, and run pre/post invariants for validation. They are used when business logic doesn't naturally belong to a single aggregate. Wire them into command handlers or application services for persistence. Use when the user asks to "add a domain service", "implement cross-aggregate logic", "coordinate multiple aggregates", "add a business operation spanning aggregates", "validate across aggregates", or when they describe scenarios like "placing an order checks inventory and reserves stock", "transferring funds between accounts", "scheduling involves both resource and calendar".Other plugins' skills for the same job