Skip to content
Back to skills

Collection

ASecurity

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.

  • 24 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 8, 2026
developmenttypescriptgotestingdocumentation

Works with

  • mcp

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add mattnigh/skills_collection --skill collection --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Collection?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Collection
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mattnigh-collection-a94d00fe/badge)](https://www.skillsdirectory.com/skills/mattnigh-collection-a94d00fe)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
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](#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<typeof EntitySchema>;
```

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

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

Files in this skill

  • 0Chan-smc__claude-code-workflow-lab__claude__skills__frontend-dev-guidelines__SKILL.md15.1 KB
  • 17hz__nextjs-template__claude__skills__example-skill__SKILL.md316 B
  • 1ambda__dataops-platform__claude__skills__context-synthesis__SKILL.md3.5 KB
  • 1natsu172__dotfiles__claude__skills__git-analysis__SKILL.md5.4 KB
  • 1natsu172__dotfiles__claude__skills__github-pr-best-practices__SKILL.md7.7 KB
  • 23Maestro__prospect-pipeline__claude__skills__npid-fastapi-skill.md26.1 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-javascript__SKILL.md15.7 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-python__SKILL.md17.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-expression-syntax__SKILL.md9.4 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-mcp-tools-expert__SKILL.md12.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-node-configuration__SKILL.md16.6 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-workflow-patterns__SKILL.md11.2 KB
  • 3x-Projetos__claude-memory-framework__claude__skills__scientist__SKILL.md14.8 KB
  • 5MinFutures__futures-arena__claude__skills__migration-tracker__SKILL.md16.2 KB
  • 5MinFutures__futures-arena__claude__skills__planning-guidelines__SKILL.md11.8 KB
  • 92Bilal26__TaskPilotAI__claude__skills__assessment-builder__SKILL.md17.5 KB
  • 92Bilal26__TaskPilotAI__claude__skills__book-scaffolding__SKILL.md19.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__code-validation-sandbox__SKILL.md6.2 KB
  • 92Bilal26__TaskPilotAI__claude__skills__exercise-designer__SKILL.md18.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__learning-objectives__SKILL.md24.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.