# Data flow — colinhacks/zod

> Canonical page: https://codevetter.com/unpack/zod/data-flow

# Data flow — colinhacks/zod

Scanned commit 10dda3a3a4bc76ed0bf83e994de194587e489ef8 (2026-09-21). Generated by codevetter codevetter 1.12.0 on 2026-09-22.

A schema factory creates an immutable schema instance whose definition and structural capabilities are stored under `_zod`. Parsing sends a mutable payload and shared context through the schema graph; child schemas transform values and append raw issues, while the public boundary either returns a deep output structure or finalizes issues into a Zod error. Optional compilation replaces only the success path and deliberately delegates failure reporting to the interpreter. Separate conversion pipelines translate schema graphs to and from JSON Schema, while the documentation application turns MDX files into pages and text feeds.
- Public factories delegate to core factory functions that instantiate a supplied schema class with a normalized definition, preserving one shared construction mechanism across classic and mini APIs. — [packages/zod/src/v4/core/api.ts#L60-83](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/api.ts#L60-L83) [packages/zod/src/v4/classic/schemas.ts#L617-622](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/classic/schemas.ts#L617-L622) [packages/zod/src/v4/mini/schemas.ts#L124-127](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/mini/schemas.ts#L124-L127)
- `$ZodType` initializes checks, runs each check's attachment hooks, and selects either the raw parser or a parse-then-check runner; asynchronous checks are rejected from synchronous parse contexts. — [packages/zod/src/v4/core/schemas.ts#L203-260](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/schemas.ts#L203-L260)
- A synchronous public parse creates `{value, issues: []}`, calls `schema._zod.run`, rejects unexpected promises, finalizes raw issues through configured error maps, and otherwise returns the transformed value. — [packages/zod/src/v4/core/parse.ts#L22-39](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/parse.ts#L22-L39) [packages/zod/src/v4/core/util.ts#L944-981](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/util.ts#L944-L981)
- Object parsing validates each declared string or symbol key through its child schema, builds a fresh result object, prefixes child issue paths, enforces optionality, and then strips, rejects, passes, or validates undeclared keys through the catchall policy. — [packages/zod/src/v4/core/schemas.ts#L1973-2014](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/schemas.ts#L1973-L2014) [packages/zod/src/v4/core/schemas.ts#L2093-2150](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/schemas.ts#L2093-L2150) [packages/zod/src/v4/core/schemas.ts#L2196-2239](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/schemas.ts#L2196-L2239)
- Array, map, and set schemas allocate fresh output containers, run element schemas with the same parse context, prefix or nest element issues, and join child promises before returning. — [packages/zod/src/v4/core/schemas.ts#L1847-1901](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/schemas.ts#L1847-L1901) [packages/zod/src/v4/core/schemas.ts#L3460-3524](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/schemas.ts#L3460-L3524) [packages/zod/src/v4/core/schemas.ts#L3550-3592](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/schemas.ts#L3550-L3592)
- The `optin` and `optout` structural metadata controls whether a parent may omit a slot, whether a default supplies a replacement, and whether undefined output should omit a property or shorten a tuple. — [packages/zod/src/v4/core/schemas.ts#L127-146](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/schemas.ts#L127-L146) [packages/zod/src/v4/core/schemas.ts#L1973-2014](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/schemas.ts#L1973-L2014) [wiki/optionality.md#L32-64](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/wiki/optionality.md#L32-L64) [wiki/optionality.md#L162-176](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/wiki/optionality.md#L162-L176)
- Safe parsing keeps failure construction lazy: callers can branch on `success` without immediately finalizing issues or constructing a ZodError, and reading or replacing `error` releases captured raw input state. — [packages/zod/src/v4/core/parse.ts#L71-103](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/parse.ts#L71-L103)
- The cycle memoizer detects recursive schema graphs, allocates placeholder containers before descending, caches results per schema/input pair, resolves back-edges to those placeholders, and rejects cycles that pass through transforms. — [packages/zod/src/v4/core/memoizer.ts#L41-198](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/memoizer.ts#L41-L198) [packages/zod/src/v4/core/memoizer.ts#L215-330](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/memoizer.ts#L215-L330)
- Pipes run the input schema first and stop on substantive issues before invoking the output schema; codecs additionally transform between the sides and reverse direction when encoding. — [packages/zod/src/v4/core/schemas.ts#L4398-4454](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/schemas.ts#L4398-L4454) [packages/zod/src/v4/core/schemas.ts#L4482-4539](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/schemas.ts#L4482-L4539) [packages/zod/src/v4/core/parse.ts#L190-259](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/parse.ts#L190-L259)
- Compilation walks the schema graph into generated source, hoists runtime constants and user callbacks into closure arguments, constructs a function with the `Function` constructor, and records whether an invalid sentinel is a definitive rejection. — [packages/zod/src/v4/core/compile.ts#L237-300](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/compile.ts#L237-L300) [packages/zod/src/v4/core/doc.ts#L3-50](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/doc.ts#L3-L50)
- A compiled schema sends valid inputs directly through its generated parser, but marks the context and invokes the original runtime parser on an invalid sentinel so canonical issue construction remains single-sourced. — [packages/zod/src/v4/core/compile.ts#L151-199](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/compile.ts#L151-L199) [wiki/compile.md#L18-30](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/wiki/compile.md#L18-L30)
- JSON Schema emission traverses schemas into a shared `seen` map, invokes per-schema or registry processors, attaches metadata, extracts reused or cyclic nodes into definitions, applies overrides and deferred rewrites, and JSON-round-trips the final document. — [packages/zod/src/v4/core/to-json-schema.ts#L213-290](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/to-json-schema.ts#L213-L290) [packages/zod/src/v4/core/to-json-schema.ts#L301-440](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/to-json-schema.ts#L301-L440) [packages/zod/src/v4/core/to-json-schema.ts#L568-757](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/core/to-json-schema.ts#L568-L757)
- JSON Schema ingestion first serializes and parses the input into a finite plain JSON graph, detects the target draft, indexes local definitions and references, converts the root, and registers recovered metadata. — [packages/zod/src/v4/classic/from-json-schema.ts#L917-944](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/classic/from-json-schema.ts#L917-L944) [packages/zod/src/v4/classic/from-json-schema.ts#L862-912](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/zod/src/v4/classic/from-json-schema.ts#L862-L912)
- Documentation content flows from generated Fumadocs MDX collections into route loaders; full LLM text rereads the underlying content files, removes frontmatter, runs the Remark pipeline, and concatenates pages in metadata order. — [packages/docs/loaders/source.ts#L1-26](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/docs/loaders/source.ts#L1-L26) [packages/docs/loaders/get-llm-text.ts#L12-42](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/docs/loaders/get-llm-text.ts#L12-L42) [packages/docs/app/llms-full.txt/route.ts#L8-39](https://github.com/colinhacks/zod/blob/10dda3a3a4bc76ed0bf83e994de194587e489ef8/packages/docs/app/llms-full.txt/route.ts#L8-L39)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
