Skip to content
aurora-cqrs logo

Aurora Cqrs

aurora-cqrs

Aurora CQRS Architecture Reference - Understanding the CQRS structure, component relationships, editable zones, and data flow in Aurora/NestJS projects. Trigger: When needing to understand CQRS architecture, component structure, or editable zones.

SKILL.md

Full skill instructions

When to Use

Use this skill as a REFERENCE when:

  • Understanding CQRS architecture and component relationships
  • Learning what Commands, Queries, Handlers, Events, Sagas are
  • Identifying which zones in generated files are editable
  • Understanding the data flow between layers
  • Learning the structure of Services, Repositories, Aggregates, Mappers

⚠️ For IMPLEMENTING business logic in handlers, use aurora-development skill instead.

This skill is for UNDERSTANDING the architecture. The aurora-development skill is for WRITING code.

What is CQRS in Aurora?

CQRS (Command Query Responsibility Segregation) separates read operations (Queries) from write operations (Commands).

Aurora implements CQRS using NestJS CQRS module with:

  • Commands → Change state (Create, Update, Delete)
  • Queries → Read state (Find, Get, Paginate, Count, etc.)
  • Handlers → Execute commands/​queries
  • Events → Domain events triggered by aggregates
  • Sagas → Coordinate complex workflows

Architecture Layers

┌─────────────────────────────────────────────────────────────┐
│                    @api Layer (REST/​GraphQL)                 │
│  Controllers/​Resolvers → Handlers → dispatch Commands/​Queries│
└─────────────────────────────────────────────────────────────┘
                              ↓
┌─────────────────────────────────────────────────────────────┐
│                   @app/​application Layer                     │
│  Commands → CommandHandlers → Services                       │
│  Queries  → QueryHandlers   → Services                       │
│  Events   → EventHandlers                                    │
│  Sagas    → React to events                                  │
└─────────────────────────────────────────────────────────────┘
                              ↓
┌─────────────────────────────────────────────────────────────┐
│                    @app/​domain Layer                         │
│  Aggregates (Entities with events)                           │
│  Value Objects (Immutable types)                             │
│  Repository Interfaces                                       │
│  Mappers (Domain ↔ Response)                                 │
└─────────────────────────────────────────────────────────────┘
                              ↓
┌─────────────────────────────────────────────────────────────┐
│                @app/​infrastructure Layer                     │
│  Repository Implementations (Sequelize/​TypeORM)              │
│  Seeders, Models                                             │
└─────────────────────────────────────────────────────────────┘

⚠️ @api Handler Responsibility (CRITICAL!)

@api handlers (REST controllers, GraphQL resolvers, handler classes in @api/) have ONE job:

  • ✅ Dispatch commands/​queries via commandBus.dispatch() or queryBus.ask()
  • ✅ Map HTTP/​GraphQL input to command/​query objects
  • ✅ Return response to client

@api handlers MUST NOT contain:

  • ❌ Business validations (status checks, permission rules)
  • ❌ Repository queries (findById, find, get)
  • ❌ State transitions or business rules
  • ❌ Multiple sequential command/​query dispatches with logic between them

If you find yourself writing if/​throw logic in an @api handler, STOP. That logic belongs in a CommandHandler in @app/.

⚠️ WARNING about codebase examples: Some IAM @api handlers (e.g., iam-update-me-account.handler.ts, iam-check-password-me-account.handler.ts) contain business logic directly in @api. These are LEGACY cross-module orchestration handlers, NOT a pattern to replicate. For domain operations (provision, cancel, approve, etc.), ALWAYS create Command + Handler + Service in @app/​application/<operation>/.

Critical Patterns

⚠️ EDITABLE ZONES (CRITICAL!)

In Aurora-generated files, you can ONLY edit the execute() method body in handlers.

DO NOT modify:

  • ❌ Command/​Query class definitions
  • ❌ Service main() methods (unless custom service)
  • ❌ Repository interfaces
  • ❌ Aggregates (entities)
  • ❌ Value Objects
  • ❌ Mappers

Marking Custom Code

Always mark custom code with AI-generated comments:

/​* #region AI-generated code */
// Custom logic here
/​* #endregion AI-generated code */

Detailed References

For detailed structures, types, and handler examples, see:

Decision Trees

When to use Command vs Query?

Operation changes state?
├─ YES → Use Command
│  ├─ Create → CreateXCommand + CreateXCommandHandler
│  ├─ Update → UpdateXCommand + UpdateXCommandHandler
│  ├─ Delete → DeleteXCommand + DeleteXCommandHandler
│  └─ Upsert → UpsertXCommand + UpsertXCommandHandler
│
└─ NO → Use Query
   ├─ Single record → FindXQuery + FindXQueryHandler
   ├─ Multiple records → GetXQuery + GetXQueryHandler
   ├─ Paginated → PaginateXQuery + PaginateXQueryHandler
   └─ Aggregate → CountXQuery / MaxXQuery / MinXQuery / SumXQuery

Where to add custom logic?

Need validation before save?
└─ Add in CommandHandler.execute() before service call

Need to react to events?
└─ Create EventHandler

Need to coordinate multiple operations?
└─ Create Saga

Need to transform data?
└─ Use Mapper

Need custom query logic?
└─ Add in QueryHandler.execute() before/​after service call

Need reusable business logic?
└─ Create custom Service and inject in Handler

Need a domain operation (provision, cancel, approve)?
└─ Create new Command + Handler + Service in @app/​application/<operation>/
   - @api handler ONLY dispatches the command
   - Handler validates business rules
   - Service handles persistence + events

Best Practices

✅ DO

  • Mark all custom code with /​* #region AI-generated code */ comments
  • Only edit execute() method body in handlers
  • Create custom services for reusable logic
  • Use dependency injection for custom services
  • Validate data in command handlers before calling service
  • Use QueryStatement for complex filters
  • Map aggregates to responses in query handlers
  • Apply events in services (created, updated, deleted)
  • Use sagas for cross-aggregate coordination
  • Inject EventPublisher in command services
  • Use Value Objects for type safety

❌ DON'T

  • Don't modify generated Command/​Query classes
  • Don't modify Service main() methods (create custom services instead)
  • Don't modify Repository interfaces
  • Don't modify Aggregates or Value Objects
  • Don't modify Mappers
  • Don't put business logic in services (put in handlers or custom services)
  • Don't bypass repository (always use repository interface)
  • Don't create commands/​queries manually (use Aurora CLI to regenerate)
  • Don't forget to commit events (call aggregate.commit())
  • Don't use direct database access (use repository)

Resources

  • NestJS CQRS: https://docs.nestjs.com/recipes/cqrs
  • Aurora Core: @aurorajs.dev/​core exports CQMetadata, IRepository, etc.
  • Project Structure: .claude/​skills/​aurora-project-structure/​SKILL.md
  • Aurora CLI: .claude/​skills/​aurora-cli/​SKILL.md

Related Skills

  • aurora-development - USE THIS for implementing business logic in handlers
  • aurora-project-structure - Understand where CQRS components live
  • aurora-criteria - Build complex QueryStatements for queries
  • typescript - Type-safe implementation
  • aurora-cli - Regenerate CQRS structure after YAML changes

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View