Generates Read Model/Projection for PHP 8.4. Creates optimized query models for CQRS read side with projections and denormalization. Includes unit tests.
From accnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accThis skill uses the workspace's default tool permissions.
references/event-sourcing-projections.mdreferences/examples.mdreferences/templates.mdCreates Read Model infrastructure for CQRS read side with optimized query models.
| Scenario | Example |
|---|---|
| CQRS read side | Separate query models |
| Denormalized views | Dashboard aggregates |
| Complex queries | Multi-entity joins |
| Event-driven updates | Event projections |
Path: src/Domain/{BoundedContext}/ReadModel/
{Name}ReadModel.php — Immutable read model with fromArray/toArray{Name}ReadModelRepositoryInterface.php — Query-focused repository interfacePath: src/Application/{BoundedContext}/Projection/
{Name}ProjectionInterface.php — Projection contract{Name}Projection.php — Event handlers building read modelPath: src/Infrastructure/{BoundedContext}/
Projection/{Name}Store.php — Store for insert/update/upsertReadModel/Doctrine{Name}Repository.php — Repository implementation{Name}ReadModelTest.php — Read model serialization tests{Name}ProjectionTest.php — Projection event handling tests| Component | Path |
|---|---|
| Read Model | src/Domain/{BoundedContext}/ReadModel/ |
| Repository Interface | src/Domain/{BoundedContext}/ReadModel/ |
| Projection Interface | src/Application/{BoundedContext}/Projection/ |
| Projection | src/Application/{BoundedContext}/Projection/ |
| Store | src/Infrastructure/{BoundedContext}/Projection/ |
| Repository Impl | src/Infrastructure/{BoundedContext}/ReadModel/ |
| Unit Tests | tests/Unit/ |
| Component | Pattern | Example |
|---|---|---|
| Read Model | {Name}ReadModel | OrderSummaryReadModel |
| Repository Interface | {Name}ReadModelRepositoryInterface | OrderSummaryReadModelRepositoryInterface |
| Projection Interface | {Name}ProjectionInterface | OrderSummaryProjectionInterface |
| Projection | {Name}Projection | OrderSummaryProjection |
| Store | {Name}Store | OrderSummaryStore |
| Test | {ClassName}Test | OrderSummaryProjectionTest |
final readonly class {Name}ReadModel
{
public function __construct(
public string $id,
// ... denormalized properties
public \DateTimeImmutable $createdAt,
public \DateTimeImmutable $updatedAt
) {}
public static function fromArray(array $data): self;
public function toArray(): array;
}
final class {Name}Projection implements {Name}ProjectionInterface
{
public function project(DomainEventInterface $event): void
{
match ($event::class) {
OrderCreated::class => $this->whenOrderCreated($event),
OrderShipped::class => $this->whenOrderShipped($event),
default => null,
};
}
public function reset(): void;
public function subscribedEvents(): array;
}
// Query read model
$orders = $orderSummaryRepository->findByCustomerId($customerId);
// Project event
$projection->project($orderCreatedEvent);
// Reset projection for rebuild
$projection->reset();
CREATE TABLE order_summaries (
id VARCHAR(36) PRIMARY KEY,
order_number VARCHAR(50) NOT NULL UNIQUE,
customer_id VARCHAR(36) NOT NULL,
customer_name VARCHAR(255) NOT NULL,
status VARCHAR(50) NOT NULL,
total_cents BIGINT NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
INDEX idx_customer (customer_id),
INDEX idx_status (status)
);
| Anti-pattern | Problem | Solution |
|---|---|---|
| Business Logic | Read model has behavior | Keep data-only |
| Write Operations | Modifying read models | Use projections only |
| Non-idempotent | Re-projection breaks data | Idempotent event handling |
| Missing Reset | Can't rebuild | Add reset() method |
| Tight Coupling | Projection depends on domain | Use events only |
For complete PHP templates and examples, see:
references/templates.md — Read model, projection, store templatesreferences/examples.md — OrderSummary example and testsreferences/event-sourcing-projections.md — Event replay projections, versioning, checkpoint tracking, async workersProvides 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.