Skip to content
acc-create-read-model logo

Read Model / Projection Generator

acc-create-read-model

Generates Read Model/Projection for PHP 8.5. Creates optimized query models for CQRS read side with projections and denormalization. Includes unit tests.

SKILL.md

Full skill instructions

Read Model / Projection Generator

Creates Read Model infrastructure for CQRS read side with optimized query models.

When to Use

ScenarioExample
CQRS read sideSeparate query models
Denormalized viewsDashboard aggregates
Complex queriesMulti-entity joins
Event-driven updatesEvent projections

Component Characteristics

Read Model

  • Optimized for queries
  • Denormalized data
  • Eventually consistent
  • No business logic

Projection

  • Builds read models from events
  • Handles event streams
  • Maintains synchronization
  • Idempotent processing

Repository

  • Query-focused methods
  • Returns read models
  • No write operations

Generation Process

Step 1: Generate Domain Read Model

Path: src/​Domain/​{BoundedContext}/​ReadModel/

  1. {Name}ReadModel.php — Immutable read model with fromArray/​toArray
  2. {Name}ReadModelRepositoryInterface.php — Query-focused repository interface

Step 2: Generate Application Projection

Path: src/​Application/​{BoundedContext}/​Projection/

  1. {Name}ProjectionInterface.php — Projection contract
  2. {Name}Projection.php — Event handlers building read model

Step 3: Generate Infrastructure

Path: src/​Infrastructure/​{BoundedContext}/

  1. Projection/​{Name}Store.php — Store for insert/​update/​upsert
  2. ReadModel/​Doctrine{Name}Repository.php — Repository implementation

Step 4: Generate Tests

  1. {Name}ReadModelTest.php — Read model serialization tests
  2. {Name}ProjectionTest.php — Projection event handling tests

File Placement

ComponentPath
Read Modelsrc/​Domain/​{BoundedContext}/​ReadModel/
Repository Interfacesrc/​Domain/​{BoundedContext}/​ReadModel/
Projection Interfacesrc/​Application/​{BoundedContext}/​Projection/
Projectionsrc/​Application/​{BoundedContext}/​Projection/
Storesrc/​Infrastructure/​{BoundedContext}/​Projection/
Repository Implsrc/​Infrastructure/​{BoundedContext}/​ReadModel/
Unit Teststests/​Unit/

Naming Conventions

ComponentPatternExample
Read Model{Name}ReadModelOrderSummaryReadModel
Repository Interface{Name}ReadModelRepositoryInterfaceOrderSummaryReadModelRepositoryInterface
Projection Interface{Name}ProjectionInterfaceOrderSummaryProjectionInterface
Projection{Name}ProjectionOrderSummaryProjection
Store{Name}StoreOrderSummaryStore
Test{ClassName}TestOrderSummaryProjectionTest

Quick Template Reference

Read Model

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;
}

Projection

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;
}

Usage Example

// Query read model
$orders = $orderSummaryRepository->findByCustomerId($customerId);

// Project event
$projection->project($orderCreatedEvent);

// Reset projection for rebuild
$projection->reset();

Database Schema

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-patterns to Avoid

Anti-patternProblemSolution
Business LogicRead model has behaviorKeep data-only
Write OperationsModifying read modelsUse projections only
Non-idempotentRe-projection breaks dataIdempotent event handling
Missing ResetCan't rebuildAdd reset() method
Tight CouplingProjection depends on domainUse events only

References

For complete PHP templates and examples, see:

  • references/​templates.md — Read model, projection, store templates
  • references/​examples.md — OrderSummary example and tests

More DevOps & CI/CD skills

Project scaffolding, deployment configuration, and CI/CD setup for Google ADK agents.

6K 472.6K
View

Set up tracing, logging, and monitoring for deployed ADK agents across Cloud Trace, BigQuery, and third-party platforms.

6K 472.6K
View

Enterprise Azure infrastructure architect generating Bicep or Terraform from workload descriptions.

1.5K 454.3K
View
azure-kubernetes logo
DevOps & CI/CD

azure-kubernetes

Plan and configure production-ready Azure Kubernetes Service clusters with Day-0 and Day-1 best practices.

1.5K 447.1K
View

Raw mechanical interfaces fusing Swiss typographic print with military terminal aesthetics. Rigid grids, extreme type scale contrast, utilitarian color, analog degradation effects. For data-heavy dashboards, portfolios, or editorial sites that need to feel like declassified blueprints.

92.7K 354.9K
View
just-scrape logo
DevOps & CI/CD

just-scrape

Web search, scraping, extraction, crawling, and monitoring via ScrapeGraph AI CLI.

69 245K
View

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

462 159.7K
View

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

462 159.1K
View
deploy-to-vercel logo
DevOps & CI/CD

deploy-to-vercel

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

31.9K 146.6K
View
programmatic-seo logo
DevOps & CI/CD

programmatic-seo

Build SEO-optimized pages at scale using templates, data, and proven playbook patterns.

53.3K 140.1K
View

Design and build isolated, reusable Convex backend components with clear boundaries and app-facing wrappers.

63 123.5K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
I
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View