CQRS Command Query Generator

Generate CQRS commands, queries, handlers, and read models with class-validator DTOs.

Updated Oct 31, 2025
One-click install
npx skills add https://github.com/RomualdP/hoki --skill cqrs-command-query-generator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: CQRS Command Query Generator
Source: https://github.com/RomualdP/hoki/tree/main/.claude/skills/cqrs-command-query
Command: npx skills add https://github.com/RomualdP/hoki --skill cqrs-command-query-generator

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires class-validator, @nestjs/common.

What problem does it solve?

This Skill implements Command Query Responsibility Segregation (CQRS) to clearly separate read and write operations in the backend, improving scalability, optimizing data payloads, and enhancing maintainability by isolating concerns.

Core Features & Use Cases

  • Commands (Write Operations): Defines DTOs and handlers for operations that modify the system's state (e.g., CreateClubCommand), returning minimal payloads like an ID.
  • Queries (Read Operations): Defines DTOs and handlers for operations that read data (e.g., ListClubsQuery), returning optimized Read Models for the UI.
  • Read Models: Guides on creating lightweight, UI-specific DTOs that can aggregate data from multiple entities without exposing raw domain models.
  • Use Case: When a user wants to create a new club, a CreateClubCommand is dispatched. When they want to view a list of clubs, a ListClubsQuery is executed, returning a ClubListReadModel optimized for display, without affecting the write path.

Quick Start

To create a new write operation, define a CreateXCommand DTO with class-validator and a CreateXHandler that orchestrates domain entities. For a read operation, define a GetXQuery and a GetXHandler that returns a XReadModel interface.

Frequently Asked Questions about CQRS Command Query Generator

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

FAQPage Schema
How do I separate read and write operations in my NestJS backend?

CQRS (Command Query Responsibility Segregation) separates read and write operations by routing writes through immutable command DTOs and handlers, and reads through query DTOs that return optimized read models. This division improves scalability and isolates concerns in your application layer.

What's the best way to structure commands and queries with class-validator?

Define commands as immutable DTOs validated with class-validator decorators, with handlers that return minimal payloads (IDs or booleans). Define queries as DTOs with handlers that return read models—lightweight, UI-specific data structures optimized for display without modifying state.

When should I use read models instead of returning domain entities?

Use read models when you need UI-optimized data structures that aggregate information from multiple entities without exposing raw domain models. Read models decouple your read path from write operations, enabling independent scaling and clearer contracts between layers.

Can I co-locate command and query handlers in NestJS modules?

Yes. CQRS encourages co-locating handlers with their command or query definitions within feature modules, keeping business logic in the domain and maintaining clear separation between write and read concerns while preserving repository-based persistence patterns.

How do commands and queries improve backend performance?

By separating writes from reads, you optimize each path independently—commands focus on minimal state changes while queries return only required fields in read models. This reduces data payloads, enables read-specific caching, and scales read and write paths separately.