view-to-query-model

Transform view specs and domain events into CQRS read-model specifications.

1|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/bflandev/threadline-ai --skill view-to-query-model
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: view-to-query-model
Source: https://github.com/bflandev/threadline-ai/tree/main/skills/view-to-query-model
Command: npx skills add https://github.com/bflandev/threadline-ai --skill view-to-query-model

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

In CQRS, aggregates are optimised for enforcing invariants, not serving screens. Querying them directly couples read performance to write-side structure and blocks UI evolution on domain model changes.

A read model is a projection — it consumes domain events and maintains a denormalised, query-optimised representation shaped for one view. Each read model serves a specific view spec, updated asynchronously as events occur.

Core Features & Use Cases

  • Start from the view spec (V-XX) and map fields, filters, and sorts to read model fields.
  • Trace back to source events that create or modify data. A single read model typically consumes events from multiple aggregates.
  • Define the schema, indexes, and staleness tolerance to match UX requirements.
  • Integration test pattern to verify that consuming domain events produces the expected projection state.

Quick Start

Generate the read-model specification RM-XX from the view spec V-XX and related domain events, then create the initial projection tests.

Frequently Asked Questions about view-to-query-model

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

FAQPage Schema
How do I derive read models from view specs in CQRS?

To derive read models from view specs in CQRS, map view spec fields, filters, and sorts to a denormalized schema, trace source domain events, and define indexes and staleness tolerance for the projection.

Why should I use CQRS projections instead of querying aggregates directly?

CQRS projections are needed because querying aggregates directly couples read performance to the write-side structure and blocks UI evolution on domain model changes. Projections consume events to maintain query-optimized representations.

How do I define staleness tolerance and indexes for a CQRS read model?

Define staleness tolerance and indexes for a CQRS read model by mapping UX requirements to the projection schema, ensuring the denormalized view supports the specific filters and sorts requested by the view spec.

How do I test CQRS projections by replaying domain events?

Test CQRS projections by replaying domain events using an integration test pattern that verifies consuming events from multiple aggregates produces the expected projection state and aligns with the read model specification.

Can a single CQRS read model consume domain events from multiple aggregates?

Yes, a single CQRS read model can consume domain events from multiple aggregates. The projection traces back to source events that create or modify data across aggregates to maintain its denormalized view.

What is the best way to map view spec fields to a read model schema?

The best way to map view spec fields to a read model schema is to start from the view spec, apply derivation to map fields directly, identify source events, and define the schema and indexes that match the specific view requirements.