Generates DDD Factory for PHP 8.4. Creates factories for complex domain object instantiation with validation and encapsulated creation logic. Includes unit tests.
From accnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accThis skill uses the workspace's default tool permissions.
references/examples.mdreferences/templates.mdGenerate 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 testsProvides UI/UX resources: 50+ styles, color palettes, font pairings, guidelines, charts for web/mobile across React, Next.js, Vue, Svelte, Tailwind, React Native, Flutter. Aids planning, building, reviewing interfaces.