# Cqrs Implementation > Implement Command Query Responsibility Segregation for scalable architectures. Use when separating read and write models, optimizing query performance, or building event-sourced systems. Source: https://skillsagentes.com/skills/wshobson/agents/cqrs-implementation Repository: https://github.com/wshobson/agents Author: wshobson License: MIT Updated: hace 2 meses Context cost: 47 tok installed, 862 tok once triggered, 4k tok with every bundled file Bundle: 2 files, 16 KB Permissions requested: none declared ## Install ```bash npx -y skills add wshobson/agents --skill cqrs-implementation --agent claude-code ``` ## What it does - Guía la separación de comandos y consultas en arquitecturas CQRS - Define componentes clave: Command, Command Handler, Event, Query, Query Handler, Projector - Proporciona buenas prácticas de diseño y errores comunes a evitar - Remite a `references/details.md` para plantillas y ejemplos detallados ## Use it when - Separar responsabilidades de lectura y escritura - Escalar lecturas de forma independiente a las escrituras - Construir sistemas basados en event sourcing - Optimizar escenarios de consultas complejas ## What triggers it - "Ayúdame a implementar CQRS en mi sistema" - "Cómo separo el modelo de lectura y escritura en mi arquitectura" - "Necesito diseñar comandos y eventos para un sistema event-sourced" ## Before you install - Consultar `references/details.md` para plantillas y ejemplos concretos. ## Files - SKILL.md — 3 KB - references/details.md — 12 KB ## SKILL.md Reproduced verbatim from wshobson/agents under MIT. This section is the upstream document and is in English. # CQRS Implementation Comprehensive guide to implementing CQRS (Command Query Responsibility Segregation) patterns. ## When to Use This Skill - Separating read and write concerns - Scaling reads independently from writes - Building event-sourced systems - Optimizing complex query scenarios - Different read/write data models needed - High-performance reporting requirements ## Core Concepts ### 1. CQRS Architecture ``` ┌─────────────┐ │ Client │ └──────┬──────┘ │ ┌────────────┴────────────┐ │ │ ▼ ▼ ┌─────────────┐ ┌─────────────┐ │ Commands │ │ Queries │ │ API │ │ API │ └──────┬──────┘ └──────┬──────┘ │ │ ▼ ▼ ┌─────────────┐ ┌─────────────┐ │ Command │ │ Query │ │ Handlers │ │ Handlers │ └──────┬──────┘ └──────┬──────┘ │ │ ▼ ▼ ┌─────────────┐ ┌─────────────┐ │ Write │─────────►│ Read │ │ Model │ Events │ Model │ └─────────────┘ └─────────────┘ ``` ### 2. Key Components | Component | Responsibility | | ------------------- | ------------------------------- | | **Command** | Intent to change state | | **Command Handler** | Validates and executes commands | | **Event** | Record of state change | | **Query** | Request for data | | **Query Handler** | Retrieves data from read model | | **Projector** | Updates read model from events | ## Templates and detailed worked examples Full template library and detailed worked examples live in `references/details.md`. Read that file when you need the concrete templates. ## Best Practices ### Do's - **Separate command and query models** - Different needs - **Use eventual consistency** - Accept propagation delay - **Validate in command handlers** - Before state change - **Denormalize read models** - Optimize for queries - **Version your events** - For schema evolution ### Don'ts - **Don't query in commands** - Use only for writes - **Don't couple read/write schemas** - Independent evolution - **Don't over-engineer** - Start simple - **Don't ignore consistency SLAs** - Define acceptable lag --- Skills Agentes — https://skillsagentes.com/skills/wshobson/agents/cqrs-implementation