projection-go

Create Go read-side projections with ApplyX methods, repository interfaces, and Postgres implementations.

4|Updated Jul 30, 2026
One-click install
npx skills add https://github.com/gabriellst/codm --skill projection-go-gabriellst
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: projection-go
Source: https://github.com/gabriellst/codm/tree/main/.claude/skills/projection/go
Command: npx skills add https://github.com/gabriellst/codm --skill projection-go-gabriellst

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building CQRS read models in Go often leads to inconsistent patterns: leaked mutation logic, shared base classes, and unjustified atomic operations. This Skill enforces a canonical structure for projections — free record structs driven by projectors through the find → ApplyX → save flow. ## Core Features & Use Cases - Projection Struct Design: Plain Go structs with exported fields and db tags, no base classes or domain events, with ApplyX methods owning per-event transition logic. - Repository Contracts: Minimal per-projection interfaces (FindByKey, Save, InsertIfNew) with Postgres implementations, in-memory mocks, and fx wiring guidance. - Atomic Ops Governance: Rules for when atomic operations are justified (hot-row contention, bulk updates, monotonic constraints) with mandatory trigger documentation. - Use Case: When adding a new read model — for example a message delivery tracker in a WhatsApp channel context — generate the projection struct, repository interface, Postgres implementation, and mock following the enforced patterns and bad-practice checks in registry.yaml. ## Quick Start Ask the agent to create a new Go projection for a domain event flow, naming the context and the events that drive it.

Frequently Asked Questions about projection-go

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

FAQPage Schema
How do I create a CQRS read model projection in Go?

Define a plain Go struct with exported fields and db tags, add ApplyX methods for each event transition, then declare a minimal repository interface with FindByKey, Save, and InsertIfNew. The projector loads the row, calls ApplyX, and saves it back.

How should a Go projection repository interface be designed?

Declare only the surface the projector needs — no shared base interface. The canonical minimum is FindByKey, Save, and InsertIfNew, where InsertIfNew returns (bool, error) with false meaning a duplicate was skipped, not an error.

When are atomic repository operations justified in projections?

Atomic ops are edge cases justified only by named triggers: hot-row contention, bulk updates, monotonic constraints, conditional updates, or cache-mirror upserts. Each atomic method must carry a comment naming its justifying trigger.

Should a Go projection embed a base entity class?

No. Projections are free record structs with no base class, no invariants, and no domain events. Embedding something like BaseEntity is flagged as a critical bad practice in the registry.

Why should the Postgres repository constructor return the interface type?

Returning the interface type instead of the concrete pointer lets fx bind the interface directly without an fx.As wrapper. Returning *pgImpl is flagged as a bad practice in the registry.

How do I test Go projection repositories without a database?

Ship an in-memory mock alongside the Postgres implementation as mock_<name>_repository.go. It implements the full interface, exposes state fields for assertions, provides a Reset helper, and uses a compile-time interface compliance assertion.