/protean:projectionfrom protean
Defines a Protean projection (read model) for CQRS read side. Creates denormalized, query-optimized data structures with basic field types and ValueObjects, stored in database or cache like Redis. Use when building read models, query views, or CQRS projections.
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 projection is a read model: a flat record shaped for one query and filled by a projector from domain events. This skill defines projections: fields, storage options and querying.
| Aspect | Aggregate | Projection |
|---|---|---|
| Purpose | Enforce business rules (write side) | Optimized for querying (read side) |
| Field types | All types (References, Associations, ValueObjects) | Basic types plus ValueObjects (flattened); no References or Associations |
| Data shape | Normalized, bounded by consistency boundary | Denormalized, flattened for query efficiency |
| Populated by | Commands and domain logic | Projectors consuming domain events |
| Storage | Database via repository | Database (provider) or cache |
| Decorator | @domain.aggregate | @domain.projection |
| Identity | Auto-generated id or custom | Must declare at least one identifier=True field |
from protean import Domain
from protean.fields import DateTime, Decimal, Identifier, Integer, String, Text
domain = Domain()
@domain.projection
class ProductInventory:
product_id: Identifier(identifier=True, required=True)
name: String(max_length=100, required=True)
description: Text()
price: Decimal(precision=19, scale=4, required=True)
stock_quantity: Integer(default=0)
last_updated: DateTime()
identifier=True; abstract projections are exempt from this checkReference and Associations (HasOne/HasMany) are rejected. Basic field types and ValueObject fields are allowed; a ValueObject is stored as flattened shadow fields (e.g. address_street, address_city)@domain.projection or domain.register(MyProjection)cache and provider are specified, cache takes precedenceNone or negative for unlimitedProductInventory -> product_inventory)Identifier/Auto fields: An identifier=True field declared as Identifier or Auto generates a value on creation if you do not supply one (a UUID by default), the same as aggregates. Auto(identifier=True, increment=True) is the exception: it stays None at construction and the DAO assigns its integer sequence when the projection is persisted. An identifier=True field declared with another field type (e.g. String) gets no default and stays required| Option | Default | Purpose |
|---|---|---|
provider | "default" | Database provider for storing projection data |
cache | None | Cache provider (e.g., "redis"); overrides provider when set |
schema_name | underscore class name | Custom table/schema name in the database |
order_by | () | Default ordering for query results |
limit | 100 | Default query result limit; None for unlimited |
abstract | False | If True, projection is an abstract base class |
externally_populated | False | Set True when a subscriber or event handler fills the projection. check then skips PROJECTION_WITHOUT_PROJECTOR and UNSOURCED_PROJECTION_FIELD for it |
To control the database mapping, register your own model with
@domain.database_model(part_of=...). See
Custom database models.
Projections support these basic field types:
| Type | Import | Example |
|---|---|---|
Identifier | from protean.fields import Identifier | user_id: Identifier(identifier=True) |
Auto | from protean.fields import Auto | id: Auto(identifier=True) |
String | from protean.fields import String | name: String(max_length=100) |
Text | from protean.fields import Text | description: Text() |
Integer | from protean.fields import Integer | count: Integer(default=0) |
Float | from protean.fields import Float | price: Float(required=True) |
Boolean | from protean.fields import Boolean | active: Boolean(default=True) |
DateTime | from protean.fields import DateTime | created_at: DateTime() |
Date | from protean.fields import Date | birth_date: Date() |
Projections also accept ValueObject fields (from protean.fields import ValueObject, e.g. shipping_address = ValueObject(Address)). A value object is stored as flattened shadow fields (shipping_address_street, shipping_address_city, ...) and each attribute is queryable on its own.
# fragment
@domain.projection(provider="postgres", schema_name="product_inventory")
class ProductInventory:
product_id: Identifier(identifier=True, required=True)
name: String(max_length=100, required=True)
stock_quantity: Integer(default=0)
# fragment
@domain.projection(cache="redis")
class ActiveSession:
session_id: Identifier(identifier=True, required=True)
user_id: Identifier(required=True)
email: String(required=True)
@domain.projection(order_by=("last_name",), limit=50)
class UserDirectory:
user_id: Identifier(identifier=True, required=True)
first_name: String(max_length=50)
last_name: String(max_length=50)
email: String(required=True)
from enum import Enum
class BuildingStatus(Enum):
WIP = "WIP"
DONE = "DONE"
@domain.projection
class Building:
building_id: Identifier(identifier=True)
name: String(max_length=50)
floors: Integer()
status: String(choices=BuildingStatus)
def defaults(self):
if not self.status:
if self.floors == 4:
self.status = BuildingStatus.DONE.value
else:
self.status = BuildingStatus.WIP.value
Projections are queried through the same repository interface as aggregates:
repo = domain.repository_for(ProductInventory)
# Flat COUNT without loading rows
low_stock = repo.query.filter(stock_quantity__lt=10).count()
# isnull lookup: records where a field is / isn't set
never_updated = repo.query.filter(last_updated__isnull=True).all().items
# Fetch items without the separate total-count round-trip
page = repo.query.filter(stock_quantity__lt=10).all(with_total=False).items
See the repository skill for the full querying surface (filtering, ordering,
pagination, Q objects).
view_for() and connection_for() operate on projections only; passing a
non-projection element (an aggregate, say) raises IncorrectUsageError with the code
USAGE_NOT_A_PROJECTION.
# fragment
@domain.projection
class OrderView:
order_id: Identifier(identifier=True)
customer = Reference(Customer) # Wrong!
items = HasMany(OrderItem) # Wrong!
Flatten related data into basic fields instead:
@domain.projection
class OrderView:
order_id: Identifier(identifier=True)
customer_name: String()
customer_email: String()
item_count: Integer()
shipping_city: String()
shipping_zip: String()
# fragment
domain.register(MyProjection, provider=None, cache=None) # Wrong!
Instead: Always have at least a provider or a cache
A projection with no projector is never populated, so queries against it always return empty. check reports this as PROJECTION_WITHOUT_PROJECTOR. Add a projector for the projection, or set externally_populated=True if a subscriber fills it instead.
A projection field no projector handler ever writes renders as a dead column. check reports this as UNSOURCED_PROJECTION_FIELD. Write every field from the projector handler for the event that carries it, or drop the field.
projector: Projectors populate projections from domain eventsaggregate: Aggregates are the write-side counterpart to projectionsevent: Events are the bridge between aggregates and projectionscheck and resolve what it reportsassets/projection_field_validation.py (opens in a new tab)assets/projection_persistence.py (opens in a new tab)assets/projection_simple.py (opens in a new tab)assets/projection_with_defaults.py (opens in a new tab)assets/projection_with_options.py (opens in a new tab)references/anti-patterns.md (opens in a new tab)references/basic-projection.md (opens in a new tab)references/configuration-options.md (opens in a new tab)references/field-type-restrictions.md (opens in a new tab)references/persistence-querying.md (opens in a new tab)What 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"./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