xiaohongshu
xiaohongshu
designing-zod-schemas
Designs Zod schemas following Zod-first development. Creates validation schemas, branded types, discriminated unions, and transforms. Infers TypeScript types from schemas. Triggers on: Zod schema, z.object, z.infer, validation, branded types, discriminated union, safeParse, refinement.
Full skill instructions
Guide the design and implementation of Zod schemas following the project's Zod-first development approach, where schemas are defined before implementing business logic.
z.infer<> instead of manual type definitions| Need | Pattern | Example |
|---|---|---|
| Basic validation | Primitives | z.string().min(1) |
| Domain safety | Branded types | transform((v) => v as EntitySlug) |
| Multiple types | Discriminated union | z.discriminatedUnion('type', [...]) |
| Cross-field rules | Refinement | .refine((data) => ...) |
| Data normalization | Transform | .transform((v) => v.trim()) |
| Partial updates | Partial schema | Schema.partial() |
import { z } from 'zod';
// String with constraints
const NameSchema = z.string().min(1).max(100).trim();
// Slug pattern
const SlugSchema = z.string().regex(/^[a-z0-9-]+$/);
// Number with range
const PriceSchema = z.number().min(0).multipleOf(0.01);
// Object schema
const EntitySchema = z.object({
name: z.string().min(1),
slug: z.string().regex(/^[a-z0-9-]+$/),
description: z.string().optional(),
});
// Array with validation
const TagsSchema = z.array(z.string()).min(1).max(10);
// Type inference
type Entity = z.infer<typeof EntitySchema>;
const result = schema.safeParse(data);
if (!result.success) {
// Handle errors
console.error(result.error.issues);
} else {
// Use validated data
const validData = result.data;
}
For detailed patterns and examples, see:
src/modules/config/schema/
├── schema.ts # Main configuration schema
├── primitives.ts # Reusable primitive schemas
├── entities/ # Entity-specific schemas
│ ├── category.ts
│ ├── product.ts
│ └── ...
└── index.ts # Schema exports
| Phase | Validate | Command |
|---|---|---|
| Schema defined | No TS errors | npx tsc --noEmit |
| Types inferred | z.infer works | Check type in IDE |
| Validation works | safeParse tests | pnpm test |
| Mistake | Issue | Fix |
|---|---|---|
| Manual type definitions | Type drift | Use z.infer<typeof Schema> |
Using .parse() directly | Throws on invalid | Use .safeParse() for error handling |
Missing .optional() | Runtime errors | Mark optional fields explicitly |
| Complex refinements | Hard to debug | Break into smaller schemas |
| Not using branded types | Type confusion | Use .brand() or transform for domain safety |
For up-to-date Zod patterns, use Context7 MCP:
mcp__context7__get-library-docs with context7CompatibleLibraryID: "/colinhacks/zod"
{baseDir}/src/modules/config/schema/schema.ts - Main schema definitions{baseDir}/docs/CODE_QUALITY.md#zod-first-development - Quality standardsadding-entity-types for full schema-to-service implementationanalyzing-test-coverage for test data builderswriting-graphql-operations for schema-to-GraphQL patternsFor a condensed quick reference, see .claude/rules/config-schema.md (automatically loaded when editing src/modules/config/**/*.ts files).
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience