# Apply CQS and CQRS Patterns in .NET

Teams often mix state changes and data reads, which makes code harder to test and reason about. This skill guides clear CQS and CQRS designs for .NET methods, handlers, and controllers.

## Install

```bash
npx skillstore add doubleslashse/cqs-patterns
```

## Metadata

- Status: approved
- Slug: doubleslashse-cqs-patterns
- Skillstore revision: r1
- Version status: missing
- Tree hash: 31c491a761c499d8e3063ed4e6527ad3205dcde7a55cbaa1605ea1881d04fce6
- Author: DoubleslashSE
- GitHub username: DoubleslashSE
- License: MIT
- Repository: https://github.com/DoubleslashSE/claude-workflows/tree/main/Plugins/dotnet-tdd/skills/cqs-patterns
- Ref: 72d5025b022c77f7a51bdf5c1637c689c80e89d1
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands
- Quality score: 77
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/doubleslashse-cqs-patterns
- Manifest: https://skillstore.pages.dev/api/skills/doubleslashse-cqs-patterns/manifest

## Capabilities

- Explains the difference between commands that change state and queries that return data.
- Provides C\# examples for method-level CQS violations and corrected designs.
- Shows CQRS command, query, handler, dispatcher, and controller patterns.
- Lists practical exceptions such as atomic operations, fluent APIs, and factory methods.
- Helps decide when CQRS is useful and when simple CRUD is enough.

## Use Cases

- Separate Service Methods: Review service methods that both modify state and return domain data, then split them into clearer commands and queries.
- Design CQRS Handlers: Create command and query records with matching handlers for a .NET application layer.
- Review Architecture Complexity: Decide whether a feature needs CQRS or whether simpler CRUD patterns are more appropriate.

## Prompt Templates

### Identify CQS Violations

```
Review this .NET class for CQS violations. Identify methods that both change state and return data, then suggest simpler names and responsibilities.
```

### Refactor to Commands and Queries

```
Refactor this service API into separate command and query operations. Keep behavior equivalent and explain each new responsibility.
```

### Design a CQRS Application Layer

```
Design a CQRS application layer for this feature. Include command records, query records, handler responsibilities, and controller flow.
```

### Evaluate CQRS Tradeoffs

```
Assess whether CQRS fits this system. Compare benefits, added complexity, testing impact, read model needs, and alternatives.
```

## Limitations

- Focuses on .NET and C\# examples, not other language ecosystems.
- Does not provide a complete production framework or package.
- Does not cover database migration, deployment, or infrastructure setup.
- Requires users to adapt examples to their domain model and persistence layer.

## Best Practices

- Name commands with imperative verbs and queries with read-oriented names.
- Keep queries free of side effects so they are safe to repeat.
- Use CQRS when read and write paths have different models, scale, or rules.

## Anti Patterns

- Returning full domain objects from methods that also persist changes.
- Adding CQRS to simple CRUD screens without a clear need.
- Hiding state changes inside getters, calculated properties, or query handlers.

## Security Audit

- Audited at: 2026-07-06T11:22:15.57\+00:00
- Summary: All static findings appear to be false positives caused by Markdown code fences, ASCII diagrams, and C\# examples in documentation. I found no prompt injection, data exfiltration intent, executable scripts, network behavior, or real system reconnaissance in SKILL.md.

## Stats

- Views: 194
- Downloads: 7
- Favorites: 0
- Popularity score: 0
