cqrs
Skill15 starsChanged 44 days agoMITView on GitHub
Expert CQRS (Command Query Responsibility Segregation) assistance covering command handlers, read projections, event denormalization, and asymmetric scaling. Use when separating read and write models, optimizing read performance, or pairing with Event Sourcing.
3 other projects use a version of this.
Adopted by
Most recently taken up by
- AnyOrgName/php-skillstheir own version, first seen Nov 8, 2026
- TheBeardedBearSAS/claude-crafttheir own version, first seen Oct 29, 2026
- troskater/flowdeck-claudetheir own version, first seen Oct 25, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- TheBeardedBearSAS/claude-craft★ 108same name
- AnyOrgName/php-skills★ 4same name
- troskater/flowdeck-claude★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository350 other files it gives its agents.
- airflowSkill
- catboostSkill
- claudeSkill
- comfyuiSkill
- cursor-aiSkill
- dalleSkill
- daskSkill
- dbtSkill
- deepseekSkill
- fastaiSkill
- geminiSkill
- github-copilotSkill
- huggingfaceSkill
- jaxSkill
- jupyterSkill
- kerasSkill
- langchainSkill
- lightgbmSkill
- llamaindexSkill
- llamaSkill
- matplotlibSkill
- midjourneySkill
- mistralSkill
- mlflowSkill
- nltkSkill
- numpySkill
- ollamaSkill
- openai-gptSkill
- opencvSkill
- pandasSkill
- perplexitySkill
- plotlySkill
- polarsSkill
- pytorchSkill
- raySkill
- scikit-learnSkill
- seabornSkill
- spacySkill
- sparkSkill
- stable-diffusionSkill
- tensorflowSkill
- vaexSkill
- weights-biasesSkill
- whisperSkill
- xgboostSkill
- api-gatewaySkill
- clean-architectureSkill
- domain-driven-designSkill
- event-drivenSkill
- event-sourcingSkill
- graphqlSkill
- grpcSkill
- hexagonalSkill
- microservicesSkill
- modular-monolithSkill
- monolithSkill
- rest-apiSkill
- sagaSkill
- serverlessSkill
- service-meshSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Pairing with Event Sourcing: When state changes are captured as events and read models are asynchronously projected from event streams.
- Distinctive: line 101
Use an asynchronous projector to update a de-normalized, query-optimized document or key-value store:
- Distinctive: line 131
Use Dedicated Read Replicas: Direct query handlers to read replicas or fast key-value caches to protect the write primary.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CQRS (Command Query Responsibility Segregation)
CQRS is a pattern that separates read and update operations for a data store. Instead of using a single model for both, you have a Command Model (Write) and a Query Model (Read).
When to Use
- Asymmetric Read/Write Workloads: Systems where reads outnumber writes by 100:1 or 1000:1 and require independent horizontal scaling.
- Complex Reporting & Search Views: Aggregating data across multiple aggregates into denormalized read stores (Elasticsearch, Read Replicas).
- Collaboration & High Concurrency: Optimizing write performance and transactional consistency while delivering instant query responses.
- Pairing with Event Sourcing: When state changes are captured as events and read models are asynchronously projected from event streams.
Quick Start
// Command Side (Write) - Optimized for Integrity
class CreateOrderCommand { ... }
class OrderAggregate {
create(cmd: CreateOrderCommand) {
// Validate business rules
// Save to DB (Normalized / Event Store)
}
}
// Query Side (Read) - Optimized for Speed
class GetOrderSummaryQuery { ... }
class OrderSummaryProjector {
// Listens to "OrderCreated" event
on(event) {
// Update a flat "Read DB" (e.g., ElasticSearch, Redis, Document DB)
// optimized for the specific UI view
}
}Core Concepts
Separation of Command and Query Models
Commands represent intent to mutate state (void return or ID); Queries request data without side effects:
Client
├── Command: POST /orders (CreateOrderCommand) ──→ Command Handler ──→ Write DB (Postgres)
│ │ (CDC / Events)
└── Query: GET /orders/summary (OrderSummary) ←── Read Handler ←── Read DB (Elastic/Redis)Command Handlers with Explicit Domain Mutex
Validates permissions and business invariants before committing writes:
// commands/cancel-order.command.ts
export interface CancelOrderCommand {
orderId: string;
reason: string;
requestedByUserId: string;
}
export class CancelOrderCommandHandler {
constructor(private readonly orderRepo: OrderRepositoryPort) {}
async handle(cmd: CancelOrderCommand): Promise<void> {
const order = await this.orderRepo.getById(cmd.orderId);
if (!order) throw new Error("Order not found");
order.cancel(cmd.reason, cmd.requestedByUserId);
await this.orderRepo.save(order);
}
}Materialized Read Projections
Updates optimized denormalized read views in response to domain events:
// projections/order-dashboard.projection.ts
export class OrderDashboardProjection {
async onOrderCancelled(event: OrderCancelledEvent): Promise<void> {
await redis.hset(`dashboard:order:${event.orderId}`, {
status: "CANCELLED",
cancelledAt: event.timestamp,
cancellationReason: event.reason,
});
}
}Common Patterns
Read-Model Projection with Event Handlers
Problem: Queries require aggregated data from multiple write models, causing slow and complex database joins.
Solution: Use an asynchronous projector to update a de-normalized, query-optimized document or key-value store:
interface OrderCreatedEvent {
orderId: string;
customerId: string;
total: number;
createdAt: string;
}
class OrderReadModelProjector {
async handleOrderCreated(event: OrderCreatedEvent): Promise<void> {
await searchIndex.upsert("orders_summary", event.orderId, {
id: event.orderId,
customerId: event.customerId,
totalAmount: event.total,
placedAt: event.createdAt,
status: "PLACED",
});
}
}Best Practices
Do:
- Make Queries Completely Side-Effect Free: Ensure queries never mutate database state or trigger transactional locks.
- Embrace Eventual Consistency: Design client user experiences to anticipate small projection delays (optimistic UI updates).
- Optimize Read Models for the UI: Structure read tables/documents to match the exact view model needed by frontend clients.
- Use Dedicated Read Replicas: Direct query handlers to read replicas or fast key-value caches to protect the write primary.
Don't:
- Apply CQRS globally to an entire system: Apply CQRS only to bounded contexts with complex requirements; simple CRUD benefits from standard MVC.
- Share entities between Command and Query pipelines: Keep query handlers completely independent of domain aggregate classes.
- Let read projections write back to the write store: Keep the data pipeline unidirectional.
Troubleshooting
| Error | Cause | Solution |
Stale Data | Lag between Command execution and Query update. | UI design updates (spinners/optimistic updates); Check projector lag. |
Complexity | Over-engineering. | Revert to simple CRUD if the domain doesn't warrant separation. |
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

