/protean:audit-domainfrom protean
Scans a Protean domain codebase for design-quality issues, anti-patterns, and convention violations. Produces a prioritized report with refactoring links.
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.
Scan a Protean domain codebase for design-quality issues, anti-patterns, and convention violations. Produces a prioritized report linking each finding to the appropriate refactoring skill.
| Output | Purpose |
|---|---|
| Finding list | Each anti-pattern found, classified by severity and category |
| Prioritized report | Findings grouped by severity (CRITICAL > HIGH > MEDIUM > LOW) |
| Refactoring links | Each finding links to the skill that fixes it |
| Summary statistics | Aggregate counts, handler counts, issue breakdown |
protean checkprotean check finds part of what this audit looks for. Run it first and record what it reports:
protean check --domain=<module>
If the module defines more than one domain, name the one to audit after a colon, for example --domain=myapp.domain:billing.
Through the MCP server, call the check tool instead. Do not pass --level=warning here. Several of the codes below are info level, and --level=warning would hide them.
| Code | Level | What it reports | Severity | Fix |
|---|---|---|---|---|
COMMAND_HANDLER_CROSS_CLUSTER | warning | A command handler processes another cluster's command | HIGH | command-handler |
CROSS_AGGREGATE_REFERENCE | warning | A field holds a Reference to another aggregate root | HIGH | split-aggregate |
EVENT_HANDLER_FOREIGN_EVENT | warning | An event handler reacts to another cluster's event | MEDIUM | event-handler |
AGGREGATE_TOO_LARGE | info | The aggregate's cluster has more child entities than [lint] aggregate_size_limit (default 5) | MEDIUM, or HIGH with the category 4 signals | split-aggregate |
HANDLER_PERSISTS_AND_CALLS_OUT | info | A handler method persists and then calls an external system while the transaction is open | MEDIUM | command-handler |
AGGREGATE_NO_INVARIANTS | info | The aggregate declares no invariant | LOW | add-validation |
HANDLER_TOO_BROAD | info | A command or event handler handles more message types than [lint] handler_breadth_limit (default 5) | LOW | command-handler, event-handler |
Report each of these codes at the severity in the table. check prints other diagnostics too, such as errors and naming and wiring codes. Report those at their level: an error as CRITICAL, a warning as MEDIUM, and an info diagnostic as LOW. The element skills cover their fixes.
check has no rule for most of these categories, and it does not look at endpoints or tests, so they need a reading of the code. Scan for them in order. Each has a detection heuristic and a linked fix. Where a finding is one check already reported, record it once, with its code.
Detect: Handler methods (@handle) with more than ~5 lines of logic beyond load/persist.
Look for conditionals, calculations, state checks, or validation in handlers, services, or endpoints.
Signals:
if statements in handler methods (beyond simple error checks)raise ValidationError or raise ValueError in handlers or endpointsSeverity: HIGH Fix: refactor-move-logic-to-aggregate
Detect: Groups of fields that always appear together, or bare String/Float/Integer
fields representing domain concepts that deserve their own type.
Signals:
amount + currency, street + city + zip_code + state_email, _phone, _url suffixesFloat fields representing moneyString fields with validators that could be a VO (email, phone, URL patterns)Severity: MEDIUM Fix: refactor-extract-value-object
Detect: Handler methods that call repository.add() or domain.repository_for() for
more than one aggregate class.
Signals:
current_domain.repository_for(X).add() calls on more than one aggregate typedomain.repository_for(X) calls in one handlerSeverity: CRITICAL Fix: refactor-introduce-events
Detect: check reports AGGREGATE_TOO_LARGE when the aggregate's cluster holds more child entities than [lint] aggregate_size_limit (default 5). That is the only size rule the framework enforces.
Signals this skill adds (check does not count these, so judge them by reading the aggregate):
HasMany associations pointing to unrelated entity typesSeverity: HIGH Fix: split-aggregate
Detect: with UnitOfWork() or from protean import UnitOfWork inside handler code.
Signals:
UnitOfWork import in handler fileswith UnitOfWork(): blocks inside @handle methodsSeverity: MEDIUM Fix: Remove the wrapping. Handlers run in an implicit UoW automatically.
Detect: Calling handler methods directly instead of using domain.process().
Signals:
handler = SomeHandler() followed by handler.method(command)domain.process() or current_domain.process() callsSeverity: HIGH
Fix: Replace with domain.process(command).
Detect: Validation logic outside the domain layer: in handlers, endpoints, or services.
Signals:
raise ValidationError in handler methodsif not field: in API endpoints@invariant.post decorators on aggregates with complex rulesSeverity: MEDIUM Fix: add-validation
Detect: Commands, events, entities, or value objects using class references for part_of
instead of string references.
Signals:
@domain.command(part_of=OrderAggregate) (a class reference where a string would do)@domain.event(part_of=Order) where Order is imported at top of filefrom .order import Order in command/event filesSeverity: LOW
Fix: Change to string references: part_of="Order".
Detect: Tests using Mock(), MagicMock(), or @patch for domain elements.
Signals:
from unittest.mock import Mock, patch, MagicMockmock_repo = Mock() or @patch("...repository...")Severity: MEDIUM Fix: Replace with Protean's in-memory adapters and real domain objects.
Detect: Events without __version__ attribute, especially in production codebases.
Signals:
@domain.event classes without __version__Severity: LOW (new projects), HIGH (production with event store)
Fix: Add __version__ to all events; create upcasters for schema changes.
Detect: Aggregate methods or handlers that directly call into another aggregate's logic without raising events.
Signals:
domain.repository_for(OtherAggregate)Severity: HIGH Fix: refactor-introduce-events
protean checkRun it as Start with protean check describes, and keep its output. Each code it reports is a finding, and the codes tell you which categories are already covered.
Find all Python files containing @domain. decorators or importing from protean:
src/**/
├── **/aggregate*.py, **/model*.py
├── **/command*.py, **/event*.py
├── **/handler*.py, **/*_handler.py
├── **/service*.py
├── **/api*.py, **/*_api.py
└── **/test_*.py
For every domain file, check all 11 detection categories. Skip a finding check already reported in Step 1. Record each finding with:
check code if there is one## Domain Audit Report
### Summary
- Files scanned: N
- Aggregates found: N
- Handlers found: N
- Issues found: N (C critical, H high, M medium, L low)
- From `check`: N (list the codes)
### CRITICAL
1. **[Category]: [description]**: `file.py:line`
Fix: [one-sentence suggestion] → [link to skill]
### HIGH
1. ...
### MEDIUM
1. ...
### LOW
1. ...
### Recommended refactoring order
1. [Most impactful fix first]
2. [Second most impactful]
3. ...
Prioritize fixes by:
_version, _events, meta_) are not findingsA domain with these elements:
from protean.exceptions import ValidationError
@domain.aggregate
class Order:
buyer_id = Identifier(required=True)
total = Decimal(precision=19, scale=4)
status = String(default="DRAFT")
@domain.aggregate
class Inventory:
quantity = Integer(default=0)
@domain.command(part_of=Order)
class PlaceOrder:
buyer_id = Identifier(required=True)
product_id = Identifier(required=True)
quantity = Integer(required=True)
items = List(content_type=Dict())
and this handler:
@domain.command_handler(part_of=Order)
class OrderCommandHandler:
@handle(PlaceOrder)
def place_order(self, command):
if len(command.items) == 0:
raise ValidationError({"items": ["Order must have items"]})
total = sum(i["price"] * i["qty"] for i in command.items)
if total > 10000:
raise ValidationError({"total": ["Order exceeds maximum"]})
order = Order(buyer_id=command.buyer_id, total=total, status="PLACED")
current_domain.repository_for(Order).add(order)
inventory = current_domain.repository_for(Inventory).get(command.product_id)
inventory.quantity -= command.quantity
current_domain.repository_for(Inventory).add(inventory)
Would produce:
CRITICAL: Transaction boundary violation: handler modifies both Order and Inventory (lines 12-14)
HIGH: Logic leak: validation and calculation in handler, not aggregate (lines 5-9)
HIGH: Missing events: Inventory update should be event-driven, not direct (lines 12-14)
MEDIUM: AGGREGATE_WITHOUT_COMMAND_HANDLER on Inventory (from check)
LOW: AGGREGATE_NO_INVARIANTS on Order and Inventory (from check)
AGGREGATE_WITHOUT_COMMAND_HANDLER is a warning that the table above does not list, so it is reported as MEDIUM. The aggregate skill covers its fix.
check and resolve what it reportsWhat 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