Generates Unit of Work pattern components for PHP 8.4. Creates transactional consistency infrastructure with aggregate tracking, flush/rollback, domain event collection, and unit tests.
From accnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accThis skill uses the workspace's default tool permissions.
references/examples.mdreferences/templates.mdCreates Unit of Work pattern infrastructure for transactional consistency across multiple aggregates.
| Scenario | Example |
|---|---|
| Multi-aggregate transactions | Order + Payment + Inventory in single transaction |
| Batch persistence | Flush multiple entity changes at once |
| Change tracking | Detect dirty entities for selective updates |
| Domain event collection | Collect and dispatch events after successful commit |
| Repository coordination | Ensure all repositories share the same transaction |
Determine:
Create in this order:
Domain Layer (src/Domain/Shared/UnitOfWork/)
EntityState.php — State enum (New, Clean, Dirty, Deleted)TransactionManagerInterface.php — Transaction contractDomainEventCollectorInterface.php — Event collection contractApplication Layer (src/Application/Shared/UnitOfWork/)
UnitOfWorkInterface.php — Main portAggregateTracker.php — Identity map and change trackingInfrastructure Layer (src/Infrastructure/Persistence/UnitOfWork/)
DoctrineUnitOfWork.php — Doctrine-based implementationDoctrineTransactionManager.php — Doctrine transaction managerDomainEventCollector.php — Event collector with dispatcherTests
EntityStateTest.phpAggregateTrackerTest.phpDoctrineUnitOfWorkTest.phpFor each context (e.g., Order):
src/Application/{Context}/
└── {Context}UnitOfWorkAware.php (trait or base class)
| Layer | Path |
|---|---|
| Domain Types | src/Domain/Shared/UnitOfWork/ |
| Application Port | src/Application/Shared/UnitOfWork/ |
| Infrastructure | src/Infrastructure/Persistence/UnitOfWork/ |
| Unit Tests | tests/Unit/{Layer}/{Path}/ |
| Component | Pattern | Example |
|---|---|---|
| State Enum | EntityState | EntityState |
| Main Interface | UnitOfWorkInterface | UnitOfWorkInterface |
| Implementation | Doctrine{Name} | DoctrineUnitOfWork |
| Tracker | AggregateTracker | AggregateTracker |
| Transaction | TransactionManagerInterface | TransactionManagerInterface |
| Test | {ClassName}Test | DoctrineUnitOfWorkTest |
interface UnitOfWorkInterface
{
public function begin(): void;
public function commit(): void;
public function rollback(): void;
public function registerNew(object $entity): void;
public function registerDirty(object $entity): void;
public function registerDeleted(object $entity): void;
public function flush(): void;
}
enum EntityState: string
{
case New = 'new';
case Clean = 'clean';
case Dirty = 'dirty';
case Deleted = 'deleted';
public function canTransitionTo(self $next): bool;
}
$unitOfWork->begin();
try {
$order = $orderRepository->findById($orderId);
$order->confirm();
$unitOfWork->registerDirty($order);
$payment = Payment::create($order->totalAmount());
$unitOfWork->registerNew($payment);
$unitOfWork->flush();
$unitOfWork->commit();
} catch (\Throwable $e) {
$unitOfWork->rollback();
throw $e;
}
# Symfony services.yaml
Application\Shared\UnitOfWork\UnitOfWorkInterface:
alias: Infrastructure\Persistence\UnitOfWork\DoctrineUnitOfWork
Domain\Shared\UnitOfWork\TransactionManagerInterface:
alias: Infrastructure\Persistence\UnitOfWork\DoctrineTransactionManager
No dedicated table needed — Unit of Work operates on existing aggregate tables. Requires database that supports transactions (PostgreSQL, MySQL with InnoDB).
For complete PHP templates and test examples, see:
references/templates.md — All component templatesreferences/examples.md — Order + Payment transaction example and unit 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.