/protean:eventfrom protean
Defines Protean domain events as immutable facts representing state changes. Use for event sourcing, CQRS, or recording business domain occurrences like OrderPlaced or CustomerRegistered.
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.
An event records a change that has happened to one aggregate, so other parts of the system can react to it. This skill defines events: fields, versioning, and how aggregates raise them.
An event is defined using the @domain.event(part_of="...") decorator:
from protean import Domain
from protean.fields import String, DateTime
domain = Domain()
@domain.event(part_of="Order")
class OrderPlaced:
__version__ = 1
order_id: String(required=True, identifier=True)
customer_id: String(required=True)
placed_at: DateTime(required=True)
part_of parameter with the aggregate name. A process manager's own events name the process manager. Never name an entity: an entity raises its events through the aggregateOrderPlaced, not PlaceOrder__version__ class attribute for schema evolution (defaults to 1)self.raise_() method within aggregate methodsDelta events capture incremental changes to aggregate state. Most events are delta events.
@domain.event(part_of="Order")
class OrderPlaced:
order_id: String(required=True, identifier=True)
customer_id: String(required=True)
total_amount: Decimal(precision=19, scale=4, required=True)
Fact events contain complete aggregate state at a point in time (Event-carried State Transfer pattern). You do not write a fact event class. Turn them on with fact_events=True, and Protean generates an <Aggregate>FactEvent class from the aggregate's fields. For Order, the class is OrderFactEvent.
@domain.aggregate(fact_events=True)
class Order:
customer_id: String(required=True)
status: String(default="draft")
The repository writes a fact event each time it saves a new or changed aggregate. Saving an unchanged aggregate writes none. The event goes to the <stream_category>-fact-<id> stream. Your code never raises it: the repository raises it on the aggregate as it saves, and the unit of work stores it on commit.
domain.init(traverse=False)
with domain.domain_context():
order = Order(customer_id="CUST-123")
domain.repository_for(Order).add(order)
stream = f"{Order.meta_.stream_category}-fact-{order.id}"
fact = domain.event_store.store.read_last_message(stream).to_domain_object()
print(type(fact).__name__) # OrderFactEvent
print(fact.id == order.id, fact.customer_id, fact.status) # True CUST-123 draft
Events can contain value objects for complex immutable data:
@domain.value_object
class Money:
amount: Decimal(precision=19, scale=4, required=True)
currency: String(max_length=3, default="USD")
@domain.event(part_of="Order")
class OrderPlaced:
__version__ = 1
order_id: String(required=True, identifier=True)
customer_id: String(required=True)
total = ValueObject(Money, required=True)
placed_at: DateTime(required=True)
Use __version__ for schema evolution:
@domain.event(part_of="Order")
class OrderPlaced:
__version__ = 1
order_id: String(required=True, identifier=True)
customer_id: String(required=True)
# Later, when schema evolves
@domain.event(part_of="Order")
class OrderPlaced:
__version__ = 2
order_id: String(required=True, identifier=True)
customer_id: String(required=True)
total = ValueObject(Money) # New field in v2
Events are raised within aggregate methods using self.raise_():
from datetime import datetime, timezone
@domain.aggregate
class Order:
order_id: String(required=True, identifier=True)
customer_id: String(required=True)
status: String(default="draft")
total = ValueObject(Money)
def place(self):
if self.status != "draft":
raise ValueError("Order already placed")
self.status = "placed"
placed_at = datetime.now(timezone.utc)
# Raise event - automatically associated with this aggregate instance
self.raise_(OrderPlaced(
order_id=self.order_id,
customer_id=self.customer_id,
total=self.total,
placed_at=placed_at
))
This aggregate stores its state, so the method changes the state first and then raises the event. An event-sourced aggregate works the other way. The business method raises the event, and an @apply method changes the state. See the event-sourced-aggregate skill.
# fragment
@domain.event(part_of="Order")
class OrderPlaced:
order_entity = HasOne(OrderEntity) # Wrong! Events can't contain entities
✅ Instead: Only fields and value objects, as in With Value Objects.
@domain.event(part_of="Order")
class OrderPlaced:
# Including entire customer object when only ID is needed
customer_name: String()
customer_email: String()
customer_address: String()
customer_phone: String()
✅ Instead: Only necessary information
@domain.event(part_of="Order")
class OrderPlaced:
customer_id: String(required=True) # Just the ID
# fragment
event = OrderPlaced(order_id="123", customer_id="456")
event.order_id = "789" # Wrong! Events are immutable
✅ Instead: Events are immutable facts
Assigning to a field of an event raises IncorrectUsageError. To record a different fact, raise a new event.
from protean.exceptions import IncorrectUsageError
@domain.event(part_of="Order")
class OrderPlaced:
order_id: String(required=True, identifier=True)
customer_id: String(required=True)
domain.init(traverse=False)
with domain.domain_context():
event = OrderPlaced(order_id="123", customer_id="456")
try:
event.order_id = "789"
except IncorrectUsageError as exc:
print(exc) # Event/Command Objects are immutable and cannot be modified once created
check reportscheck inspects your events and reports these diagnostics:
EVENT_NOT_PAST_TENSE: the event is named as a gerund (OrderPlacing), so it describes an in-flight action and reads like a command. Rename it to the past tense (OrderPlaced).EVENT_WITHOUT_DATA: the event declares no fields, so it carries nothing about the state change. Add fields capturing what changed, or confirm the event is intentionally a bare signal.UNRAISED_EVENT: no aggregate or entity method raises the event. The check reads only aggregate and entity method bodies, so an event raised from a command handler, subscriber, or module-level factory still shows here. Raise it from the aggregate or entity method that makes the change it records, or remove the event if nothing produces it.UNHANDLED_EVENT: the event has no registered handler, projector, or process manager, so nothing reacts to it. Register a consumer for it, or mark it published=True if it is meant only for external subscribers.fact_events=Trueaggregate: Events are always part of aggregatesvalue-object: Events can contain value objectsevent-handler: How events are consumed and processedevent-sourced-aggregate: Using events as the source of truthcheck and resolve what it reportsassets/event_fact.py (opens in a new tab)assets/event_simple.py (opens in a new tab)assets/event_versioning.py (opens in a new tab)assets/event_with_value_object.py (opens in a new tab)assets/raising_events.py (opens in a new tab)references/anti-patterns.md (opens in a new tab)references/delta-events.md (opens in a new tab)references/event-versioning.md (opens in a new tab)references/fact-events.md (opens in a new tab)references/raising-events.md (opens in a new tab)references/with-value-objects.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