本文へ移動
cccskills
無料GitHub で公開

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.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md4.9 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

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

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Master backend architectures, REST API design, microservices, and server-side development across multiple languages. Use this as a central index to access specialized sub-skills.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

在每次回复中使用固定前缀并列出本次实际参考的指令/文件,便于校验是否遵循上下文与规则。

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

Automate 21risk tasks via Rube MCP (Composio). Always search tools first for current schemas.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

Automate 2chat tasks via Rube MCP (Composio). Always search tools first for current schemas.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

Arquitecto de Soluciones Principal y Consultor Tecnológico de Andru.ia. Diagnostica y traza la hoja de ruta óptima para proyectos de IA en español.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

[00] META. Orchestrate skills into dynamic chains for complex tasks. Analyzes the task, discovers available skills, builds an optimal chain, explains why each skill is needed, and executes step-by-step with user confirmation. Use for any complex task requiring multiple thinking/research/analysis steps. Triggers on "plan this", "how to approach", "what's the strategy", "build a plan", or any multi-step problem requiring skill orchestration.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

MikeCheng1208 のスキルをすべて見る

このスキルの問題を報告する