/protean:add-fieldfrom protean
Guides adding fields to Protean domain elements (aggregates, entities, value objects). Covers field type selection, validations, and placement for simple fields and associations like HasOne, HasMany, and ValueObject.
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.
Guide for adding fields to Protean domain elements: choosing the right type, configuring parameters, and placing fields correctly.
Before adding a field:
| Target | When | Patterns |
|---|---|---|
| Aggregate | Root domain object | See aggregate |
| Entity | Child object within an aggregate (has identity) | See entity: always needs part_of="AggName" |
| Value Object | Immutable descriptive concept (no identity) | See value-object |
Use a simple field when the data is a single value with no behavior:
email = String(required=True, max_length=254)
price = Decimal(required=True, precision=19, scale=4, min_value=0.01)
Use Decimal for money. Float stores binary floating-point values, so amounts drift
when you add them up.
Use ValueObject when the data has multiple related attributes, behavior, or should be reusable:
@domain.value_object
class Money:
amount = Decimal(required=True, precision=19, scale=4)
currency = String(required=True, max_length=3)
@domain.aggregate
class Invoice:
number = String(required=True, max_length=20)
total = ValueObject(Money) # amount and currency always travel together
Rule of thumb: If you see two fields that always travel together (amount + currency, street + city), extract a value object. See refactor-extract-value-object.
Use HasMany for entities with identity and behavior:
line_items = HasMany("LineItem") # LineItem is an entity with its own identity
Use List for simple values without identity:
tags = List(content_type=String) # Just strings, no identity
| Data | Field type | Example |
|---|---|---|
| Short text | String(max_length=N) | names, codes, statuses |
| Long text | Text() | descriptions, notes |
| Whole number | Integer() | counts, quantities |
| Money | Decimal(precision=19, scale=4) | prices, totals, balances |
| Measurement | Float() | weights, ratios, coordinates |
| True/False | Boolean(default=True) | flags |
| Date only | Date() | birth_date, expiry_date |
| Date + time | DateTime() | timestamps |
| Identity | String(identifier=True) | custom IDs |
| One child entity | HasOne("Entity") | one-to-one |
| Many child entities | HasMany("Entity") | one-to-many |
| Embedded VO | ValueObject(VOClass) | Money, Address |
| Link to another aggregate | Identifier() | customer_id, holds the other aggregate's id |
| Link back to the parent (aggregate root, or parent entity when nested) | Reference("Order") | on an entity, the reverse side of HasMany/HasOne |
| Simple list | List(content_type=String) | tags, codes |
| Key-value | Dict() | metadata |
from protean.fields.validators import RegexValidator
# Required vs optional
name = String(required=True)
description = String() # Optional (can be None)
# Defaults
status = String(default="draft")
# Constraints
sku = String(unique=True, max_length=50)
price = Decimal(precision=19, scale=4, min_value=0.01, max_value=999999.99)
quantity = Integer(min_value=1, max_value=10000)
# Enum-like choices
status = String(choices=["draft", "published", "archived"])
# Format validators
email = String(validators=[RegexValidator(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")])
| Rule type | Where | How |
|---|---|---|
| Single-field constraint | Field parameter | Integer(min_value=1) |
| Format validation | Validator | String(validators=[RegexValidator(r"...")]) or a custom validator class |
| Cross-field business rule | @invariant.post on aggregate | See add-validation |
| State-dependent guard | Method body | if self.status != "DRAFT": raise ... |
Never duplicate: if a rule can be expressed as a field parameter, don't also add an invariant.
If a repository filters on a field, add an index led by that field so the query does not force a full table scan:
from protean import Index
@domain.aggregate(indexes=[Index("email")])
class User:
email = String(required=True, max_length=254)
name = String(max_length=100)
An indexed String field should carry a max_length. An index over an unbounded string is
unportable: the DDL fails on SQL Server, needs a prefix length on MySQL, and is inefficient
on PostgreSQL. Size the length to the field's domain.
UNINDEXED_FILTER_PATH: a repository filter on a field with no covering index. Add
an index led by that field (indexes=[Index("field")]), or leave it alone when the table
stays small or the query is a one-off.UNBOUNDED_INDEXED_STRING: an indexed String field with no max_length. Give it a
bounded length, or drop it from the index if it does not need indexing.When you add items = HasMany("LineItem"), these methods are automatically available:
aggregate.add_items(item): add one or more itemsaggregate.remove_items(item): remove an itemaggregate.get_one_from_items(id=item_id): get one item by keyword criteria. It raises
ObjectNotFoundError (from protean.exceptions) when nothing matches and TooManyObjectsError
when more than one item matches. It never returns None.aggregate.filter_items(**criteria): get the items whose fields equal the given values.
It matches equality only; operators such as price__gt are not supported.Never manually define these methods: they exist automatically.
Integer for counts, Decimal for money and Float for measurements, not String. Use Date/DateTime for dates.See references/common-mistakes.md for detailed examples.
Identifier link to another aggregatecheck and resolve what it reportsassets/add_association_fields.py (opens in a new tab)assets/add_field_with_custom_validator.py (opens in a new tab)assets/add_simple_field.py (opens in a new tab)assets/add_value_object_field.py (opens in a new tab)references/associations.md (opens in a new tab)references/common-mistakes.md (opens in a new tab)references/field-types.md (opens in a new tab)references/validation.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-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"./add-subscriber-flowBuild a complete external integration flow in Protean using subscribers. Subscribers consume messages from external systems via broker streams and translate them into domain actions using the anti-corruption layer (ACL) pattern. Use when the user asks to "add an external integration", "consume external events", "handle webhook events", "integrate with an external system", "add a subscriber flow", "build an anti-corruption layer", "translate external messages", "process broker messages", or when they describe scenarios like "when the payment gateway confirms", "when the ERP syncs users", "react to external system notifications".Other plugins' skills for the same job