create-entity-lifecycle
Skill2 starsChanged 6 days agoMITView on GitHub
Generate comprehensive entity lifecycle documentation. USE THIS SKILL when user mentions: create entity, entity lifecycle, entity documentation, document entity, entity state machine, create entity spec, entity definition, domain entity, aggregate lifecycle, or any request to create technical documentation for a domain entity including state machine, transitions, and domain behavior. This skill creates complete entity specs with state diagrams, transition matrices, domain methods, and extracts business rules and invariants.
In this repository19 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adr-amendSkill
- adr-createSkill
- adr-review-alternativesSkill
- adr-validateSkill
- agents-maintainerSkill
- audit-docsSkill
- explore-domainSkill
- sdlc-guideSkill
- setup-sdlcSkill
- inception-workshopSkill
- prd-workshopSkill
- user-story-mappingSkill
- modify-flowSkill
- reverse-engineer-domainSkill
- create-moduleSkill
- implement-flowSkill
- create-featuresSkill
- create-flow-documentationSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 7 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 60
After generating the entity lifecycle document, review the project's Architecture Decision Records (ADRs) to ensure alignment with …
- Very specific: line 82
Before writing a single row, open the class the document describes — plus its value objects, the repository port in domain/, and …
- Distinctive: line 111
State Completeness: Every state shown in the Mermaid diagram must have a corresponding definition in the State Definitions section
- Distinctive: line 112
Transition Completeness: Every transition arrow in the Mermaid diagram must be documented in the State Transition Matrix
- Very specific: line 113
State Names: Use consistent naming (e.g., DRAFT, CFP_OPEN, not draft, active)
- Very specific: line 116
Domain Methods: If domain methods are shown in the Mermaid (e.g., Event.publishCfp()), they must be documented in the Domain Behavior …
- Distinctive: line 117
Terminal States: All terminal states (states with no outgoing transitions) should be clearly identified in State Definitions
- Distinctive: line 139
Use the templates provided at:
- Very specific: line 146
Ensure the generated entity lifecycle document links to these extracted files under its Invariants & Business Rules section using relative …
- Distinctive: line 168
Domain Behavior: - Every public method the class exposes, each with a Status
- Distinctive: line 233
Before ending your turn, verify every item below with concrete evidence (not just a checkmark).
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PROTOCOL: CREATE-ENTITY-LIFECYCLE (EXECUTION LEVEL 3)
<state_machine>
CURRENT_STEP -> REQUIRED_TOOL -> REQUIRED_OUTPUT -> MANDATORY_HALT
Step 1: Read Code -> read_file (domain class, VOs, repo port, events) -> Earned status facts (✅ Built / ⚠️ Unverified / ⏳ Planned) -> Continue to Step 2
Step 2: Write Doc -> read_file(templates/entity-lifecycle|value-object) -> bounded-contexts/{ctx}/{entities,value-objects,domain-services}/ -> Continue to Step 3
Step 3: Extract Rules -> read_file(templates/business-rules.md, invariants) -> BR-XXX & INV-XXX files + bidirectional Enforcement & tests -> 🛑 HALT TURN (Present docs)
</state_machine>
<execution_invariants>
- WORKFLOW IMMUTABILITY: You may reason freely INSIDE each step to inspect domain classes, value objects, and state transitions, but you are strictly forbidden from skipping reading the real source code (
Code Is Truth), skipping rule extraction, or improvising document structure (workflow structure = immutable | step reasoning = flexible). - TEMPLATE LOCK: Reconstructing template headers or tables from internal memory is strictly forbidden. You MUST call
read_fileontemplates/entity-lifecycle.md(ortemplates/value-object.md/templates/domain-service.md) andtemplates/business-rules.md/templates/invariants.mdbefore writing. - EARNED STATUS INVARIANT (
Code Is Truth): Open and read the real domain class, value objects, repository port, and domain events before writing any row. Never mark a row✅ Builtwithout reading the code, and always write⏳ Plannedrows in the future tense. - ESCAPE HATCH: If the situation does not fit the contract, do not silently improvise and do not force-fit: declare the deviation in one line and ask. </execution_invariants>
<output_contract>
- ENTITY / VO / SERVICE DOCUMENT:
- TARGET_PATH:
docs/product/bounded-contexts/{context}/{entities|value-objects|domain-services}/{Name}.md - SOURCE_TEMPLATE:
templates/entity-lifecycle.md|templates/value-object.md|templates/domain-service.md(MUST callread_filebefore writing) - SCHEMA_INVARIANCE: Preserve every H1/H2/H3 section heading,
Statuscolumn (✅ Built/⚠️ Unverified/⏳ Planned), and table column schema verbatim.
- TARGET_PATH:
- BUSINESS RULES & INVARIANTS:
- TARGET_PATHS:
docs/product/bounded-contexts/{context}/business-rules/BR-[XXX]-[rule-name].mdandinvariants/INV-[XXX]-[invariant-name].md - SOURCE_TEMPLATES:
templates/business-rules.mdandtemplates/invariants.md(MUST callread_filebefore writing)
- TARGET_PATHS:
- ESCAPE_HATCH: Never silently omit or invent template sections. If a section genuinely does not apply (e.g.,
## 🛠️ Repository Interface *(aggregate roots only)*on a child entity, or## 📣 Domain Eventswhen the entity emits zero events), preserve the heading and write"N/A — [1-line rationale]"(e.g.,"N/A — Child entity persisted via parent aggregate root"). </output_contract>
Paths: the locations shown are the pack defaults; if
.sdlc/config.jsonexists (written by/setup-sdlc), honour itsdocsRoot/productDocsDir/adrDiroverrides.
📋 Input Context
- Entity Name: [Domain noun/entity name]
- Aggregate Role: [Root Entity or Child Entity]
- Domain Context: [Bounded context or domain area]
- Bounded Context: [Identify the bounded context for this entity]
- Related Entities: [List related entities in the aggregate]
- Value Objects: [List value objects used by the entity]
- State Machine: [List all possible states]
- Domain Behavior: [List core domain methods]
- Feature References:
docs/product/working-on/active/[change]/features/(feature specs as input only — use them to establish bidirectional traceability inBR-XXXandINV-XXXdocs, but never link them fromBR-*/INV-*docs)
✅ Required ADR Review After Creation
After generating the entity lifecycle document, review the project's Architecture Decision Records (ADRs) to ensure alignment with established architectural decisions.
Compliance Checklist
- Entity is properly designated as Aggregate Root or Child Entity
- Value Objects encapsulate validation and business rules
- Domain behavior is exposed through methods (not data setters)
- State transitions are explicit and validated
- Domain events are published on state changes
- Repository interfaces are defined for data access
- Entity invariants are documented and enforced
- Entity links to relevant User Flows / Journeys
- Domain events are documented with triggers and side effects
- State definitions are clear and unambiguous
- Validation rules are comprehensive
- Every state, transition, method, event and repository row carries a Status you earned by opening the class
⏳ Plannedrows are phrased in the future tense, never in the present tense
🔍 Code Is Truth (Read The Class First)
Before writing a single row, open the class the document describes — plus its value objects, the
repository port in domain/, and domain/events/. This document describes what ships. The product
blueprint describes what is wanted, and only one of those two is a claim about the code.
- Every table row is a claim about the class.
✅ Builtonly for a state, transition, method, event or repository method you found in the code you read;⚠️ Unverifiedwhen you believe it but did not look;⏳ Plannedwhen no code exists yet. ⏳ Plannedis written in the future tense — "will emitCfpClosed", never "publishesCfpClosed". Present tense asserts the code ships.- A target-product state machine documented as if it were Wave 1 is the most expensive defect this
document can carry. If the class implements one mutator, the matrix gets one
✅ Builtrow and the rest are⏳ Planned. That is a correct document, not an incomplete one. - Never invent an API in order to document one. No
closeCfp()in the class ⇒ it is a⏳ Plannedrow or absent — never a present-tense row. Same rule for repository methods, event constructors and value-object members. - A side effect needs a live consumer. An event whose worker is not built gets
⏳ Planned, and the unbuilt worker does not appear as a bullet in the side-effect cell. - Transcribe the repository port, do not improve it — optional parameters included (
save(e, tx?); thattxis what makes the Transactional Outbox atomic). A phantomfindByStatus()hides drift for months. - A
✅you did not earn by opening the file is worse than a⚠️— this binds on this document's tables exactly as it binds on a rule'sEnforced bytable (§Extraction item 5).
🔄 Mermaid Diagram & State Definition Consistency
The Mermaid state machine diagram and the State Definitions/Transition Matrix MUST be aligned:
- State Completeness: Every state shown in the Mermaid diagram must have a corresponding definition in the State Definitions section
- Transition Completeness: Every transition arrow in the Mermaid diagram must be documented in the State Transition Matrix
- State Names: Use consistent naming (e.g.,
DRAFT,CFP_OPEN, notdraft,active) - Trigger Alignment: The triggering actions/events in the Mermaid diagram must match the "Event / Trigger" column in the State Transition Matrix
- Target State Alignment: The target states in the Mermaid diagram must match the "Target State" column in the State Transition Matrix
- Domain Methods: If domain methods are shown in the Mermaid (e.g.,
Event.publishCfp()), they must be documented in the Domain Behavior section - Terminal States: All terminal states (states with no outgoing transitions) should be clearly identified in State Definitions
📁 Output Path
Choose the output path based on the DDD classification of what you are documenting:
| Type | Path | When to use |
| Aggregate root / child entity | docs/product/bounded-contexts/{context}/entities/{EntityName}.md | Has identity, lifecycle, state machine |
| Value object | docs/product/bounded-contexts/{context}/value-objects/{VoName}.md | No identity, validated at construction, immutable |
| Domain service | docs/product/bounded-contexts/{context}/domain-services/{ServiceName}.md | Stateless logic that doesn't belong to a single entity |
Where {bounded-context-name} is the kebab-case name of the bounded context (e.g., event, submission, review, scheduling, or any future context)
📐 Business Rules & Invariants Extraction
During entity lifecycle creation, you MUST identify all business rules and invariants that govern the entity's state machine, transitions, domain methods, or value objects:
- Use the templates provided at:
templates/business-rules.mdtemplates/invariants.md
- Extract each identified business rule to:
docs/product/bounded-contexts/{bounded-context-name}/business-rules/BR-[XXX]-[rule-name].md
- Extract each identified invariant to:
docs/product/bounded-contexts/{bounded-context-name}/invariants/INV-[XXX]-[invariant-name].md
- Ensure the generated entity lifecycle document links to these extracted files under its Invariants & Business Rules section using relative markdown links (e.g.,
../business-rules/BR-[XXX]-[rule-name].md) - Complete the
Traceabilitysection of every rule/invariant you create (templates/business-rules.md§5,templates/invariants.md§6) —Traces up to(journey, flow),Enforced by(one row per layer that can reject the policy, naming the file and the guard, each marked ✅ Verified / ⚠️ Unverified / ⏳ Planned according to what you read in the code) andVerified by(test file and test title). A rule with an emptyEnforced bytable is not finished; a ✅ you did not earn by opening the file is worse than ⚠️. Convention:../guidelines/traceability.md - Complete the
Enforcement & teststable in the entity/value-object document you are generating, so each rule listed under Invariants & Business Rules also names its enforcing member and test file — that table is the reverse edge of item 5, and both must be written in the same change
📖 Documentation Structure
This skill is language- and framework-agnostic. File paths and class conventions should follow the target repository's established architecture (consult AGENTS.md or ARCHITECTURE.md).
Entities (aggregate roots / child entities)
- Definition & Context - Description, database table / collection, primary key, implementation source path
- State Machine Diagram - Mermaid state diagram showing all states and transitions
- State Transition Matrix - Complete mapping of allowed state changes, every row carrying a Status
- State Definitions - Detailed criteria for each state
- Domain Behavior - Every public method the class exposes, each with a Status
- Domain Events - Event, constructing call site, payload, and the consumer that exists today, each with a Status
- Invariants & Business Rules - Links to extracted BRs and INVs, plus the
Enforcement & testsreverse edge - Repository Interface (aggregate roots only) - The persistence port transcribed from
domain/, signature included - Linked User Stories & Flows - References to flows that interact with the entity
Value Objects
- Definition - Description, type (
Simple Value Object | Composite Value Object), immutability, validation summary, implementation source path - Composition - Property, type, and description table
- Validation Rules - Rule name and what is validated/why
- Behavior & Methods - Factory methods (
create()for validated new instances,fromData()for persistence reconstitution), getters, and equality methods, each with a Status (✅ Built/⏳ Planned) - Error Conditions - Exception class, trigger condition, and Status
- Invariants & Business Rules - Links to relevant INVs and BRs, plus the
Enforcement & testsreverse-edge table - Referenced By - Which aggregates, entities, or use cases embed this VO
- Related Value Objects - Related VOs in the same or adjacent bounded contexts
Domain Services
Two parts, so a PM can stop after Part A:
Part A — Product View (shipped behaviour, business language, no code names)
- Summary - One sentence: what it decides and why it matters
- Business Context - Why it is a domain service, the business problem it solves, participating flows
- How It Decides - Decision paths, governing policies (BRs and INVs), one business-language decision flow per path
- Pending Changes - Changes coming from an open proposal (change, slice, proposal link, ticket, status); removed when the slice ships
Part B — Developer View
- Definition - Type and implementation source path
- Collaborators - Dependencies, what each provides, Built/Planned status
- Methods - Each public method: guards, steps, side effects, return value, status
- Sequence Diagram - One diagram showing all method orchestration flows (use
rectblocks per method) - Rules & Invariants Enforced - BRs and INVs the service enforces, with the method that enforces each (a domain service may enforce business rules as well as invariants)
- Traceability -
Enforced by(file + guard + status) andVerified by(test file + test title) - Linked Flows - Which flows invoke which methods and at which step
📚 Bundled Resources
Templates
| Template | Purpose |
templates/entity-lifecycle.md | Entity lifecycle document template |
templates/value-object.md | Value object document template |
templates/domain-service.md | Domain service document template |
templates/business-rules.md | Business rule documentation template |
templates/invariants.md | Invariant documentation template |
Guidelines
| Guideline | Purpose |
../guidelines/flow-documentation-structure.md | Flow documentation standards (reference) |
../guidelines/business-rules-vs-invariants.md | When to use BR vs INV, differences and enforcement |
../guidelines/traceability.md | Linking rules to flows, entities, code and tests — both ends of every edge |
🔗 Related Documentation
- User journey docs: the repo's journey/inception documentation — discover the path, don't assume
docs/inception/. - Bounded contexts: the repo's product docs tree — discover the path, don't assume
docs/product/.
<self_validation_gate> Before ending your turn, verify every item below with concrete evidence (not just a checkmark). If any item cannot be cited with real evidence from this turn, DO NOT produce your final response — return to the failed step and fix the violation first:
- Code Read Evidence (
Code Is Truth): List the exact domain class, value object, repository port, and event source files opened viaread_file(or state"Greenfield — all rows marked ⏳ Planned in future tense"):<source paths> - Template Read Evidence: Exact
templates/*.mdpaths passed toread_filein this turn:<paths> - Output & State Parity Evidence: Exact doc path written and number of states/transitions matched 1:1 across Mermaid diagram, Transition Matrix, and State Definitions:
<path, N states> - Bidirectional Traceability Evidence: List the
BR-XXXandINV-XXXfiles created/updated with completeTraceabilitytables (Traces up to,Enforced by,Verified by) AND matching rows in### Enforcement & tests:<BR/INV paths></self_validation_gate>
Last Updated: 2026-11-05
Version: 1.4 (Level 3 Execution Protocol)
Changes from v1.2:
- Added
🔍 Code Is Truth: open the class, its value objects, the repository port anddomain/events/before writing any row; every table row is an earned claim with a Status Documentation Structure → Entitiesnow listsDomain Behavior,Domain EventsandRepository Interface— the three sections whose absence let unbuilt mutators be documented in the present tense- Templates
entity-lifecycle.md,value-object.mdanddomain-service.mdgainedStatuscolumns (✅ Built/⚠️ Unverified/⏳ Planned) and a status legend Changes from v1.1: - Domain service documentation structure updated: sequence diagram + one flow diagram per method
templates/domain-service.mdupdated with separate flow diagram blocks per method andrect-based sequence diagram Changes from v1.0:- Output path now distinguishes entities, value-objects, and domain-services folders
- Documentation Structure split into three sections matching DDD classifications
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

