Public evidence: generated by OpenThunder’s keyless engine (no AI) from colinhacks/zod@680d19f on 2026-10-19. Reproduce it: openthunder lens generate --no-narrate && openthunder lens export. ← Evidence Gallery

zod: Architecture

zod · 680d19f7d1e0 · generated 2026-10-19T06:57:03.859Z · static analysis

Architecture health: 54/100 (F)

Overview

zod is a JavaScript/TypeScript pnpm project, built with React, Next.js, and Vite. It runs as a frontend (.), backed by 8 shared packages. It stores data in Drizzle and calls OpenAI and Vercel AI SDK across an explicit AI provider boundary. The main structural risks to watch: 12 oversized "god" files and 1 circular import chain. The file with the widest blast radius is packages/zod/src/v4/core/util.ts: 82 files depend on it at runtime; part of an import cycle; oversized and doing too much.

_This entire analysis runs on your machine with no AI required. Connect a model provider to also narrate the reasoning and recover decisions._

Where to start

  1. packages/zod/src/v4/index.ts Core module: 115 other modules depend on it, so it shapes much of the system.
  2. packages/zod/src/v4/core/util.ts Core module: 85 other modules depend on it, so it shapes much of the system.
  3. packages/zod/src/v4/core/errors.ts Core module: 74 other modules depend on it, so it shapes much of the system.
  4. packages/zod/src/v4/core/checks.ts Core module: 70 other modules depend on it, so it shapes much of the system.
  5. scripts/triage-signal.ts Key flow: Authentication, a high-risk path that enters at invoke triage-signal.ts (scripts/triage-signal.ts).
  6. packages/docs/loaders/get-llm-text.ts Key flow: AI provider call, a high-risk path that enters at invoke get-llm-text.ts (packages/docs/loaders/get-llm-text.ts).
  7. scripts/check-comments.ts Key flow: File changes / writes, a high-risk path that enters at invoke check-comments.ts (scripts/check-comments.ts).
  8. packages/bench/metabench.ts Change with care: 46 files depend on it at runtime.

System map

flowchart TD
  subgraph sys_boundary["zod"]
    node["."]
    benchmarks["benchmarks"]
    docs["docs"]
    integration["integration"]
    mini["mini"]
    resolution["resolution"]
    treeshaking["treeshaking"]
    tsc_perftest["tsc-perftest"]
    zod["zod"]
    store_drizzle[("Drizzle")]
  end
  subgraph ai_boundary["AI Provider Boundary"]
    ai_openai{{"OpenAI"}}
    ai_vercel_ai_sdk{{"Vercel AI SDK"}}
  end
  benchmarks -->|uses| zod
  docs -->|uses| node
  integration -->|uses| zod
  integration -->|uses| mini
  mini -->|uses| zod
  mini -->|uses| node
  resolution -->|uses| mini
  resolution -->|uses| zod
  resolution -->|uses| node
  treeshaking -->|uses| zod
  tsc_perftest -->|uses| zod
  zod -->|uses| node
  node -->|uses| zod
  class node frontend
  class benchmarks library
  class docs library
  class integration library
  class mini library
  class resolution library
  class treeshaking library
  class tsc_perftest library
  class zod library
  class store_drizzle store
  class ai_openai aiprovider
  class ai_vercel_ai_sdk aiprovider
  classDef frontend fill:#2563eb,stroke:#93c5fd,color:#fff,stroke-width:2px;
  classDef service fill:#059669,stroke:#6ee7b7,color:#fff,stroke-width:2px;
  classDef store fill:#d97706,stroke:#fcd34d,color:#fff,stroke-width:2px;
  classDef queue fill:#9333ea,stroke:#d8b4fe,color:#fff,stroke-width:2px;
  classDef job fill:#4f46e5,stroke:#a5b4fc,color:#fff,stroke-width:2px;
  classDef external fill:#475569,stroke:#cbd5e1,color:#fff,stroke-width:2px;
  classDef aiprovider fill:#e11d48,stroke:#fda4af,color:#fff,stroke-width:2px;
  classDef library fill:#0891b2,stroke:#67e8f9,color:#fff,stroke-width:2px;
  classDef cli fill:#0d9488,stroke:#5eead4,color:#fff,stroke-width:2px;
  classDef user fill:#64748b,stroke:#e2e8f0,color:#fff,stroke-width:2px;
  classDef muted fill:#334155,stroke:#64748b,color:#cbd5e1,stroke-width:1px;

Critical flows

Authentication high risk

Entry: invoke triage-signal.ts (scripts/triage-signal.ts)

writes files to the working tree (disk); calls an external service (external API); returns a response to the caller (client)

Authentication guards every protected resource; a regression here can expose data or grant unauthorized access.

