cqrs-implementation

Implement CQRS patterns separating command and query models in Python applications.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill cqrs-implementation-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cqrs-implementation
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/cqrs-implementation
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill cqrs-implementation-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires fastapi, pydantic.

What problem does it solve? Building systems where read and write workloads have different scaling and modeling needs is difficult with a single data model. This Skill provides templates for separating commands from queries so each side can be optimized, scaled, and evolved independently. ## Core Features & Use Cases - Command Infrastructure: Base classes for commands, command handlers, and a command bus with validation before state changes. - Query Infrastructure: Query handlers, paginated result types, and denormalized read models optimized for fast retrieval. - FastAPI Integration: Ready-to-adapt endpoints routing writes through the command bus and reads through the query bus. - Use Case: When building an order management system with high read traffic, use this Skill to split the write model (order creation, cancellation) from a denormalized read model (order views, customer order history) synchronized via event projections. ## Quick Start Ask the AI to implement a CQRS architecture for an order service with separate command handlers, query handlers, and a FastAPI API layer.

Frequently Asked Questions about cqrs-implementation

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

FAQPage Schema
How do I implement CQRS in Python?

Define separate Command and Query dataclasses, register handlers in a CommandBus and QueryBus, and dispatch operations through the appropriate bus. Commands mutate the write model and emit events, while queries read from denormalized read models.

How to use CQRS with FastAPI?

Inject the command bus into POST, PUT, and DELETE endpoints and the query bus into GET endpoints using FastAPI dependency injection. Commands return identifiers or status, while queries return view models like paginated order results.

What is the difference between a command and a query in CQRS?

A command expresses intent to change state and is validated and executed by a command handler against the write model. A query only retrieves data from the read model and never modifies state, allowing each side to use different schemas.

How do I keep read models in sync with events?

Use a read model synchronizer that polls the event store from a saved checkpoint and applies matching events to projections. Checkpoints track the last processed position, and projections can be rebuilt from scratch by resetting the checkpoint.

How do I handle eventual consistency in CQRS?

For read-your-writes scenarios, poll the projection version until it reaches the expected event version before executing the query, with a timeout fallback. Define acceptable lag SLAs and return stale data with a warning when the timeout expires.

When should I not use CQRS?

Avoid CQRS for simple CRUD applications where read and write needs are identical, since it adds event handling, projection, and consistency complexity. Start simple and adopt CQRS only when read/write scaling or modeling requirements genuinely diverge.