From acc
Generates DDD-compliant entities for PHP 8.4 with identity, behavior, state transitions, invariants, status enums, exceptions, and unit tests.
How this skill is triggered — by the user, by Claude, or both
Slash command
/acc:create-entityThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Generate DDD-compliant Entities with identity, behavior, and tests.
Generate DDD-compliant Entities with identity, behavior, and tests.
Every Entity consists of:
| Component | Description |
|---|---|
Identity ({Name}Id) | Unique identifier, readonly, set at construction |
| Status Enum | Lifecycle states with transition rules |
| Constructor | Sets identity, initial status, timestamps, validates invariants |
| Behavior methods | Domain actions (confirm(), cancel(), addLine()) |
| Query methods | State checks (isActive(), canBeConfirmed(), isEmpty()) |
touch() helper | Updates $updatedAt timestamp on mutations |
| File | Location |
|---|---|
| Entity | src/Domain/{BoundedContext}/Entity/{Name}.php |
| Status Enum | src/Domain/{BoundedContext}/Enum/{Name}Status.php |
| Exceptions | src/Domain/{BoundedContext}/Exception/{...}Exception.php |
| Unit Test | tests/Unit/Domain/{BoundedContext}/Entity/{Name}Test.php |
Entities must encapsulate domain logic, not just hold data. Use meaningful behavior methods (confirm(), activate()) instead of anemic setters (setStatus()). Each behavior method enforces invariants before mutating state.
Every mutation method must validate business rules before making changes. Common invariants:
Use a Status enum with explicit transition rules. The enum defines canTransitionTo() to enforce valid state machines. Entities delegate transition validation to the enum.
When asked to create an Entity:
| Concept | Method Pattern | Exception |
|---|---|---|
| State change | confirm(), activate(), cancel() | InvalidStateTransitionException |
| Add relation | addLine(), addItem() | CannotModifyException |
| Update property | changeEmail(), updateName() | InvalidValueException |
| Query state | isActive(), canBeConfirmed() | N/A (boolean return) |
final class {Name}
{
private {Name}Status $status;
private DateTimeImmutable $createdAt;
private ?DateTimeImmutable $updatedAt = null;
public function __construct(
private readonly {Name}Id $id,
{constructorProperties}
) {
{constructorValidation}
$this->status = {Name}Status::default();
$this->createdAt = new DateTimeImmutable();
}
public function id(): {Name}Id { return $this->id; }
public function status(): {Name}Status { return $this->status; }
{behaviorMethods}
private function touch(): void { $this->updatedAt = new DateTimeImmutable(); }
}
#[Group('unit')]
#[CoversClass({Name}::class)]
final class {Name}Test extends TestCase
{
public function testCreatesWithValidData(): void
{
$entity = $this->createEntity();
self::assertInstanceOf({Name}Id::class, $entity->id());
self::assertSame({Name}Status::default(), $entity->status());
}
{behaviorTests}
private function createEntity(): {Name}
{
return new {Name}(id: {Name}Id::generate(), {testConstructorArgs});
}
}
To generate an Entity, provide:
references/templates.md — full PHP code templates (Entity, Test, State Transition Enum, design principle code samples)references/examples.md — complete Order Entity and User Entity implementation examplesnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accGenerates State pattern for PHP 8.4 including context, state interface, concrete states, factory, entity updates, exceptions, and unit tests for state-dependent object behavior like order workflows.
Generates .NET domain entities following DDD principles with factory methods, private setters, domain events, and proper encapsulation. Supports aggregate roots, child entities, and value objects.
Translates domain rules into code using entities, value objects, aggregates, repositories, and domain events with explicit invariants.