add-domain-entity

Create domain layer components: models, repository interfaces, marshallers, and implementations. Use when: (1) adding domain model in internal/domain/model/, (2) creating repository interface in internal/domain/repository/, (3) implementing repository with marshaller in internal/infrastructure/{db}/. This is Step 2 of CRUD workflow (after add-database-table, before add-api-endpoint).

181 stars

Best use case

add-domain-entity is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Create domain layer components: models, repository interfaces, marshallers, and implementations. Use when: (1) adding domain model in internal/domain/model/, (2) creating repository interface in internal/domain/repository/, (3) implementing repository with marshaller in internal/infrastructure/{db}/. This is Step 2 of CRUD workflow (after add-database-table, before add-api-endpoint).

Teams using add-domain-entity should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/add-domain-entity/SKILL.md --create-dirs "https://raw.githubusercontent.com/majiayu000/claude-skill-registry/main/skills/data/add-domain-entity/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/add-domain-entity/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How add-domain-entity Compares

Feature / Agentadd-domain-entityStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Create domain layer components: models, repository interfaces, marshallers, and implementations. Use when: (1) adding domain model in internal/domain/model/, (2) creating repository interface in internal/domain/repository/, (3) implementing repository with marshaller in internal/infrastructure/{db}/. This is Step 2 of CRUD workflow (after add-database-table, before add-api-endpoint).

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Add Domain Entity

Create domain layer components for a new entity following DDD patterns.

## Prerequisites

- Database table created (use **add-database-table** skill first)
- SQLBoiler model generated via `make migrate.up`

## Quick Workflow

```
1. Domain Model     → internal/domain/model/{entity}.go
2. Domain Error     → internal/domain/errors/errors.go
3. Repository Interface → internal/domain/repository/{entity}.go
4. Marshaller       → internal/infrastructure/{db}/internal/marshaller/{entity}.go
5. Repository Impl  → internal/infrastructure/{db}/repository/{entity}.go
6. Generate Mocks   → make generate.mock
```

## Step 1: Create Domain Model

Location: `internal/domain/model/{entity}.go`

Create the entity struct, constructor, update methods, and type aliases.

Key requirements:
- Use `id.New()` for ID generation in constructor
- Set both `CreatedAt` and `UpdatedAt` to the same time parameter
- Define `ReadonlyReference` for relations (always nil in constructor)
- Create slice type alias: `type Examples []*Example`

See: [references/domain-model-patterns.md](references/domain-model-patterns.md)

## Step 2: Add Domain Error

Location: `internal/domain/errors/errors.go`

Add a not-found error for the entity:

```go
ExampleNotFoundErr = NewNotFoundError("E2xxxxx", "Example not found")
```

Follow error code conventions from `.claude/rules/domain-errors.md`.

## Step 3: Create Repository Interface

Location: `internal/domain/repository/{entity}.go`

Define the repository interface with standard CRUD operations and query structs.

Key requirements:
- Add `//go:generate` directive for mock generation
- Use `nullable.Type[T]` for optional enum/custom type filter fields
- Embed `BaseGetOptions` / `BaseListOptions` in query structs

See: [references/repository-patterns.md](references/repository-patterns.md)

## Step 4: Create Marshaller

Location: `internal/infrastructure/{mysql|postgresql|spanner}/internal/marshaller/{entity}.go`

Convert between DB models and domain models.

Key requirements:
- Related entity's `ReadonlyReference` must remain nil (no recursive loading)
- Use var declaration pattern for nullable timestamp fields
- Include both `ToModel` and `ToDBModel` functions

See: [references/marshaller-patterns.md](references/marshaller-patterns.md)

## Step 5: Create Repository Implementation

Location: `internal/infrastructure/{mysql|postgresql|spanner}/repository/{entity}.go`

Implement the repository interface using SQLBoiler.

