agentleFS
h3y6eh3y6e/agent-skills/skills/functional-domain-modeling/SKILL.md

functional-domain-modeling

Skill0 starsChanged 29 days agoMITView on GitHub

Functional domain modeling for server-side TypeScript with better-result and valibot — discriminated unions, pure state transitions, TaggedError-based Result handling, schema-validated boundaries, and PII protection. Use when adding or changing a server-side domain type, state transition, repository, or boundary parser, or when deciding how a failure is represented. Skip frontend components, build tooling, and code unrelated to domain logic.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    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:

    Read only the reference file(s) relevant to the current task.

    line 29

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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

Functional Domain Modeling in TypeScript

Robust server-side TypeScript design with better-result (Result, TaggedError) and valibot (schemas, branded types).

Invariants

Apply these throughout:

  • Model each entity state as its own Readonly<> type; discriminate with kind project-wide.
  • Define domain types with type, never interface; write functions in type definitions with function property notation (save: (t: Task) => Promise<void>).
  • Express state transitions as pure functions whose argument types constrain valid source states and whose return types name the target state. Invalid transitions must be compile errors.
  • Errors are values: domain code returns Result<T, E> and never throws. Define each known failure as a TaggedError class; reserve panic for violated invariants and programmer mistakes.
  • Compose fallible steps with Result.gen by default; use a lone combinator only for a single transform. Avoid long combinator chains.
  • Validate every external input (API request, DB row, env var, file, queue message) with a valibot schema at the boundary; trust types inside the domain — do not re-validate. When a schema already defines a boundary representation, derive its type with v.InferOutput/v.InferInput instead of restating the shape.
  • as is banned except as const and as const satisfies T. When a value's type is unknown, parse it through a schema. Brand IDs with v.brand so no cast is ever needed.

Topics

Read only the reference file(s) relevant to the current task.

Task involvesRead
Entity types, branded IDs, companion objects, file layoutreferences/domain-modeling.md
State transitions, domain events, repository interfacesreferences/state-modeling.md
TaggedError design, Result composition, HTTP error mappingreferences/error-handling.md
Parsing external input, schema→Result factory, PII protectionreferences/boundary-defense.md
Collection operations, test fixturesreferences/style-and-testing.md
Setting up lint enforcement (oxlint)references/linting.md

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.