/craft:ddd-fp-principlesfrom craft
Provides cross-language functional DDD principles: immutable records, curried operations, Result types, validation/enrichment pipelines, and handler orchestration. Activates for 'aggregate', 'smart constructor', 'make*', 'validation pipeline', 'enrichment', 'domain handler' in a functional context.
Ships in craft. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The rules below describe functional-style DDD (records over classes, curried operations, Result pipelines). Language-specific examples live in:
ddd-ts-fp(TypeScript withpipe,chain,Result<T, E>)For OOP-style DDD (classes, ports/adapters, module-bounded contexts), see
craft:ddd-principles. The two styles can coexist in the same codebase (e.g. PHP/Symfony in OOP, TypeScript domain in FP) — pick the one that matches the language's idioms.
Model aggregates as immutable record types with all fields readonly. State changes return new instances; no in-place mutation.
Each domain operation is a curried function: (context) => (input) => output.
A single operation returns exactly one of the two shapes, output or Result<output, error>, never both in the same signature.
pipe(aggregate, op1, op2, op3) or pipe(..., chain(opThatCanFail)).Why curried: each op becomes directly usable in a pipe without extra wrapping.
Total operations compose bare in a pipe; only a fallible operation needs chain, because chain requires a function that returns a Result.
make* prefix)A validator owns the invariants and returns a narrower type; a maker builds the aggregate from that narrower type and cannot fail.
| Element | Rule |
|---|---|
| Validator | (raw) => Result<Validated<X>, error> — owns the invariants, returns a type the raw input does not satisfy |
| Prefix | make |
| Shape | make<X>(context) => (validated) => aggregate |
| Return | The aggregate. A maker is total, and its input type is what earns that |
| Position in pipeline | After the validator, applied to the narrowed value |
Every maker is paired with a named validator that owns its invariants, and the two are separate units: the validator is fallible and narrows the type, the maker is total because its input already carries that proof.
A maker that takes the raw input is not total — it is partial and silent. Raw -> Aggregate is total only when every Raw yields a valid aggregate. When some do not, the invariant lives outside the types and nothing stops make(neverValidated) from compiling: the split then costs a step and buys no guarantee, because the ordering is a promise rather than a compile error.
Why not a single fallible constructor? That is the canonical form and it is correct — create: (raw) => Result<T, error> makes illegal states unrepresentable in one step (Wlaschin, Domain Modeling Made Functional). Split it in two only for a reason: to accumulate every error instead of short-circuiting at the first, or to keep construction context (ids, clocks) out of the invariants. Without one of those two, the fallible constructor is simpler and just as safe.
Totality is not purity. A function returning Result<T, error> is pure — Result is a value, not an effect. Never reach for a total maker in the name of purity: both forms are pure, and only the narrowed input type buys anything.
Earning the narrower type. Prefer a shape that is genuinely narrower and therefore constructed, because a construction is checked and needs no assertion. A phantom brand adds no data, so it can only ever be asserted: when it is the right tool, mint it through one helper outside the domain rather than at each site. A type predicate is not a third option — the language never checks that its body proves its claim, so it is the same assertion with no word left to grep for.
A validator that returns its own input type throws away what it just proved: once it succeeds you hold the type you started with, and the compiler knows nothing it did not know before. Return a narrower type instead, so the proof travels with the value (Alexis King, Parse, don't validate, 2019).
Validation is a chain of composable validators: (raw) => Result<narrower, error>.
if.Enrichment transforms incoming data into domain objects at the system boundary.
| Aspect | Validation | Enrichment |
|---|---|---|
| Purpose | Verify constraints | Transform / complete data |
| Source | Internal data | External data (API, message broker) |
| Position | Before business logic | At system boundary |
Both compose with the same pipe / chain machinery.
A handler orchestrates a use case: it is the impure shell around a pure domain core.
Flow:
validate(command)
→ load(aggregate from repository)
→ apply pure domain operations
→ persist updated aggregate
→ return result / publish events
pipe(aggregate, op1(deps), op2(deps)) shaped consistently.| Rule | Convention |
|---|---|
| Aggregate | Immutable readonly record, no class |
| Operations | Pure curried functions returning new aggregates |
| Validator | Fallible; owns the invariants and narrows the type |
| Maker | Total; takes the narrowed type, which is what earns the totality |
| Updates | Spread / structural sharing — never mutate |
| Composition | pipe(aggregate, op1, op2, op3) |
| Fallible composition | pipe(aggregate, op1, chain(op2)) |
| Validation pipeline | Chain of (raw) => Result<narrower, e>; stops at first error |
| Enrichment pipeline | Transform external → domain at system boundary |
| Handler | Orchestrator: validate → load → pure domain → persist |
| Dependency group | Positional arguments, never a destructured object or container |
| Argument order | Handler: deps then data. Model: data then subject, aggregate last |
| Curry scope | Only what is partially applied or piped; ports/predicates/mappers stay single-stage |
| Handler type | export type XHandler for Command, never for Query |
| Handler composition | Never handler-to-handler; compose in a Workflow/Listener/Router/Consumer |
| Handler return | Result when failable, Promise<void> when fire-and-forget |
| Data stage input | One XCommand/XQuery object, never a list of primitives |
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub fabiensalles/claude-marketplace --plugin craft8 skills in this plugin
/code-style-principlesACTIVATE whenever writing or modifying production code in src/, in any language — this is the base layer these rules build on. ACTIVATE for code review, formatting questions, or 'coding standards'. Covers cross-language code style: control-structure spacing, early-return pattern, continue-vs-if/else in loops, explicit (non-truthy/falsy) checks, flattening nested null checks, parameter ordering. These rules go BEYOND standard linters. Language-specific syntax (no-empty in PHP, template literals in TS, nowdoc, optional chaining vs nullsafe) lives in php-code-conventions / ts-code-conventions, which apply on top of this skill rather than instead of it. DO NOT use for: language-specific syntax already covered by php-code-conventions / ts-code-conventions (see php:php-code-conventions + typescript:ts-code-conventions for PHP/TS specifics)./ddd-principlesACTIVATE when designing the domain layer in OOP languages — bounded contexts, aggregates, value objects, layer purity, ports/adapters, dependency direction. ACTIVATE for 'domain', 'DDD', 'hexagonal', 'ports and adapters', 'domain purity', 'bounded context', 'aggregate'. Provides cross-language OOP-style DDD principles. For functional-style DDD (immutable records, smart constructors, pipelines) see craft:ddd-fp-principles. Language-specific examples live in php-ddd-conventions, nest-ddd-conventions.Other plugins' skills for the same job