/protean:extract-bounded-contextfrom protean
Splits a Protean Domain into two bounded contexts by extracting a set of aggregates into a second Domain and wiring them via domain events with an anti-corruption layer. Use when a domain has grown two distinct languages or has circular cluster dependencies.
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.
In Protean each Domain is a bounded context. When one domain grows to hold two
languages, that is a sign it holds two contexts that belong apart. This skill
takes a set of aggregates out of one Domain into a second Domain and wires
the two by domain events across the boundary.
It builds on the element skills add-subscriber-flow for the anti-corruption layer, event for the cross-context event, and aggregate for the aggregates on each side.
check reports the smells that push toward the split:
CIRCULAR_CLUSTER_DEPENDENCY: two aggregate clusters hold identity references
at each other, forming a cycle. Neither can be loaded or changed on its own.CROSS_AGGREGATE_REFERENCE: a Reference from one aggregate reaches across
what should be a boundary into a different aggregate's root.A handful of these between two groups of aggregates is a seam. The seam-detection reference covers the signals and how to sort each aggregate onto its side.
One domain holds both a sales context and a fulfilment context. Order (sales)
points at its Shipment and Shipment (fulfilment) points back at its Order,
both by Reference. Those two cross-cluster references form a cycle, so check
reports CIRCULAR_CLUSTER_DEPENDENCY on both clusters.
extract_bounded_context_before.py is
the tangled starting point. extract_bounded_context_after.py
is the extraction: two Domain objects that talk by a published event across the
seam, with the cycle gone.
Run check and read the CIRCULAR_CLUSTER_DEPENDENCY and
CROSS_AGGREGATE_REFERENCE findings. They name the aggregates that reference
each other across the boundary. Group the aggregates by the language they speak:
Order and Payment are sales; Shipment and Manifest are fulfilment. Each
reference that crosses the seam is a line in the rewrite work list. See the
seam-detection reference.
The original domain keeps the aggregates that stay behind. Here that is sales,
and Order no longer holds a Reference to Shipment:
sales = Domain(name="Sales")
@sales.aggregate
class Order:
customer_id = String(required=True, max_length=50)
address = String(required=True, max_length=200)
status = String(default="placed", max_length=20)
def place(self) -> None:
self.status = "placed"
self.raise_(
OrderPlaced(
order_id=self.id,
customer_id=self.customer_id,
address=self.address,
)
)
Create a second Domain for the aggregates you are extracting, and move them and
their events, commands, and handlers into it:
fulfilment = Domain(name="Fulfilment")
@fulfilment.aggregate
class Shipment:
order_id = Identifier(required=True)
address = String(required=True, max_length=200)
status = String(default="pending", max_length=20)
@fulfilment.command(part_of="Shipment")
class CreateShipment:
order_id = Identifier(required=True)
address = String(required=True)
@fulfilment.command_handler(part_of=Shipment)
class ShipmentCommandHandler:
@handle(CreateShipment)
def create_shipment(self, command: CreateShipment) -> None:
shipment = Shipment(order_id=command.order_id, address=command.address)
fulfilment.repository_for(Shipment).add(shipment)
The moved aggregate holds the far side by its identifier (order_id), a plain
Identifier field. That identity is what replaces the Reference that used to
cross the seam.
Replace each cross-seam reference with a domain event. The owning context publishes the event as part of its published language, and turns the outbox on so the event actually leaves the context:
sales.config["server"]["default_subscription_type"] = "stream"
sales.config["brokers"]["events"] = {"provider": "inline"}
sales.config["outbox"]["external_brokers"] = ["events"]
@sales.event(part_of="Order", published=True)
class OrderPlaced:
order_id = Identifier(required=True)
customer_id = String(required=True)
address = String(required=True)
Broker names are local to a Domain, so the consuming context declares the
broker for itself too. Without this, sales dispatches to its events broker
while fulfilment listens on its own default and nothing arrives:
fulfilment.config["brokers"]["events"] = {"provider": "inline"}
Deployed, both entries name the same broker endpoint (the same Redis, say) and
the outbox relay carries the event between the contexts. inline is demo-only:
each Domain builds its own InlineBroker with its own messages and
subscribers, so two inline entries are two separate objects. That is why the
worked example relays the message across by hand.
The other context consumes the event through a subscriber that translates it into
its own command. The subscriber is the anti-corruption layer. It binds to that
shared broker, listens on the publishing aggregate's stream_category, and finds
the fields under payload["data"]:
# Fulfilment names the sales message type as a string. Importing `OrderPlaced`
# would restore the dependency the extraction just removed, and the class is not
# importable at all once the contexts live in separate processes.
SALES_ORDER_PLACED = "Sales.OrderPlaced.v1"
@fulfilment.subscriber(stream="sales::order", broker="events")
class OrderPlacedSubscriber:
def __call__(self, payload: dict) -> None:
if payload["metadata"]["headers"]["type"] != SALES_ORDER_PLACED:
return
data = payload["data"]
fulfilment.process(
CreateShipment(order_id=data["order_id"], address=data["address"])
)
Broker delivery is at-least-once, so a redelivered OrderPlaced runs the
subscriber again and ShipmentCommandHandler opens a second shipment for the same
order.
The event-integration reference covers
published=True, the outbox and outbox.external_brokers wiring, the stream and
envelope the outbox delivers on, guarding against redelivery, and holding the far
side by identity in full.
Fulfilment now holds the order by its identifier (order_id) and learns about
orders from sales events. Sales holds no shipment identifier at all. Neither
domain holds a Reference into the other. The cycle is gone, so check reports neither
CIRCULAR_CLUSTER_DEPENDENCY nor CROSS_AGGREGATE_REFERENCE on either domain.
check and
resolve what it reports, including any CIRCULAR_CLUSTER_DEPENDENCY.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"./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