sequenceDiagram
  actor C0 as Caller
  participant F0 as triage-signal.ts
  participant Disk as disk
  participant External as external API
  C0->>F0: invoke triage-signal.ts
  F0->>Disk: writes files to the working tree
  F0->>External: calls an external service
  F0-->>C0: returns a response to the caller

AI provider call high risk

Entry: invoke get-llm-text.ts (packages/docs/loaders/get-llm-text.ts)

Provider calls cost money and shape model output; mistakes leak prompts, burn budget, or route to the wrong model.

sequenceDiagram
  actor C0 as Caller
  participant F0 as get-llm-text.ts
  participant F1 as llms-full.txt/route.ts
  participant F2 as llms.txt/route.ts
  C0->>F0: invoke get-llm-text.ts

File changes / writes high risk

Entry: invoke check-comments.ts (scripts/check-comments.ts)

writes files to the working tree (disk); calls an external service (external API); returns a response to the caller (client)

Direct writes to the working tree are hard to reverse; an unguarded write can clobber user code.

sequenceDiagram
  actor C0 as Caller
  participant F0 as check-comments.ts
  participant F1 as reindex.mjs
  participant F2 as triage-signal.ts
  participant F3 as update-iso-4217.ts
  participant F4 as write-stub-package-jsons.ts
  participant Disk as disk
  participant External as external API
  C0->>F0: invoke check-comments.ts
  F0->>Disk: writes files to the working tree
  F1->>Disk: writes files to the working tree
  F2->>Disk: writes files to the working tree
  F2->>External: calls an external service
  F2-->>C0: returns a response to the caller
  F3->>Disk: writes files to the working tree
  F3->>External: calls an external service
  F4->>Disk: writes files to the working tree

Fragile zones

Architecture rules

blocking Route all AI provider calls through a single provider abstraction; do not scatter direct SDK calls (OpenAI, Vercel AI SDK) across feature modules.

A single provider boundary keeps the system model-agnostic, makes routing/failover/cost-tracking possible, and is the core differentiator of this product.

blocking Persist and read data through the data-access layer (packages/zod); do not issue raw Drizzle queries from request handlers or feature modules.

Centralizing persistence keeps schema knowledge in one place, preserves invariants/migrations, and contains the blast radius of storage changes.

blocking Change packages/zod/src/v4/core/util.ts with care: 82 files depend on it at runtime; part of an import cycle; oversized and doing too much. Preserve its public signatures, keep changes additive where possible, and run/extend its tests before and after.

This file has a wide blast radius (fan-in 85, fan-out 4, risk score 173.3); a careless edit ripples through many dependents.

blocking Change packages/bench/metabench.ts with care: 46 files depend on it at runtime. Preserve its public signatures, keep changes additive where possible, and run/extend its tests before and after.

This file has a wide blast radius (fan-in 46, fan-out 1, risk score 92.3); a careless edit ripples through many dependents.

blocking Change packages/zod/src/v4/core/errors.ts with care: 5 files depend on it at runtime; types used by 69 modules. Preserve its public signatures, keep changes additive where possible, and run/extend its tests before and after.

This file has a wide blast radius (fan-in 74, fan-out 5, risk score 79.5); a careless edit ripples through many dependents.

blocking Change packages/zod/src/v4/core/checks.ts with care: 3 files depend on it at runtime; types used by 67 modules; oversized and doing too much. Preserve its public signatures, keep changes additive where possible, and run/extend its tests before and after.

This file has a wide blast radius (fan-in 70, fan-out 5, risk score 77.8); a careless edit ripples through many dependents.

blocking Change packages/zod/src/index.ts with care: 30 files depend on it at runtime. Preserve its public signatures, keep changes additive where possible, and run/extend its tests before and after.

This file has a wide blast radius (fan-in 42, fan-out 1, risk score 60.3); a careless edit ripples through many dependents.

blocking Change packages/bench/benchUtil.ts with care: 21 files depend on it at runtime. Preserve its public signatures, keep changes additive where possible, and run/extend its tests before and after.

This file has a wide blast radius (fan-in 21, fan-out 1, risk score 42.3); a careless edit ripples through many dependents.

warning Do not add imports that deepen existing import cycles (e.g. packages/zod/src/v4/core/core.ts → packages/zod/src/v4/core/util.ts). Break cycles when you touch the files involved.

Circular dependencies make modules impossible to reason about or test in isolation and cause load-order bugs.

advisory Do not add new responsibilities to oversized files (packages/zod/src/v3/types.ts, packages/zod/src/v4/core/schemas.ts, packages/zod/src/v4/classic/schemas.ts, packages/zod/src/v4/core/compile.ts, packages/zod/src/v4/mini/schemas.ts); extract new logic into focused modules instead.

Large multi-purpose files are change magnets that accumulate coupling and resist testing; keeping them from growing limits the damage.