/protean:add-commandfrom protean
Generates a complete command flow for a Protean aggregate: command class, FastAPI endpoint, and command handler with repository logic. Use when adding write operations like 'place an order' or 'register a user'.
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 command flow to an existing aggregate. It creates three artifacts that work together:
PlaceOrder)| Artifact | Role | File location |
|---|---|---|
| Command class | Carries intent data | <aggregate_folder>/<verb>_<noun>.py |
| Command Handler | Loads/creates aggregate, calls methods, persists | Same file as command |
| API Endpoint | Translates HTTP to command, calls domain.process() | <aggregate_folder>/<noun>_api.py |
Before generating, ensure you know the following. If any item is unknown, ask the user before proceeding.
Follow the patterns in command.
Key points for this workflow:
PlaceOrder, RegisterUser, CancelReservationpart_of="AggregateName" (string, not class reference)HasOne/HasMany@domain.command(part_of="Order")
class PlaceOrder:
order_id: Identifier(required=True)
customer_id: String(required=True)
total_amount: Decimal(precision=19, scale=4, required=True)
Follow the patterns in command-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(CommandClass) decorator on handler methodsdomain.repository_for(Aggregate).add()domain.repository_for(Aggregate).get(id), call method, persistThe handler works on an existing Order aggregate like this one:
from decimal import Decimal as D
@domain.aggregate
class Order:
order_id: Identifier(identifier=True)
customer_id: String(required=True)
total_amount: Decimal(precision=19, scale=4)
status: String(default="draft")
cancellation_reason: String()
def place(self, total_amount: D):
self.total_amount = total_amount
self.status = "placed"
def cancel(self, reason: str):
self.status = "cancelled"
self.cancellation_reason = reason
@domain.command_handler(part_of=Order)
class OrderCommandHandler:
@handle(PlaceOrder)
def handle_place_order(self, command: PlaceOrder):
order = Order(
order_id=command.order_id,
customer_id=command.customer_id,
)
order.place(total_amount=command.total_amount)
domain.repository_for(Order).add(order)
return order.order_id
Follow the patterns in api-endpoint.
Key points for this workflow:
domain.init() at app startup (the lifespan hook), after every registration and before the first requestcurrent_domain.process(command, asynchronous=False) for synchronous processingfrom contextlib import asynccontextmanager
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from protean import current_domain
@asynccontextmanager
async def lifespan(app: FastAPI):
# Wire the commands and handlers once, before the app takes requests
domain.init()
try:
yield
finally:
# Release the adapter connections on shutdown, even after an error
domain.close()
app = FastAPI(lifespan=lifespan)
@app.middleware("http")
async def domain_context_middleware(request: Request, call_next):
with domain.domain_context():
return await call_next(request)
@app.post("/orders", status_code=201)
async def create_order(request: Request):
payload = await request.json()
command = PlaceOrder(
order_id=payload["order_id"],
customer_id=payload["customer_id"],
total_amount=payload["total_amount"],
)
result = current_domain.process(command, asynchronous=False)
return JSONResponse(status_code=201, content={"order_id": result})
Colocate command + handler in a single file named after the action. Place API endpoints in a separate <aggregate>_api.py file:
src/myapp/order/
├── order.py # Aggregate + entities + VOs
├── place_order.py # PlaceOrder command + OrderCommandHandler
├── cancel_order.py # CancelOrder command (add to existing handler or new file)
└── order_api.py # All API endpoints for Order
When the aggregate already has a command handler, add the new @handle method to the existing handler class rather than creating a second one. Protean enforces one handler per command but allows multiple @handle methods in one handler class.
# In place_order.py - add new command and handler method
@domain.command(part_of="Order")
class CancelOrder:
order_id: Identifier(required=True)
reason: String(required=True)
# Add to existing handler
@domain.command_handler(part_of=Order)
class OrderCommandHandler:
@handle(PlaceOrder)
def handle_place_order(self, command): ...
@handle(CancelOrder)
def handle_cancel(self, command: CancelOrder):
order = domain.repository_for(Order).get(command.order_id)
order.cancel(reason=command.reason)
domain.repository_for(Order).add(order)
part_of="String": Handlers usually pass the class, part_of=ClassRef, and a string works on a handler too@handle methods in one handler is finedomain.process(). No repository access, no business logiccurrent_domain.process(): Never call a handler directlycurrent_domain is not availableasynchronous=Falsecheck and resolve what it reportsassets/add_command_create_flow.py (opens in a new tab)assets/add_command_multiple_commands.py (opens in a new tab)assets/add_command_update_flow.py (opens in a new tab)references/create-aggregate-flow.md (opens in a new tab)references/multiple-commands-flow.md (opens in a new tab)references/update-aggregate-flow.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
protean, command-flow, aggregate, write-operations, fastapi-endpoint
npx claudepluginhub proteanhq/protean --plugin protean39 skills in this plugin
/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"./add-subscriber-flowBuild a complete external integration flow in Protean using subscribers. Subscribers consume messages from external systems via broker streams and translate them into domain actions using the anti-corruption layer (ACL) pattern. Use when the user asks to "add an external integration", "consume external events", "handle webhook events", "integrate with an external system", "add a subscriber flow", "build an anti-corruption layer", "translate external messages", "process broker messages", or when they describe scenarios like "when the payment gateway confirms", "when the ERP syncs users", "react to external system notifications".Other plugins' skills for the same job