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.
In this repository13 other files it gives its agents.
- AGENTS.mdAGENTS.md
- writing-skillsSkill
- building-wikiSkill
- compressing-knowledgeSkill
- creating-issuesSkill
- designing-cliSkill
- fuckSkill
- git-shippingSkill
- no-commentsSkill
- orchestratingSkill
- receiving-code-reviewSkill
- tracking-tasksSkill
- writing-japaneseSkill
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
- Distinctive: line 29
Read only the reference file(s) relevant to the current task.
≈ “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.
Files
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 withkindproject-wide. - Define domain types with
type, neverinterface; 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 aTaggedErrorclass; reservepanicfor violated invariants and programmer mistakes. - Compose fallible steps with
Result.genby 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.InferInputinstead of restating the shape. asis banned exceptas constandas const satisfies T. When a value's type is unknown, parse it through a schema. Brand IDs withv.brandso no cast is ever needed.
Topics
Read only the reference file(s) relevant to the current task.
| Task involves | Read |
| Entity types, branded IDs, companion objects, file layout | references/domain-modeling.md |
| State transitions, domain events, repository interfaces | references/state-modeling.md |
| TaggedError design, Result composition, HTTP error mapping | references/error-handling.md |
| Parsing external input, schema→Result factory, PII protection | references/boundary-defense.md |
| Collection operations, test fixtures | references/style-and-testing.md |
| Setting up lint enforcement (oxlint) | references/linting.md |
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
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.

