agentleFS
nimadorostkarnimadorostkar/Claude-Skills-collection/skills/development/domain-modeling/SKILL.md

domain-modeling

Skill28 starsChanged 5 months agoMITView on GitHub

Use when the code's vocabulary does not match the business's. Establishes a ubiquitous language, models domain concepts as explicit types, and identifies bounded contexts.

171 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use writing-beats, setup-ts-deep-modules and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • RoentekSkill

    writing-beats

    Writing, exploit — assemble raw material into a journey of beats, grounding each term before a beat leans on it.

    Also in 24 projects that use this

  • loulanyueSkill

    setup-ts-deep-modules

    Wire dependency-cruiser into a TypeScript repo so each package is a deep module — implementation hidden in subfolders, reachable only through its entry-point files. User-invoked.

    Also in 16 projects that use this

  • risadamsSkill

    which-skill

    Router over this pack's skills and flows. Ask it "which skill fits X" when you don't remember what's available.

    Also in 5 projects that use this

  • RoentekSkill

    writing-shape

    Writing, exploit — shape raw material into an article, paragraph by paragraph.

    Also in 22 projects that use this

  • pahwarangerSkill

    setup-skills

    Sets up an `## Agent skills` block in AGENTS.md/CLAUDE.md and `docs/agents/` so the engineering skills know this repo's ticket tracker (GitHub or local markdown), triage label vocabulary, and domain doc layout. Run before first use of `to-tickets`, `to-prd`, `triage`, `diagnose`, `tdd`, `improve-codebase-architecture`, or `zoom-out` — or if those skills appear to be missing context about the ticket tracker, triage labels, or domain docs.

    Also in 7 projects that use this

  • qwlabsSkill

    claude-handoff

    Hand the current conversation off to a fresh background agent that picks up the work immediately.

    Also in 17 projects that use this

  • +2 more from Roentek

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 160 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never share a database table across bounded contexts.

    line 57
  2. Distinctive:

    Do not build a domain model for a CRUD application.

    line 58

“Common” is measured: kept by at least 6 in 10 of the 160 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Domain Modeling

Purpose

Make the code speak the business's language precisely. Most long-lived complexity comes from a mismatch between the words the business uses and the structures the code has — where "user" means four different things and none of them are named.

When to Use

  • The same concept has different names in code, in the database, and in conversation.
  • A single model class is used by three subsystems that each need something different from it.
  • New requirements consistently require changes in unrelated modules.
  • Designing a new subsystem in a domain with real business rules.

Capabilities

  • Ubiquitous language: a shared, enforced vocabulary between code and domain experts.
  • Modeling entities, value objects, and aggregates with clear invariants.
  • Bounded-context identification and mapping.
  • Replacing primitive obsession with domain types.
  • Making illegal states unrepresentable.

Inputs

  • The domain vocabulary, ideally from the people who use it daily.
  • The current model and where it hurts.
  • The business rules, especially the ones that are currently enforced by convention.

Outputs

  • A glossary of terms, each with exactly one meaning.
  • Domain types that carry their invariants.
  • Named bounded contexts and the translation between them.

Workflow

  1. Collect the vocabulary — Listen to how the domain experts speak. When they say "a subscription lapses", the code should have a lapse() and not a status = 3.
  2. Find the collisions — The same word meaning two things is the highest-value finding. "Order" in fulfilment and "Order" in billing are usually different concepts.
  3. Draw the context boundaries — Where the meaning of a word changes, a context boundary exists. Draw it explicitly and translate at the edge.
  4. Replace primitives with types — Money, EmailAddress, SubscriptionId. A type that validates on construction cannot be invalid downstream.
  5. Move invariants into the model — If a rule is currently enforced in a controller, the model permits an invalid state. Move it.
  6. Rename ruthlessly — Code that uses a word the business does not use is code the business cannot verify.

Best Practices

  • One word, one meaning, per context. If you need to say "billing order" to be clear, the type should be BillingOrder.
  • A value object with no identity should be immutable and compared by value. Money(1000, "USD") equals Money(1000, "USD").
  • An aggregate is a consistency boundary. Everything inside it is transactionally consistent; everything outside it is eventually consistent. Choose the boundary deliberately.
  • Never share a database table across bounded contexts. That is a hidden coupling that no interface can undo.
  • Do not build a domain model for a CRUD application. If there are no invariants, a form and a table is the correct architecture.
  • The glossary belongs in the repository, and disagreements about it are the most productive meetings you will have.

Examples

Primitive obsession versus a domain type:

// Before: every caller must remember the currency and the unit.
function refund(orderId: string, amount: number, currency: string) { ... }
refund("ord_1", 19.99, "USD");   // floating point money, in an unvalidated string id

// After: the types make the mistakes impossible.
class Money {
  private constructor(readonly cents: bigint, readonly currency: Currency) {}

  static of(cents: bigint, currency: Currency): Money {
    if (cents < 0n) throw new DomainError("Money cannot be negative");
    return new Money(cents, currency);
  }

  plus(other: Money): Money {
    if (other.currency !== this.currency) {
      throw new DomainError(`Cannot add ${other.currency} to ${this.currency}`);
    }
    return new Money(this.cents + other.cents, this.currency);
  }
}

function refund(orderId: OrderId, amount: Money): Refund { ... }

Currency mismatches and negative amounts are now compile-time or construction-time errors rather than production incidents.

Notes

  • Aggregate boundaries that are too large create lock contention; boundaries that are too small push consistency into the application layer. Start with the smallest set of objects that must change together atomically.
  • Anti-corruption layers exist so that a bad upstream model does not leak into a good one. When integrating a vendor API, translate at the edge — do not let their nouns into your domain.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.