Help us improve
Share bugs, ideas, or general feedback.
How this skill is triggered — by the user, by Claude, or both
Slash command
/acc:create-read-modelThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Creates Read Model infrastructure for CQRS read side with optimized query models.
Generates CQRS-compliant queries, handlers, DTOs, read model interfaces, and unit tests for PHP 8.4. Creates immutable read-only operations for single, list, search, and count queries with pagination.
Build read models and projections from event streams. Implements CQRS read sides, materialized views, and optimizes query performance in event-sourced systems.
Builds read models and projections from event streams for CQRS read sides, materialized views, query optimization, real-time dashboards, and search indexes in event-sourced systems.
Share bugs, ideas, or general feedback.
Creates 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 workers