/protean:add-use-casefrom protean
Builds a complete vertical slice in the Protean framework: command definition, handler, aggregate mutation, event raising, and event handler reaction. Use when adding a new feature or end-to-end command flow.
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.
A use case in Protean follows the command flow pattern. Each use case is a vertical slice through the architecture:
Command → Command Handler → Aggregate Method → Event → Event Handler
| Component | Purpose | Decorator |
|---|---|---|
| Command | Carries user intent and input data | @domain.command(part_of=...) |
| Command Handler | Receives command, orchestrates aggregate | @domain.command_handler(part_of=...) |
| Aggregate method | Mutates state, raises events | Method on @domain.aggregate |
| Event | Records what happened | @domain.event(part_of=...) |
| Event Handler | Reacts to what happened (side effects) | @domain.event_handler(part_of=...) |
Before building a use case, understand:
Commands are named as imperative verb phrases. They carry the data needed to perform the action. Use part_of to associate with the target aggregate.
@domain.command(part_of="Order")
class PlaceOrder:
order_id: Identifier(required=True)
customer_id: Identifier(required=True)
product_id: Identifier(required=True)
quantity: Integer(required=True, min_value=1)
Key rules for commands (see command):
PlaceOrder, ApproveRequest, CancelSubscriptionrequired=True on mandatory fields. A missing field raises protean.exceptions.ValidationError, and its .messages maps the field to its errors ({'order_id': ['is required']})Events record what happened after the command was processed. Named in past tense.
@domain.event(part_of="Order")
class OrderPlaced:
order_id: Identifier(required=True)
customer_id: Identifier(required=True)
product_id: Identifier(required=True)
quantity: Integer(required=True)
total_amount: Decimal(precision=19, scale=4, required=True)
The aggregate method encapsulates the business logic. It mutates state and raises the event.
@domain.aggregate
class Order:
customer_id: Identifier(required=True)
product_id: Identifier(required=True)
quantity: Integer(required=True)
total_amount: Decimal(precision=19, scale=4, default=0)
status: String(default="placed")
@classmethod
def place(cls, order_id, customer_id, product_id, quantity, unit_price):
"""Factory method for placing a new order."""
total = quantity * unit_price
order = cls(
id=order_id,
customer_id=customer_id,
product_id=product_id,
quantity=quantity,
total_amount=total,
)
order.raise_(OrderPlaced(
order_id=order.id,
customer_id=customer_id,
product_id=product_id,
quantity=quantity,
total_amount=total,
))
return order
The command handler receives the command, orchestrates the aggregate, and persists it. Use domain.process(command, asynchronous=False) for synchronous processing.
@domain.command_handler(part_of=Order)
class OrderCommandHandler:
@handle(PlaceOrder)
def handle_place_order(self, command: PlaceOrder):
order = Order.place(
order_id=command.order_id,
customer_id=command.customer_id,
product_id=command.product_id,
quantity=command.quantity,
unit_price=10.0, # In real code, look up from catalog
)
domain.repository_for(Order).add(order)
Key rules for command handlers (see command-handler):
part_of=AggregateClass when the class is in scope. A string reference also works and resolves at init@handle(CommandClass) decorator on each handler method(self, command: CommandClass)repository_for().add()Event handlers react to events for side effects: notifications, cross-aggregate updates, logging. The handler sits in the cluster that owns the event, here Order. To change another aggregate, it issues a command, and that aggregate's command handler does the write.
The handler below records a Notification, so define that aggregate first:
@domain.aggregate
class Notification:
message: String(required=True)
@domain.event_handler(part_of=Order)
class OrderNotificationHandler:
@handle(OrderPlaced)
def on_order_placed(self, event: OrderPlaced):
current_domain.process(
SendNotification(
notification_id=f"{event.order_id}:placed",
message=f"Order {event.order_id} placed for customer {event.customer_id}",
)
)
SendNotification is part_of="Notification". Events are delivered at least once, so the command carries an id built from the event, and Notification's command handler adds the notification only when repository.get(command.notification_id) raises ObjectNotFoundError. A handler that is part_of=Notification and reacts to OrderPlaced is what check reports as EVENT_HANDLER_FOREIGN_EVENT. For a flow with several causally dependent steps, use a process manager.
Initialize the domain, then process the command inside a domain context:
domain.init(traverse=False)
with domain.domain_context():
domain.process(
PlaceOrder(
order_id="ORD-001",
customer_id="CUST-001",
product_id="PROD-001",
quantity=3,
),
asynchronous=False,
)
The update and guard patterns below handle two more commands on Order:
@domain.command(part_of="Order")
class ApproveOrder:
order_id: Identifier(required=True)
approver_id: Identifier(required=True)
@domain.command(part_of="Order")
class CancelOrder:
order_id: Identifier(required=True)
requested_by_role: String(required=True)
reason: String()
Step 4 shows the create pattern: a factory method builds the aggregate and the handler adds it.
# Handler loads existing aggregate and calls method
@handle(ApproveOrder)
def handle_approve_order(self, command):
order = domain.repository_for(Order).get(command.order_id)
order.approve(approved_by=command.approver_id)
domain.repository_for(Order).add(order)
# Handler validates context before aggregate operation
@handle(CancelOrder)
def handle_cancel_order(self, command):
if command.requested_by_role not in ["admin", "customer"]:
raise ValidationError({"authorization": ["Not authorized"]})
order = domain.repository_for(Order).get(command.order_id)
order.cancel(reason=command.reason)
domain.repository_for(Order).add(order)
| Component | Convention | Example |
|---|---|---|
| Command | Imperative verb phrase | PlaceOrder, ApproveRequest |
| Event | Past tense of command | OrderPlaced, RequestApproved |
| Handler class | {Aggregate}CommandHandler | OrderCommandHandler |
| Handler method | handle_{command} | handle_place_order |
| Aggregate factory | cls.{verb}(...) | Order.place(...) |
| Aggregate method | self.{verb}(...) | order.approve(...) |
| Event handler class | Descriptive name | OrderNotificationHandler |
# fragment
# Wrong! Business rule computed in the handler
@handle(PlaceOrder)
def handle_place_order(self, command):
order = Order(customer_id=command.customer_id)
order.total_amount = command.quantity * 10.0 # rule leaks into the handler
order.status = "placed"
domain.repository_for(Order).add(order)
Instead: keep the rule in an aggregate method or factory, as in Step 4; the handler only orchestrates.
# fragment
# Wrong! State changes, but nothing is recorded or published
@classmethod
def place(cls, **kwargs):
order = cls(**kwargs)
return order # no raise_()
Instead: raise the past-tense event so the fact is recorded and handlers can react: order.raise_(OrderPlaced(...)).
# fragment
# Wrong! Two aggregates mutated and saved in one transaction
@handle(PlaceOrder)
def handle_place_order(self, command):
order = Order.place(...)
inventory.reduce(command.quantity)
domain.repository_for(Order).add(order)
domain.repository_for(Inventory).add(inventory) # cross-aggregate write
Instead: persist one aggregate. An event handler in its cluster reacts to the event and issues a command, and the other aggregate's command handler does the write (eventual consistency). To check a rule across aggregates before the change, use a domain service: it checks the rule, and the handler still persists one aggregate.
# fragment
# Wrong! Context/authorization baked into the domain model
def cancel(self, role):
if role != "admin":
raise ValidationError({"authorization": ["Not authorized"]})
Instead: guard authorization in the handler (Layer 4); keep the aggregate focused on invariants.
check and resolve what it reportsWhat SKILL.md sets; muted values are Claude Code's defaults
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"./add-eventAdd a complete event flow to an existing aggregate. It creates a domain event, adds or updates an aggregate method that raises the event via self.raise_(), and wires an event handler that processes the event and performs specified side effects (such as syncing state across aggregates, sending notifications, or triggering downstream processes). This is the primary workflow for adding reactive, event-driven behavior to a Protean domain. Use when the user wants to "add an event", "add a domain event", "add a reaction to a state change", "add a side effect", "create an event flow", "wire an event handler", "add event-driven behavior", "react to a state change", "sync aggregates on event", or describes something that happened or should happen (like "when an order is placed, reduce inventory", "after payment is confirmed, send a notification", "when a user registers, create a welcome email", "notify the warehouse when an order ships"). This workflow composes the event, aggregate, and event-handler element skills./add-fieldAdd fields to Protean domain elements (aggregates, entities, value objects). Guides you through selecting the right field type, configuring validations, and placing fields correctly. Use when the user asks to "add a field", "add an attribute", "add a property", "I need to store [data]", "add a new field to [aggregate/entity]", or describes data that needs to be tracked. Covers simple fields, association fields (HasOne, HasMany, ValueObject), field validation, custom validators, and choosing between field types for different use cases./add-read-modelBuild a complete read model in Protean, a projection populated by a projector that reacts to domain events. Covers single-aggregate projections (flattened view of one aggregate), cross-aggregate projections (combining data from multiple aggregates), and choosing between database-backed and cache-backed storage. Use when the user asks to "add a read model", "create a projection with projector", "build a query view", "add a CQRS read side", "create a denormalized view", "build a reporting view", "add a dashboard query model", or when they need to combine data from multiple aggregates into one queryable structure./add-saga-flowBuild a complete saga in Protean using a process manager that coordinates a multi-step flow across several aggregates. The saga reacts to domain events, issues commands to drive each aggregate forward, tracks its own state, and closes on a terminal handler with a compensating path for failures. Use when the user asks to "add a saga", "coordinate a multi-step process", "orchestrate a workflow across aggregates", "manage order fulfillment", "add a process manager flow", "compensate on failure", "roll back a distributed transaction", or when they describe a flow like "reserve stock, take payment, then ship, and undo the reservation if payment fails".Other plugins' skills for the same job