/protean:add-subscriber-flowfrom protean
Builds external integration flows in Protean using subscribers that consume broker messages and translate them into domain actions via the anti-corruption layer pattern.
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 subscriber flow bridges external systems with your domain. It consumes raw messages from broker streams and translates them into domain-native commands or aggregate operations.
| Component | Purpose | Decorator |
|---|---|---|
| Subscriber | Consume external broker messages | @domain.subscriber(stream=...) |
| Anti-corruption translation | Convert external format to domain language | Methods on subscriber |
| Command (optional) | Domain-native command from external data | @domain.command(part_of=...) |
| Command Handler (optional) | Process the translated command | @domain.command_handler(part_of=...) |
| Aggregate | Domain entity being updated | @domain.aggregate |
Before building a subscriber flow, understand:
"payment_gateway", "erp_events")A subscriber listens to a named broker stream. It implements __call__ with a payload: dict parameter.
@domain.subscriber(stream="payment_gateway")
class PaymentSubscriber:
def __call__(self, payload: dict) -> None:
# payload is always a raw dict from the external broker
event_type = payload.get("type")
if event_type == "payment.confirmed":
self._handle_payment_confirmed(payload["data"])
def _handle_payment_confirmed(self, data: dict) -> None:
# Translate and act on the external message
...
Key rules for subscribers (see subscriber):
stream parameter is required: it names the broker stream to listen to__call__(self, payload: dict): Only method to implementdict: no typed events, no Protean objectsThe subscriber translates external data formats into domain language. This is the key DDD concept: the Anti-Corruption Layer (ACL).
# fragment
def _handle_payment_confirmed(self, data: dict) -> None:
# External format (camelCase, external IDs):
# {"orderId": "ext-123", "amountPaid": 99.99, "paymentMethod": "card"}
#
# Domain format (snake_case, domain language):
# ConfirmPayment(order_id="ext-123", amount=99.99)
command = ConfirmPayment(
order_id=data["orderId"],
amount=data["amountPaid"],
)
domain.process(command)
Pattern A: Subscriber → Command → Handler → Aggregate
For complex flows where the domain action warrants a full command flow:
@domain.subscriber(stream="erp_events")
class ERPSubscriber:
def __call__(self, payload: dict) -> None:
if payload["type"] == "user.created":
command = RegisterCustomer(
name=f"{payload['firstName']} {payload['lastName']}",
email=payload["email"],
)
domain.process(command)
Pattern B: Subscriber → Aggregate directly
For simpler flows where the subscriber can directly update the aggregate:
@domain.aggregate
class Order:
status: String(default="PENDING")
def mark_paid(self) -> None:
self.status = "PAID"
@domain.subscriber(stream="payment_gateway")
class PaymentSubscriber:
def __call__(self, payload: dict) -> None:
if payload["status"] == "SUCCESS":
order = domain.repository_for(Order).get(payload["order_id"])
order.mark_paid()
domain.repository_for(Order).add(order)
domain.config["message_processing"] = "sync"
domain.config["command_processing"] = "sync" # if dispatching commands
In tests, use the broker to simulate external messages. Initialize the domain first, and publish inside a domain context:
domain.init(traverse=False)
with domain.domain_context():
domain.repository_for(Order).add(Order(id="ORD-001"))
domain.repository_for(Order).add(Order(id="ORD-002"))
# Publish to the broker stream (triggers the subscriber in sync mode)
domain.brokers["default"].publish(
"payment_gateway",
{"order_id": "ORD-001", "status": "SUCCESS"},
)
domain.brokers["default"].publish(
"payment_gateway",
{"order_id": "ORD-002", "status": "FAILED"},
)
assert domain.repository_for(Order).get("ORD-001").status == "PAID"
assert domain.repository_for(Order).get("ORD-002").status == "PENDING"
| External System | Typical Format | Translation Needed |
|---|---|---|
| REST webhook | camelCase JSON | Field renaming, flatten nested |
| ERP system | Custom schema with IDs | Map IDs, combine fields |
| Payment gateway | Status codes | Map codes to domain states |
| Message queue | Envelope + body | Unwrap envelope, parse body |
# fragment
# Wrong! Raw external payload pushed into domain logic
def __call__(self, payload: dict) -> None:
order = domain.repository_for(Order).get(payload["orderId"])
order.apply(payload) # camelCase + external IDs leak into the aggregate
Instead: translate at the subscriber (the ACL) into domain language first, then act.
# fragment
# Wrong! Domain rules enforced in the ACL
def __call__(self, payload: dict) -> None:
if payload["amountPaid"] >= order.total: # rule belongs on the aggregate
order.mark_paid()
Instead: the subscriber only translates and delegates; rules live on the aggregate or a command handler.
# fragment
# Wrong! Subscribers receive raw dicts, not typed events
def __call__(self, payload: PaymentConfirmed) -> None:
...
Instead: def __call__(self, payload: dict). It is always a raw dict from the broker.
# fragment
# Wrong! Nothing processes the published message
domain.brokers["default"].publish("payment_gateway", {"order_id": "O-1"})
assert order.is_paid # fails: subscriber never ran
Instead: set domain.config["message_processing"] = "sync" (and command_processing if you dispatch commands) in tests.
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".Other plugins' skills for the same job