/protean:projectorfrom protean
Defines Protean projectors that maintain read-optimized projections by listening to domain events. Use for CQRS read-side models, denormalized views, and cross-aggregate query data.
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 projector keeps one projection up to date: it listens to domain events and writes the projection's records. This skill defines projectors: event sources, options and redelivery.
| Aspect | Event Handler | Projector |
|---|---|---|
| Purpose | Orchestrate side effects (notifications, syncing) | Maintain read-optimized projections |
| Association | part_of=Aggregate | projector_for=Projection |
| Decorator | @handle(EventClass) | @on(EventClass) (alias for @handle) |
| Target | Updates aggregates | Updates projections (read models) |
| Event source | stream_category | aggregates or stream_categories |
| Import | from protean import handle | from protean.core.projector import on |
from protean import Domain
from protean.core.projector import on
from protean.fields import Identifier, Integer, String
domain = Domain()
domain.config["event_processing"] = "sync"
@domain.event(part_of="Product")
class ProductAdded:
product_id: Identifier(required=True)
name: String(required=True)
stock_quantity: Integer(required=True)
@domain.aggregate
class Product:
name: String(required=True)
stock_quantity: Integer(default=0)
@classmethod
def create(cls, name, stock_quantity=0):
product = cls(name=name, stock_quantity=stock_quantity)
product.raise_(ProductAdded(
product_id=product.id, name=name, stock_quantity=stock_quantity
))
return product
@domain.projection
class ProductInventory:
product_id: Identifier(identifier=True, required=True)
name: String(required=True)
stock_quantity: Integer(default=0)
@domain.projector(projector_for=ProductInventory, aggregates=[Product])
class ProductInventoryProjector:
@on(ProductAdded)
def on_product_added(self, event: ProductAdded):
repo = domain.repository_for(ProductInventory)
inventory = ProductInventory(
product_id=event.product_id,
name=event.name,
stock_quantity=event.stock_quantity,
)
repo.add(inventory)
@domain.projector(projector_for=MyProjection, ...)aggregates=[Product] or stream_categories=[Product.meta_.stream_category]. A stream category is domain-qualified (<domain>::<aggregate>, such as inventory::product), so a bare "product" never matches. Derive it from the aggregate@on(EventClass), imported with from protean.core.projector import on (not from protean directly)def method_name(self, event: EventClass)Reference and Associations (HasOne/HasMany) are not allowed; basic field types and ValueObject fields are allowed (a ValueObject is stored as flattened shadow fields)idempotent=True (see Projector options)| Option | Purpose | Required |
|---|---|---|
projector_for | The projection class this projector maintains | Yes |
aggregates | List of aggregate classes whose events to listen to | Yes (unless stream_categories provided) |
stream_categories | List of stream category names to listen to | Yes (unless aggregates provided) |
retries | Max retry attempts on transient exceptions; overrides server.transient_retry | No |
backoff | Retry delay strategy: "exponential", "linear", or "fixed" | No |
retry_exceptions | Exception types (classes or dotted paths) treated as transient for retry | No |
sequential_by | Field name on every handled event; events in the same stream category that share its value are processed one at a time (needs a partitioning broker and a stream subscription) | No |
subscription_type | "stream" or "event_store" | No |
subscription_profile | "production", "fast", "batch", "debug", "projection" | No |
subscription_config | Custom config dict (messages_per_tick, max_retries, etc.) | No |
idempotent | When True, each handler records a delivery marker in the same UnitOfWork as its write, so a redelivered event applies exactly once on a relational provider. On the in-memory provider the marker only skips a sequential redelivery; it is neither atomic nor concurrency-safe. For a cache-backed projection the option is a no-op, so the handler must write an idempotent upsert | No |
suppress_checks | Diagnostic codes to suppress for this projector | No |
@domain.event(part_of="Product")
class StockAdjusted:
product_id: Identifier(required=True)
new_stock_quantity: Integer(required=True)
@domain.projector(projector_for=ProductInventory, aggregates=[Product])
class ProductInventoryProjector:
@on(ProductAdded)
def on_product_added(self, event: ProductAdded):
repo = domain.repository_for(ProductInventory)
inventory = ProductInventory(
product_id=event.product_id, name=event.name,
stock_quantity=event.stock_quantity,
)
repo.add(inventory)
@on(StockAdjusted)
def on_stock_adjusted(self, event: StockAdjusted):
repo = domain.repository_for(ProductInventory)
inventory = repo.get(event.product_id)
inventory.stock_quantity = event.new_stock_quantity
repo.add(inventory)
from protean.fields import Decimal
@domain.aggregate
class User:
name: String(required=True)
@domain.aggregate
class Transaction:
user_id: Identifier(required=True)
amount: Decimal(precision=19, scale=4, required=True)
@domain.event(part_of=User)
class Registered:
user_id: Identifier(required=True)
name: String(required=True)
@domain.event(part_of=Transaction)
class Transacted:
user_id: Identifier(required=True)
amount: Decimal(precision=19, scale=4, required=True)
@domain.projection
class Balances:
user_id: Identifier(identifier=True, required=True)
name: String()
balance: Decimal(precision=19, scale=4, default=0)
@domain.projector(
projector_for=Balances,
aggregates=[User, Transaction],
)
class TransactionProjector:
@on(Registered)
def on_registered(self, event: Registered):
balance = Balances(user_id=event.user_id, name=event.name, balance=0)
domain.repository_for(Balances).add(balance)
@on(Transacted)
def on_transacted(self, event: Transacted):
balance = domain.repository_for(Balances).get(event.user_id)
balance.balance += event.amount
domain.repository_for(Balances).add(balance)
A redelivered Transacted adds the amount twice here, and a redelivered Registered fails because the record exists. Writing on_registered as an upsert (get the record, create it only if missing) fixes the second case. An upsert does not fix the first, because adding to a balance is not safe to repeat. Set idempotent=True on the projector (see the options table below) to have the framework skip an event it has already handled.
@domain.projection
class ProductCatalog:
product_id: Identifier(identifier=True, required=True)
name: String(required=True)
@domain.projector(projector_for=ProductInventory, aggregates=[Product])
class ProductInventoryProjector:
@on(ProductAdded)
def on_product_added(self, event: ProductAdded):
# Populate detailed inventory projection
...
@domain.projector(projector_for=ProductCatalog, aggregates=[Product])
class ProductCatalogProjector:
@on(ProductAdded)
def on_product_added(self, event: ProductAdded):
# Populate simplified catalog projection
...
@domain.projection
class SystemMetrics:
metric: String(identifier=True)
count: Integer(default=0)
@domain.projector(
projector_for=SystemMetrics,
stream_categories=[
User.meta_.stream_category, # "<domain>::user"
Transaction.meta_.stream_category, # "<domain>::transaction"
],
)
class SystemMetricsProjector:
@on(Registered)
def on_registered(self, event):
...
Read the category from meta_.stream_category after the aggregate is registered. Registration prefixes it with the domain name.
from protean import handle # Wrong import for projectors
@domain.projector(projector_for=ProductInventory, aggregates=[Product])
class MyProjector:
@handle(ProductAdded) # Works but not idiomatic
def on_product_added(self, event):
...
Instead: Use @on from protean.core.projector. It is an alias for @handle and reads better in a projector.
# fragment
@domain.projector(projector_for=ProductInventory, aggregates=[Product])
class MyProjector:
@on(ProductRenamed) # Wrong! ProductRenamed was renamed/removed
def on_product_renamed(self, event):
...
A projector @on handler wired to an event the domain does not register can
never be dispatched, usually a stale reference after a rename or removal.
check reports this as PROJECTOR_HANDLES_ORPHANED_EVENT. Register the
event, or remove the handler for the orphaned type.
# fragment
class MyProjection: # Wrong! Not registered with domain
product_id: Identifier(identifier=True)
@domain.projector(projector_for=MyProjection, aggregates=[Product])
class MyProjector:
pass
Instead: Register projection with @domain.projection decorator
event: Events are the input to projectorsaggregate: Aggregates produce the events that projectors consumeevent-handler: Generic event handlers (compare/contrast with projectors)projection: Projections are the output that projectors maintaincheck and resolve what it reportsassets/projector_cross_aggregate.py (opens in a new tab)assets/projector_error_handling.py (opens in a new tab)assets/projector_multiple_events.py (opens in a new tab)assets/projector_multiple_projectors.py (opens in a new tab)assets/projector_single_aggregate.py (opens in a new tab)references/anti-patterns.md (opens in a new tab)references/cross-aggregate.md (opens in a new tab)references/error-handling.md (opens in a new tab)references/multiple-projectors.md (opens in a new tab)references/single-aggregate.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
39 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".npx claudepluginhub proteanhq/protean --plugin proteanOther plugins' skills for the same job