/protean:query-handlerfrom protean
Defines Protean query handlers that answer read-side CQRS queries using @read decorators, reading from projections via view_for and returning results without side effects.
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 query handler answers queries: it receives a query DTO, reads from a projection, and returns the result. It is the read-side mirror of a command handler, but it uses @read instead of @handle, runs no Unit of Work, and always returns a value.
from protean import Domain, current_domain, read
from protean.fields import Identifier, String
domain = Domain()
@domain.projection
class OrderSummary:
order_id: Identifier(identifier=True)
status: String(max_length=20)
@domain.query(part_of="OrderSummary")
class GetOrderById:
order_id: Identifier(required=True)
@domain.query_handler(part_of="OrderSummary")
class OrderQueryHandler:
@read(GetOrderById)
def get_by_id(self, query: GetOrderById):
return current_domain.view_for(OrderSummary).get(query.order_id)
@domain.query_handler(part_of="OrderSummary") (the read model, not an aggregate)@read decorator: Each method is decorated @read(QueryClass) (the read-side counterpart to @handle); import it: from protean import readdomain.dispatch(query) hands the query handler's result back to the caller@read method(self, query): The dispatched query instance is passed inview_for: Use current_domain.view_for(Projection) to get a read-only query interface: .get(id), .query.filter(...).all(), .count(), .exists(id)domain.dispatch(query): This routes the query to its handler and returns the result (synchronous)from protean import Domain, current_domain, read
from protean.fields import Identifier, String
domain = Domain()
@domain.projection
class OrderSummary:
order_id: Identifier(identifier=True)
status: String(max_length=20)
@domain.query(part_of="OrderSummary")
class GetOrderById:
order_id: Identifier(required=True)
@domain.query(part_of="OrderSummary")
class ListOrdersByStatus:
status: String(required=True)
@domain.query_handler(part_of="OrderSummary")
class OrderQueryHandler:
@read(GetOrderById)
def get_by_id(self, query: GetOrderById):
return current_domain.view_for(OrderSummary).get(query.order_id)
@read(ListOrdersByStatus)
def list_by_status(self, query: ListOrdersByStatus):
view = current_domain.view_for(OrderSummary)
return view.query.filter(status=query.status).all().items
domain.init(traverse=False)
with domain.domain_context():
domain.repository_for(OrderSummary).add(
OrderSummary(order_id="ORD-1", status="placed")
)
# Returns the handler's return value directly (synchronous)
order = domain.dispatch(GetOrderById(order_id="ORD-1"))
placed = domain.dispatch(ListOrdersByStatus(status="placed"))
current_domain.view_for(Projection) returns a read-only interface:
with domain.domain_context():
view = current_domain.view_for(OrderSummary)
view.get("ORD-1") # single record by id
view.query.filter(status="placed").all().items # filtered list
view.query.filter(status="placed").count() # flat count
view.exists("ORD-1") # is there a record with this id?
A projection with a query handler but no @domain.query(part_of=...) registered for it has a read path nothing can invoke. check reports this as QUERY_HANDLER_WITHOUT_QUERY. Register a query for the handler to serve, or remove the query handler if the projection needs no read path.
query: The read-intent DTO a handler answersprojection: The read model the handler reads fromprojector: Populates the projection from domain eventscommand-handler: The write-side counterpart (uses @handle, runs a UoW)check and resolve what it reportsWhat 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