From acc
Generates DDD-compliant factories for PHP 8.4 domain objects, encapsulating complex creation logic with input validation and unit tests. Ideal for intricate entity instantiation, aggregates, and reconstruction from persistence.
How this skill is triggered — by the user, by Claude, or both
Slash command
/acc:create-factoryThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Generate DDD-compliant Factories for complex domain object creation.
Generate DDD-compliant Factories for complex domain object creation.
| Scenario | Example |
|---|---|
| Complex construction logic | OrderFactory::createFromCart() |
| Multiple creation paths | User::register(), User::createAdmin() |
| Aggregate creation | PolicyFactory::createWithCoverage() |
| Reconstruction from persistence | OrderFactory::reconstitute() |
| Creation with validation | InvoiceFactory::create() |
Path: src/Domain/{BoundedContext}/Factory/
{Entity}Factory.php — Main factory classcreate() — Primary creation with validationcreateFrom{Source}() — Creation from other objectsreconstitute() — Reconstruction from persistence (no validation)Path: tests/Unit/Domain/{BoundedContext}/Factory/
| Component | Path |
|---|---|
| Factory | src/Domain/{BoundedContext}/Factory/ |
| Unit Tests | tests/Unit/Domain/{BoundedContext}/Factory/ |
| Pattern | Example |
|---|---|
| Factory Class | {EntityName}Factory |
| Create Method | create(), createFrom{Source}() |
| Named Constructor | create{Variant}() |
| Reconstitute | reconstitute() |
| Validation | validate{Aspect}() |
final class {Entity}Factory
{
public static function create({parameters}): {Entity}
{
self::validate({parameters});
return new {Entity}({constructorArgs});
}
public static function createFrom{Source}({SourceType} $source): {Entity}
{
return new {Entity}({mappedArgs});
}
public static function reconstitute({allFields}): {Entity}
{
return new {Entity}({allArgs});
}
private static function validate({parameters}): void
{
{validationLogic}
}
}
final readonly class {Entity}Factory
{
public function __construct(
private {DomainService} $service,
private {Repository} $repository
) {}
public function create({parameters}): {Entity}
{
{creationLogicWithDependencies}
}
}
| Anti-pattern | Problem | Solution |
|---|---|---|
| Infrastructure in Factory | DB calls in factory | Keep pure domain logic |
| No Validation | Creates invalid objects | Validate before creation |
| Too Many Parameters | Hard to use | Use Value Objects, Builder |
| Mutable Factory | Stateful creation | Make stateless or readonly |
| Missing Reconstitute | Can't hydrate from DB | Add reconstitute method |
For complete PHP templates and examples, see:
references/templates.md — Static Factory, Instance Factory, Test templatesreferences/examples.md — Order, User, Policy factory examples and testsnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accGenerates DDD-compliant aggregates for PHP 8.4 with root entity, child entities, domain events, invariant protection, and unit tests.
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.
Implements Clean Architecture, Hexagonal (Ports & Adapters), and Domain-Driven Design patterns in PHP 8.3+ with Symfony 7.x. For enterprise app architecture, legacy refactoring, DDD, and testable backends.