entity-go

Create Go domain entities with BaseEntity embedding, constructors, behavior methods, and domain events.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? It standardizes how Go domain entities are modeled in a DDD codebase, preventing common mistakes like version bumps in repositories, rehydration that regenerates UUIDs, and panicking behavior methods. ## Core Features & Use Cases - Entity scaffolding: Defines the full pattern for aggregate roots — BaseEntity embedding, New<Name> constructor returning error, and Reconstruct<Name> for persistence rehydration. - Behavior method conventions: Enforces guard → mutate → IncrementVersion → optional domain event flow, with errors returned instead of panics. - Domain event placement: Ensures creation events are raised in the constructor and transition events in behavior methods, never in use cases. - Use Case: When adding a new aggregate like a TranscodingJob to a Go bounded context, follow this Skill to produce a constructor that validates inputs, behavior methods that enforce state transitions, and a Reconstruct function the repository can call safely. ## Quick Start Create a Go domain entity for the billing context with a constructor, behavior methods, and rehydration function following the BaseEntity pattern.

Frequently Asked Questions about entity-go

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

FAQPage Schema
How do I create a domain entity in Go with DDD?

Embed entities.BaseEntity in your struct, write a New<Name> constructor that validates inputs and returns (*T, error), and add behavior methods that guard preconditions, mutate state, and call IncrementVersion. Raise the creation domain event inside the constructor via AddDomainEvent.

Where should IncrementVersion be called in a Go entity?

IncrementVersion must be called inside every entity behavior method that mutates state, not in the repository save method. Calling it in the repository causes double version bumps and optimistic-lock conflicts.

How do I rehydrate a Go entity from the database without losing its ID?

Write a Reconstruct<Name> function that accepts a BaseEntity built via entities.ReconstructBaseEntity with the persisted ID, timestamps, and version. Never call NewBaseEntity during rehydration, since it generates a fresh UUID and timestamps.

When should a Go entity use private fields with getters?

Use private fields with exported getters when the aggregate has complex invariants where direct field writes are dangerous, such as deletedAt or muteExpiration. Simple aggregates like a transcoding job can safely use public fields.

Should domain events be raised in the use case or the entity?

Creation events belong in the New<Name> constructor and transition events in behavior methods, attached via AddDomainEvent. Raising them in use cases risks missing events when other code paths call the constructor directly.