/eng:schemas-and-contractsfrom Engineering Skills
Zod schemas at every boundary and the shared contracts that hold them — write schemas as `.pick()` allowlists, partial updates that keep omitted fields, tolerant reads of stored data, list projections, strings from forms and URLs, per-field errors, dates and money on the wire, safe shared primitives, evolving a contract, and building a contracts package. Use when adding a field, a request body, a form schema, an enum, a list shape or a shared type.
Ships in Engineering Skills. 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.
Read when SKILL.md points to them.
A shape that crosses a boundary — a request body, a stored document, an API response, a worker's trigger, a form — is defined once, as a Zod schema, and every side imports it. One schema is both the runtime parser and, through z.infer, the type, so the API's validation, the form's validation and the frontend's types can't disagree.
Before applying this skill, read the project's root AGENTS.md, the AGENTS.md closest to the files in question, and any doc they link for this skill's topic. Names, values and choices — budgets, tiers, tokens, voice, paths — come from those files, never from this skill.
export const UserSchema = … then export type User = z.infer<typeof UserSchema>. A hand-written type beside a schema is a second definition that drifts. Never pool the types at the bottom of the file.z.email(), z.uuid(), z.url(); the chained z.string().email() forms are deprecated..pick(), .extend() and .partial(), so a field changes in one place..extend() and .partial() throw on an object that carries a refinement, so a cross-field check goes on the derived schema that needs it, never the base; extend a refined schema only with .safeExtend().z.discriminatedUnion("kind", […]), which picks the branch by its tag and reports that branch's errors, where a plain union reports every branch's..min() and .max() read UPPER_SNAKE_CASE constants that the UI's hints read too, never magic numbers.A write schema is a .pick() allowlist of the full schema — the fields a caller may set, named one by one. It fails closed: a field added to the document isn't writable until someone adds it to the pick. Never derive a write schema with .omit(), which lets every new field through.
A partial update goes through a helper that removes defaults. .partial() keeps each field's .default(), so a PATCH that omits a field gets the default filled in and written — resetting a value the caller never touched. Unwrap the defaults first:
// shared.schema.ts
export function stripDefaults<T extends z.ZodRawShape>(shape: T) {
return Object.fromEntries(
Object.entries(shape).map(([key, field]) => [
key,
field instanceof z.ZodDefault ? field.unwrap() : field,
]),
) as { [K in keyof T]: T[K] extends z.ZodDefault<infer U> ? U : T[K] };
}
export const UpdateUserSchema = z
.object(stripDefaults(UserSchema.pick({ displayName: true, phoneNumber: true }).shape))
.partial();
export type UpdateUser = z.infer<typeof UpdateUserSchema>;
What a caller sends is always exact. Unknown keys are dropped, every value is validated, and nothing tolerant applies to input. z.strictObject refuses unknown keys instead, where a typo should fail loudly (a config file).
Query strings, route params, form data and env values arrive as strings, or not at all. The schema turns them into real types, once, in shared helpers:
z.coerce.number() — but Number("") is 0, so an empty field is turned into undefined first, or a blank optional field saves as zero."on"; z.stringbool().default(false) reads both.?tag=a&tag=b) are read with getAll; Object.fromEntries keeps only the last.undefined for an optional field, never an empty string stored as a value.z.iso.date() (YYYY-MM-DD), not a timestamp.z.flattenError(error) gives fieldErrors (field → messages) and formErrors (the rest); a Server Action returns them in its action result and the API in the validation error's details, so a form shows each message beside its field and the rest beside the submit button..refine(check, { path: ["confirmPassword"], error: "…" }) — or its message has nowhere to go.error, not Zod's defaults..pick() of the full schema naming exactly what its card or row renders, and the data layer parses every document through it, so a key the pick doesn't name is dropped. That keeps payloads small and keeps sensitive fields out: a field added to the document can't leak into a list, because the pick doesn't name it. A detail read returns the full document; a sensitive field never appears in a list or public shape.firestore's.Keep the primitives every domain reuses in one shared.schema.ts — email, phone, country code, timestamps, pagination queries, safe URLs — and build domain schemas from them.
z.httpUrl(), which allows only http: and https: — the rule the sanitisers share (frontend-security, backend-security). Plain z.url() accepts javascript: and data:. mailto: and tel: appear only in links the app builds itself.z.string().brand<"EventId">()), so passing a user id where an event id belongs fails the type check.JSON has no dates, undefined, Map or bigint, so a contract describes what actually travels:
z.iso.datetime()), turned into a Date only where code needs one, with a codec (z.codec(z.iso.datetime(), z.date(), { decode, encode })) so both directions stay paired.Timestamp, a driver's Date or Decimal — to the wire form before parsing, and back when writing (firestore).z.input<> is what a form or caller holds, z.output<> (what z.infer gives) what the parse returns. Type a form's values with the input.The same four kinds whatever the repo's shape. A single app keeps them in lib/; a monorepo moves the ones two or more workspaces share into a contracts package, so the API, the apps and the workers import one copy.
| Kind | Holds | Single app | Monorepo |
|---|---|---|---|
constants/ | as const enums and the unions derived from them, limits, labels, data paths | lib/constants/ | the contracts package |
schemas/ | Zod schemas with their inferred types, one <domain>.schema.ts per domain | lib/schemas/ | the contracts package |
types/ | only shapes nothing infers — UI state that never crosses a wire | lib/types/ | the contracts package |
permissions/ | the closed list of verbs, role maps and the pure can() predicates | split across constants/ and utils/ | the contracts package |
types/ holds only what no schema or const produces (upload progress, a menu's open state).as const array, and both the enum schema and the UI read that one array (EVENT_STATUSES → z.enum(EVENT_STATUSES) and type EventStatus).can() is pure, with no I/O, so the same predicate gates a button in the UI and the guard in the API; how roles and verbs are designed is access-control's.lib/schemas/, built from contract pieces (OrganiserSchema.shape.name, the safe URL schema). It moves into the contracts only when a second workspace needs it. Never re-declare a contracts schema inside an app.dist/, and every consumer reads the build. NodeNext needs the .js extension on relative imports; switching to bundler resolution to avoid it breaks Node consumers at runtime, and rewriting imports after the build is not a fix.dist/ reports the new shape as a validation error. A dev task usually doesn't rebuild dependencies, so say so in the project's docs.<domain>.schema.test.ts): the value it accepts, the one it refuses, and the message.api-architecture.nextjs.can() → access-control.satisfies and tsconfig → typescript; names of schemas and types → naming.lib/ kinds and packages go → code-structure.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub timonwa/engineering-skills --plugin eng20 skills in this plugin
/agents-mdWrites or updates a project's AGENTS.md and the short AGENTS.md notes in each app and package — what an agent can't work out from the code: commands, structure, conventions that differ from the defaults, workflow, recorded deviations from the house standards and hard constraints, under 200 lines. Use when starting a project, setting up AGENTS.md or CLAUDE.md, or bringing a project's agent instructions up to date./audit-allManually invoked. Runs the house audit suite across the eng, fe and be sets — detects what the repo has, runs every installed audit that applies (codebase, conventions, dependencies, env, security, accessibility, frontend, performance, SEO/AEO/GEO, Storybook, content, API, access control, Firestore, Redis), and rolls their reports into one health report with an overall score and cross-cutting priorities. Each audit still writes its own report./codebase-auditManually invoked. Broad repo-health triage that routes to the deep audits and covers the hygiene no other audit owns — tech debt, dead code, TypeScript strictness and the options TypeScript 6 deprecates, error handling, tests (boundary-only mocks, determinism, no skipped or flaky tests), CI hygiene, branch protection, releases and deploys, and git hygiene. Verifies each finding and writes a prioritized report with an overall health score./code-structureThe file and folder structure of a Next.js App Router app — thin page and layout entries, components/ organised by product area, section-based pages composed by an index, a flat kind-first lib/ using the `<domain>.<kind>.ts` grammar, the server folders for each app shape (an app with its own backend, a frontend over a separate API, the API app itself), and where shared code goes in a monorepo. Use when adding or refactoring a page, building a screen, splitting UI, organising lib/ or server code, or deciding whether code belongs in a package./conventions-auditManually invoked. Audits an app or monorepo against the house naming and code-structure standards — identifier, file, test-file, field and error naming; thin route entries and app/ holding only Next's files; components by product area; kind-first lib/ and barrels; server boundaries; typed routes; promotion on the second consumer; duplicated helpers, oversized files, hardcoded values and cross-app config drift. Verifies each finding and writes a prioritised report./dependency-auditManually invoked. Dependency-health audit of a monorepo — one version per dependency through the pnpm catalog with recorded exceptions, workspace protocol and dependency direction, peer dependencies for singletons, unused, missing, duplicate and misplaced packages, build-script allowlists, release-age holds, advisories, automated updates, and lockfile integrity. Verifies each finding and writes a prioritised report.