$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
ArchitectureadvancedNew

CQRS Setup

Share

Implement CQRS pattern

Works with OpenClaude

You are an architect implementing the CQRS (Command Query Responsibility Segregation) pattern. The user wants to set up a complete CQRS system with separate command and query handlers, event sourcing integration, and proper separation of concerns.

What to check first

  • Verify your project has a message bus or event dispatcher (MediatR for .NET, simple EventEmitter for Node, or custom implementation)
  • Check if you have a persistent event store or database to track state changes
  • Confirm your read/write data models can be physically separate (different tables, schemas, or databases)

Steps

  1. Create a Command base class that defines an operation requiring side effects (e.g., CreateUserCommand with user data)
  2. Create a Query base class that defines a read-only request returning data (e.g., GetUserByIdQuery with only an ID parameter)
  3. Implement CommandHandler(s) that receive commands, validate input, emit domain events, and persist state
  4. Implement QueryHandler(s) that receive queries, read from a denormalized read model, and return data without modifying state
  5. Set up an EventStore or event log to track all domain events emitted by command handlers
  6. Create UpdatedProjection or ReadModel builders that subscribe to events and update the read-only view when events occur
  7. Configure your command bus/dispatcher to route commands to their handlers and your query bus to route queries to theirs
  8. Add an event publisher that ensures events from commands are persisted before handlers complete

Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

// Command and Query base classes
public abstract class Command { }
public abstract class Query<TResult> { }

public class CreateUserCommand : Command
{
    public string Name { get; set; }
    public string Email { get; set; }
}

public class GetUserByIdQuery : Query<UserReadModel>
{
    public Guid UserId { get; set; }
}

// Domain event
public class UserCreatedEvent
{
    public Guid UserId { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
    public DateTime Timestamp { get; set; }
}

// Write model (command side)
public class CommandHandler
{
    private readonly EventStore _eventStore;
    private readonly EventPublisher _eventPublisher;

    public CommandHandler(EventStore eventStore, EventPublisher eventPublisher)
    {
        _eventStore = eventStore;
        _eventPublisher = eventPublisher;
    }

    public async Task Handle(CreateUserCommand command)
    {
        if (string.IsNullOrEmpty(command.Email)) throw new ArgumentException("Email required");
        
        var @event = new UserCreatedEvent
        {
            UserId = Guid.NewGuid(),
            Name = command.Name,
            Email = command.Email,
            Timestamp = DateTime.

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryArchitecture
Difficultyadvanced
Version1.0.0
AuthorClaude Skills Hub
architecturecqrspattern

Install command:

curl -o ~/.claude/skills/cqrs-setup.md https://claude-skills-hub.vercel.app/skills/architecture/cqrs-setup.md

Related Architecture Skills

Other Claude Code skills in the same category — free to download.

Want a Architecture skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.