implement-cqrs-pattern

Implement CQRS with aggregates, domain events, and projections for read models.

Updated Oct 27, 2025
One-click install
npx skills add https://github.com/mariotoffia/gobridge --skill implement-cqrs-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: implement-cqrs-pattern
Source: https://github.com/mariotoffia/gobridge/tree/main/.cursor/skills/implement-cqrs-pattern
Command: npx skills add https://github.com/mariotoffia/gobridge --skill implement-cqrs-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a structured blueprint for implementing CQRS in a domain-driven design. It explains how to separate the write model (aggregates and domain events) from the read models (denormalized projections) and how to wire events into projections to support fast, query-optimized reads.

Core Features & Use Cases

  • Command model with aggregates and domain events: write operations mutate state via aggregates that emit events.
  • Projections for read models: events update dashboard and analytics views without touching the write model.
  • Query handlers for reads: retrieve pre-computed views (dashboard, analytics, lists) efficiently.
  • Use Case: heating-building domain uses HeatingBuilding aggregates and HeatingOptimized events to populate BuildingDashboardView and BuildingAnalyticsView for real-time monitoring.

Quick Start

Define the HeatingBuilding aggregate and its command handlers, emit HeatingOptimized events, and wire projections to update the read models. Implement GetBuildingDashboardHandler and GetBuildingAnalyticsHandler to query the views, and ensure views can be rebuilt by replaying events.

Frequently Asked Questions about implement-cqrs-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I separate read and write models using CQRS and domain events?

CQRS separates write models via aggregates that emit domain events from read models using projections. You wire domain events into projections to populate query-optimized views for dashboards and analytics without touching the write model.

How do I build fast read models for dashboards from event-driven architectures?

You build fast read models by creating projections that listen to domain events emitted by aggregates. These projections update denormalized views, allowing query handlers to retrieve pre-computed dashboard and analytics data efficiently.

When should I use CQRS with event sourcing in domain-driven design?

Use CQRS with event sourcing when you have distinct read and write workloads in a domain-driven design. It enforces aggregates as the source of truth while enabling read-optimized views via projections for real-time monitoring and analytics.

Can I rebuild read models by replaying events in a CQRS architecture?

Yes, you can rebuild read models by replaying events. The architecture uses event sourcing where aggregates emit domain events, allowing projections to reconstruct dashboard and analytics views from the event history.

How do query handlers retrieve data in a CQRS pattern?

Query handlers retrieve pre-computed views directly from read models. They query denormalized projections populated by domain events, ensuring fast reads for dashboards, analytics, and lists without accessing the write model.

What is the difference between aggregates and projections in CQRS?

Aggregates handle write operations and mutate state by emitting domain events as the source of truth. Projections consume those events to update denormalized read models, optimizing queries for dashboards and analytics.