🎯

designing-zod-schemas

🎯Skill

from saleor/configurator

VibeIndex|
What it does

Designs and validates Zod schemas with type inference, supporting complex validation patterns, branded types, and transformations.

designing-zod-schemas

Installation

Install skill:
npx skills add https://github.com/saleor/configurator --skill designing-zod-schemas
7
Last UpdatedJan 23, 2026

Skill Details

SKILL.md

"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."

Overview

# Zod Schema Designer

Purpose

Guide the design and implementation of Zod schemas following the project's Zod-first development approach, where schemas are defined before implementing business logic.

When to Use

  • Creating new data structures
  • Adding validation to inputs
  • Designing configuration schemas
  • Implementing type-safe transformations
  • Creating test data builders

Table of Contents

  • [Core Principles](#core-principles)
  • [Quick Reference](#quick-reference)
  • [Schema Patterns](#schema-patterns)
  • [Project Schema Location](#project-schema-location)
  • [References](#references)

Core Principles

Zod-First Development

  1. Define Schema First: Schema is the source of truth
  2. Infer Types: Use z.infer<> instead of manual type definitions
  3. Share Validation: Same schema for runtime validation and tests
  4. Compose Schemas: Build complex schemas from primitives

Decision Guide

| 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() |

Quick Reference

Common Schema Shapes

```typescript

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;

```

Safe Parsing

```typescript

const result = schema.safeParse(data);

if (!result.success) {

// Handle errors

console.error(result.error.issues);

} else {

// Use validated data

const validData = result.data;

}

```

Schema Patterns

For detailed patterns and examples, see:

  • [Primitive Patterns](references/primitive-patterns.md): Strings, numbers, enums, branded types
  • [Object Patterns](references/object-patterns.md): Objects, discriminated unions, arrays, transforms, refinements
  • [Testing Patterns](references/testing-patterns.md): Test data builders, schema validation tests

Project Schema Location

```

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

```

Validation Checkpoints

| 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 |

Common Mistakes

| Mistake | Issue | Fix |

|---------|-------|-----|

| Manual type definitions | Type drift | Use z.infer |

| 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 |

External Documentation

For up-to-date Zod patterns, use Context7 MCP:

```

mcp__context7__get-library-docs with context7CompatibleLibraryID: "/colinhacks/zod"

```

References

  • {baseDir}/src/modules/config/schema/schema.ts - Main schema definitions
  • {baseDir}/docs/CODE_QUALITY.md#zod-first-development - Quality standards
  • Zod documentation: https://zod.dev

Related Skills

  • Complete entity workflow: See adding-entity-types for full schema-to-service implementation
  • Testing schemas: See analyzing-test-coverage for test data builders
  • GraphQL type mapping: See writing-graphql-operations for schema-to-GraphQL patterns

Quick Reference Rule

For a condensed quick reference, see .claude/rules/config-schema.md (automatically loaded when editing src/modules/config/*/.ts files).

More from this repository8

🎯
implementing-cli-patterns🎯Skill

Here's a concise, practical description for the "implementing-cli-patterns" skill: Implements consistent CLI user experiences with color-coded output, progress indicators, interactive prompts, and...

🎯
creating-changesets🎯Skill

Automates changeset creation for semantic versioning, determining version bump type and generating detailed release notes.

🎯
reviewing-typescript-code🎯Skill

Reviews TypeScript code for type safety, clean code principles, functional patterns, Zod validation, and error handling across various project scenarios.

🎯
understanding-saleor-domain🎯Skill

Explains Saleor e-commerce domain, revealing entity identification, deployment pipeline, and configuration management strategies for developers.

🎯
writing-graphql-operations🎯Skill

Generates type-safe GraphQL operations using gql.tada and urql, implementing a repository pattern for Saleor API interactions with robust error handling.

🎯
validating-pre-commit🎯Skill

Validates code quality by running linting, TypeScript compilation, tests, and CI checks before committing or pushing changes.

🎯
analyzing-test-coverage🎯Skill

Analyzes and generates comprehensive tests using Vitest and MSW, creating test builders, mocking repositories, and configuring integration tests.

🎯
managing-github-ci🎯Skill

Configures and manages GitHub Actions workflows, automates releases via Changesets, validates PRs, and troubleshoots CI pipeline failures.