joeyave/golang-ddd-skills · Archived

golang-ddd-refactor

Refactor existing Go code toward a behavior-first, invariant-protecting domain model.

First seen Apr 12, 2026

Installation

$ npx skills add joeyave/golang-ddd-skills --skill golang-ddd-refactor

Summary

  • Refactor existing Go code toward a behavior-first, invariant-protecting domain model.
  • Use when business rules live in handlers or repositories, shared structs couple DB and API models, entities expose setters or mutable public fields, or a service needs domain methods, constructors, private state, repository update closures, and focused domain tests.

Stronger alternatives

This repository is archived — consider an actively maintained alternative.

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from joeyave/golang-ddd-skills.

npx skills add joeyave/golang-ddd-skills

Browse all from joeyave/golang-ddd-skills

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Declared
Cursor Declared
Codex Declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Declared
Cline Not declared
OpenCode Declared

Repository health

Stars 4
License LICENSE
Default branch main
Open issues 0
Status Archived

Skill metadata

Parsed from SKILL.md frontmatter.

Version0.3.0
LicenseMIT
CompatibilityDesigned for Codex, Claude Code, Gemini CLI, Cursor, OpenCode, and similar AI coding agents working with Go services.
Declared agents claude-code cursor codex gemini opencode
More metadata
author
joeyave
version
0.3.0

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 3,294 B
  • docs SUMMARY.md 379 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 40 installs

SKILL.md

Golang DDD Refactor

Use this skill when the code already works but is becoming hard to trust, test, or extend because the business rules are scattered across transport and persistence code.

Refactor Loop

  1. Find the use case from the edge of the system.
  • Start from HTTP handlers, gRPC methods, commands, repository callbacks, or transaction blocks.
  • Write down the business operation in plain language before introducing any new types.
  1. Extract the rules hiding inside conditionals.
  • Look for "walls of if" that decide whether something may happen.
  • Turn those rules into invariants and behavior methods on a domain type.
  1. Create or tighten the domain type.
  • Prefer constructors that reject invalid state.
  • Prefer private fields when external mutation would bypass invariants.
  • Replace setters with behavior methods named in business language.
  1. Make the domain database-agnostic.
  • Remove Firestore, SQL, protobuf, or HTTP concerns from domain packages.
  • Introduce separate persistence models if storage shape differs from the domain shape.
  1. Rebuild the repository boundary.
  • Put the repository interface next to the code that consumes it.
  • Prefer generic repository capabilities such as load or update over repository methods that mirror every business action.
  • Use closure-based update methods when the write requires transactional read-modify-save behavior.
  1. Add black-box tests around the domain.
  • Test exported behavior, not private fields.
  • Use helpers that create meaningful domain objects such as "available hour" or "canceled training".
  • Keep mocks out of domain tests.
  1. Shrink the old code paths.
  • Make handlers, services, and repositories delegate to the new domain behavior.
  • Delete duplicated validation once the domain enforces it reliably.

Guardrails

  • Do not invent entities and value objects unless they clarify real business behavior.
  • Do not move pure transport validation into the domain unless it is a business rule.
  • Do not leak database transaction types or clients into the domain.
  • Do not keep public writable fields just because the old code used them.

Use These References

  • Read [references/domain-rules.md](references/domain-rules.md) for the core rules adapted for this skill pack.
  • Read [references/refactor-playbook.md](references/refactor-playbook.md) for a step-by-step migration path and anti-pattern checklist.

Deliverables

  • behavior-oriented domain methods,
  • constructors or factories that enforce validity,
  • narrowed repository contracts,
  • removed duplicated business checks from handlers or adapters,
  • focused domain tests that describe the behavior in business terms.