agentleFS
TheBeardedBearSASTheBeardedBearSAS/claude-craft/.claude/skills/cqrs/SKILL.md

cqrs

Skill108 starsChanged 6 days agoMITView on GitHub

CQRS - Command Query Responsibility Segregation. Use when implementing DDD patterns, separating read/write models, event sourcing, or building scalable architectures with heterogeneous performance requirements.

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

CQRS — Quick Reference

CQRS (Command Query Responsibility Segregation) sépare les opérations d'écriture et de lecture dans des modèles distincts. N'est pas par défaut — c'est une optimisation à activer quand le coût de la complexité est justifié.

Quand utiliser

PertinentPas pertinent
Domaine métier complexe avec règles d'invariants richesCRUD simple, domaine pauvre
Ratio lectures/écritures > 10×Petits projets, équipe junior
Audit / compliance (Event Sourcing naturel)Cohérence immédiate requise
Read models hétérogènes (mobile vs analytics vs back-office)Modèle de données stable et unique
Scale différencié reads vs writes (replicas, cache, search)Charge faible, monolithe modeste

Règle d'or : commencer par une architecture classique. Migrer vers CQRS lorsqu'au moins 2 des cas pertinents sont présents simultanément.

Architecture en 30 secondes

[ User ]
   ↓
[ Command ]──────────▶ [ Write Model (Domain) ]
                              ↓ persist + emit
                       [ Event(s) ]
                              ↓
[ Query ] ◀───── [ Read Model (denormalised) ] ◀── projections
  • Command side : modèle normalisé, focus invariants métier. Écrit, ne lit que ce qui est nécessaire à la validation.
  • Query side : modèle dénormalisé, focus performance lecture. N'a pas de logique métier.
  • Projections : transforment les events en read models. Eventually consistent.

Trade-off central

BénéficeCoût
Scale indépendant lecture / écritureEventual consistency (≈ 50-500 ms latency typique)
Read models taillés pour chaque besoinPlus de code à maintenir (2 modèles)
Event Sourcing devient facile à brancherDebugging plus complexe (event flow)
Audit trail naturelMigration tardive très coûteuse

Patterns associés (souvent ensemble)

  • Event Sourcing : stocker la séquence d'events comme source de vérité, le write model est reconstruit en replay.
  • Saga / Process Manager : orchestrer des transactions distribuées via events.
  • Outbox Pattern : garantir l'atomicité publication event + write DB.
  • Materialized Views : projections persistées en table dédiée pour query speed.

Anti-patterns critiques

  • ❌ CQRS sans cas d'usage clair → over-engineering, double charge cognitive.
  • ❌ Read model qui exécute des règles métier → bug d'invariants à chaque projection.
  • ❌ Projections synchrones → on perd le bénéfice scalability.
  • ❌ Event Sourcing sans snapshots → replay de millions d'events au boot.
  • ❌ Command qui retourne data complète → c'est une Query déguisée.

Pour aller plus loin

Implémentations Symfony / Laravel / .NET, Event Sourcing (Prooph, KurrentDB 26.2.3, ex-EventStoreDB), saga patterns, outbox, exemples concrets, migration progressive d'un CRUD vers CQRS, checklists par phase : voir @.claude/skills/cqrs/REFERENCE.md.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.