Key requirements:
- Use `transactable.GetContextExecutor(ctx)` for all DB operations
- Implement `buildListQuery` helper for reusable filter logic
- Implement `buildPreload` helper for relation loading
- Use base helper functions: `addForUpdateFromBaseGetOptions`, `addForUpdateFromBaseListOptions`

See: [references/repository-patterns.md](references/repository-patterns.md)

## Step 6: Generate Mocks

```bash
make generate.mock
```

This generates mock implementations in `internal/domain/repository/mock/`.

## Checklist

### Domain Model
- [ ] Entity struct with all fields
- [ ] `ReadonlyReference` for relations (if any)
- [ ] Constructor with `id.New()` and `ReadonlyReference: nil`
- [ ] Update method using `null.*` types for optional fields
- [ ] Slice type alias (`Examples []*Example`)
- [ ] Helper methods on slice (`IDs()`, `MapByID()`)

### Status/Enum Types (if needed)
- [ ] Type definition with `Unknown` as first constant
- [ ] `String()` and `Valid()` methods
- [ ] `New{Type}(str string)` constructor

### Repository
- [ ] Interface with `//go:generate` directive
- [ ] Query structs with `nullable.Type[T]` for optional enums
- [ ] Domain error added for not-found case

### Implementation
- [ ] Marshaller with `ToModel`, `ToDBModel`, `ToModels`, `ToDBModels`
- [ ] Marshaller handles `ReadonlyReference` correctly
- [ ] Repository implementation with all CRUD methods
- [ ] `buildListQuery` and `buildPreload` helpers
- [ ] Mocks generated

## Next Steps

After creating domain entity, use **add-api-endpoint** skill to create:
- Usecase input/output structs
- Interactor interface and implementation
- Protocol Buffers definition
- gRPC handler

Related Skills

add-ravendb-identity-store

181
from majiayu000/claude-skill-registry

Implement ASP.NET Identity user and refresh token stores backed by RavenDB

add-entity-field

181
from majiayu000/claude-skill-registry

Add a new field to an existing entity/model with related service and endpoint updates

acc-create-entity

181
from majiayu000/claude-skill-registry

Generates DDD Entities for PHP 8.5. Creates identity-based objects with behavior, state transitions, and invariant protection. Includes unit tests.

acc-create-domain-service

181
from majiayu000/claude-skill-registry

Generates DDD Domain Services for PHP 8.5. Creates stateless services for business logic that doesn't belong to entities or value objects. Includes unit tests.

acc-create-domain-event

181
from majiayu000/claude-skill-registry

Generates DDD Domain Events for PHP 8.5. Creates immutable event records with metadata, past-tense naming. Includes unit tests.

abp-entity-patterns

181
from majiayu000/claude-skill-registry

ABP Framework domain layer patterns including entities, aggregates, repositories, domain services, and data seeding. Use when: (1) creating entities with proper base classes, (2) implementing custom repositories, (3) writing domain services, (4) seeding data.

domain-name-brainstormer

181
from majiayu000/claude-skill-registry

Generates creative domain name ideas for your project and checks availability across multiple TLDs (.com, .io, .dev, .ai, etc.). Saves hours of brainstorming and manual checking.

4-domain-deep-dive

181
from majiayu000/claude-skill-registry

Fourth step in building instruction context for codebase

20-build-domain

181
from majiayu000/claude-skill-registry

Status: ACTIVE

Enforce Agent Identity in Skill

181
from majiayu000/claude-skill-registry

No description provided.

ux

159
from majiayu000/claude-skill-registry

This AI agent skill provides comprehensive guidance for creating professional and insightful User Experience (UX) designs, covering user research, information architecture, interaction design, visual guidance, and usability evaluation. It aims to produce actionable, user-centered solutions that avoid generic AI aesthetics.

UX Design & StrategyClaude

grail-miner

159
from majiayu000/claude-skill-registry

This skill assists in setting up, managing, and optimizing Grail miners on Bittensor Subnet 81, handling tasks like environment configuration, R2 storage, model checkpoint management, and performance tuning.

DevOps & Infrastructure