Choose an adapter
Adapters let your domain model depend on one contract while each boundary keeps using the validation engine that fits it best.
Decision table
Section titled “Decision table”| Situation | Recommended package | Why |
|---|---|---|
| You already use Zod in app or shared code | @xndrjs/domain-zod | Great parser ergonomics, transforms, and kit reuse inside parent schemas |
| You prefer small function-first schemas | @xndrjs/domain-valibot | Good fit for composable parser pipelines and bundle-sensitive code |
| You consume JSON Schema or OpenAPI | @xndrjs/domain-ajv | Compiles existing external contracts instead of rewriting them |
| Validation is very small or custom | @xndrjs/domain | Use compose helpers or your own Validator implementation |
The adapter does not own the domain
Section titled “The adapter does not own the domain”Core @xndrjs/domain always takes a Validator via domain.core.*. Adapter packages (domain-zod, domain-valibot) export an adapted domain whose top-level shape / primitive / proof accept native schemas only; use domain.core.* with *ToValidator when you need an explicit Validator. Ajv stays on jsonSchemaToValidator / OpenAPI helpers + domain.core.* because the input is a JSON Schema document, not a single fluent schema object.
Minimal example: Email comes from a JSON Schema fragment (as in an OpenAPI bundle), while UserProfile is defined with Zod. The contact field reuses the Email primitive inside the Zod object so you do not duplicate email rules.
import { domain as ajvDomain, jsonSchemaToValidator } from "@xndrjs/domain-ajv";import { domain, zodFromKit } from "@xndrjs/domain-zod";import { z } from "zod";
const Email = ajvDomain.core.primitive( "Email", jsonSchemaToValidator<string>({ type: "string", format: "email", }));
const UserProfile = domain.shape( "UserProfile", z.object({ displayName: z.string().min(1), contact: zodFromKit(Email), }));After validation, Email.create / UserProfile.create and the rest of the kit APIs behave the same regardless of which adapter built the validator.
Mixing adapters
Section titled “Mixing adapters”It is valid for different boundaries to use different engines:
- backend OpenAPI contracts can use AJV
- client features (i.e. a document editor) can use Valibot or Zod
The important part is that each boundary ends up with a Validator<Input, Output> under the kit (explicitly or via an adapter domain that wraps a native schema). After that, kits use the same APIs: adapter top-level domain.shape / primitive / proof (or domain.core.* with a Validator), plus domain.capabilities.*.
Practical recommendation
Section titled “Practical recommendation”Start with the adapter your project already uses. Reach for another adapter only when a boundary naturally speaks a different schema language.
- Zod adapter — then First model for a full walkthrough
- Valibot adapter
- AJV adapter
- Domain mental model — trust boundaries behind the kits