スキル一覧に戻る
saleor

designing-zod-schemas

by saleor

A tool that helps you automate the creation of data models in Saleor.

22🍴 3📅 2026年1月23日
GitHubで見るManusで実行

SKILL.md


name: designing-zod-schemas description: "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." allowed-tools: "Read, Grep, Glob, Write, Edit"

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

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

NeedPatternExample
Basic validationPrimitivesz.string().min(1)
Domain safetyBranded typestransform((v) => v as EntitySlug)
Multiple typesDiscriminated unionz.discriminatedUnion('type', [...])
Cross-field rulesRefinement.refine((data) => ...)
Data normalizationTransform.transform((v) => v.trim())
Partial updatesPartial schemaSchema.partial()

Quick Reference

Common Schema Shapes

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

Safe Parsing

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:

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

PhaseValidateCommand
Schema definedNo TS errorsnpx tsc --noEmit
Types inferredz.infer worksCheck type in IDE
Validation workssafeParse testspnpm test

Common Mistakes

MistakeIssueFix
Manual type definitionsType driftUse z.infer<typeof Schema>
Using .parse() directlyThrows on invalidUse .safeParse() for error handling
Missing .optional()Runtime errorsMark optional fields explicitly
Complex refinementsHard to debugBreak into smaller schemas
Not using branded typesType confusionUse .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
  • 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).

スコア

総合スコア

65/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

レビュー

💬

レビュー機能は近日公開予定です