cratis/ai.distribution/cratis-readmodel
Claude Code and agent skill by cratis/ai.distribution
- community
Checking that the SKILL.md file is still in the repository.
Step-by-step guidance for creating a Cratis Chronicle read model from scratch — defining events, choosing between projection and reducer, [ReadModel] record with static query methods, and the generated TypeScript proxy in React. Use when creating a read model, working with [EventType], [ReadModel], IProjectionFor, IReducerFor, observable queries, or deriving state from events. For adding a projection or reactor to an existing read model, use add-projection instead.
Install
npx vskill@latest install cratis/ai.distribution/cratis-readmodelSKILL.md
The same SKILL.md was published earlier as cratis/ai.distribution/cratis-readmodel.
Creating a Cratis Read Model
A read model is derived state built from events. The path is:
Step 1 — Define your events
Events are the source of truth. Define each as a record decorated with [EventType]. Name them in past tense.
Good event design:
- One clear purpose per event — do not mix concerns.
- Avoid nullable properties — Chronicle's analyzer warns on them; model an optional fact as a separate event.
- Properties are concept-typed facts (never raw
Guid/string), and never carry the event-source id.
Step 2 — Define the read model record
Decorate the record with [ReadModel] and add static query methods directly on it. The proxy generator turns each static method into a TypeScript query class.
Rules:
[ReadModel]attribute is required for proxy generation and runtime routing- Static methods must be
public staticand return the record type, a collection of it, orISubject<T>for real-time push - Do not return
Task<ISubject<T>>— observable methods must returnISubject<T>directly - Use
ConceptAs<T>wrappers for all identity fields — never rawGuid - One read model per use case — do not reuse them
Step 3 — Choose: projection or reducer?
| Projection | Reducer | ||
|---|---|---|---|
| Best for | Shaped read models with mapping logic, joins, children | Running aggregates: balances, counts, sums | |
| How it works | Declarative mapping: each event updates specific fields | Receives events one by one and returns the new full state | |
| When to pick | The read model shape comes mostly from mapping event fields | The state is a function of accumulating multiple events |
For the AccountSummary above: use a projection for name/owner fields and a reducer for balance (a running total). In practice, reducers cover both when the aggregate combines both concerns.
Step 4A — Implement a projection
- AutoMap is on by default — never call `.AutoMap()`. Matching property names (e.g.
Name,OwnerId) map automatically from.From<DebitAccountOpened>(); only.Set().To()the ones whose names differ. - Discovered automatically — no registration needed.
IProjectionFor<T>is keyed by event source ID by default (theIdpassed when appending the event).- Appended
tags,eventSourceType, andeventStreamTypedo not filter projections directly; use reducers or reactors alongside the projection when you need metadata-based filtering - See
references/projections.mdfor joins, auto-mapping, children, composite keys
Model-bound shorthand (preferred for simple cases)
[FromEvent<T>] is a class-level attribute declaring which event populates the model; property mapping is implicit via AutoMap (matching names) or explicit per-property with [SetFrom<T>]. The model needs [ReadModel], and the key is the event-source id (no [Key] needed when the id property is the EventSourceId<T> identity).
[FromEvent<T>]goes on the class, not a property. Property-level mapping uses[SetFrom<T>], and only for genuine name differences — never call `.AutoMap()`; matching names map automatically.- Add more
[FromEvent<T>]attributes to fold in additional events.
Step 4B — Implement a reducer
Use a reducer when the state is built by accumulating values across events:
- Return the complete new state — do not mutate
current currentisnullon the first event for a given event sourceEventContextprovidesOccurred,EventSourceId,SequenceNumber,CorrelationId- Discovered automatically — no registration needed
- Add
[FilterEventsByTag],[EventSourceType], and[EventStreamType]when the reducer should only observe events appended with matching metadata
Step 5 — Expose read model queries
Query methods live directly on the `[ReadModel]` record as static methods (see Step 2). You do not need a separate controller or IReadModels injection.
The method name becomes the TypeScript proxy class name — use descriptive names like AllAccounts, GetAccount, ObserveAllAccounts.
Snapshot (one-time) queries
Observable (real-time push) queries
Return ISubject<T> to push updates as projection changes land:
When the frontend uses an observable query, the query proxy type changes from QueryFor to ObservableQueryFor. The same `query` prop accepts a standard or observable query — there is no separate observableQuery prop; DataPage auto-detects it and subscribes to live updates.
Step 6 — Build and use in React
For building full pages with filtering, sorting, and command actions — see the cratis-react-page skill.
Reference files
| File | What's in it | |
|---|---|---|
references/projections.md | Full builder API: Set, Add, Join, Children, AutoMap, composite keys | |
references/reducers.md | Reducer signatures, async, passive, snapshot behavior | |
references/events.md | [EventType], appending, AppendResult, tags, constraints | |
references/queries.md | Query result shape, observable queries, paging |
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cratis-readmodel/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/cratis/ai.distribution/cratis-readmodel)