Type Safety Documentation Audit & Update
Audit every file in {{TYPE_DOCS_DIR}}/ against the live codebase and fix any errors, gaps, or stale information so the docs are the authoritative single source of truth for the six-layer type safety chain.
Before Starting
- Read every file in
{{TYPE_DOCS_DIR}}/ (README.md, TYPE_SAFETY.md, all files in layers/, validation/, and any other files present).
- Gather ground truth from the codebase for each layer — use the actual source files, generators, and validators as the authority.
Ground Truth Collection
For each layer, collect the following from the actual codebase (not from existing docs):
Layer 1 — Drizzle Schema
- Read
{{SCHEMA_PATH}} (first ~100 lines for structure, then count pgTable exports)
- Read
{{SCRIPTS_DIR}}/validate-db-alignment.ts to understand what the validator actually checks
- Read
{{SCRIPTS_DIR}}/generate-schema.ts (if it exists) to understand schema generation
- Count:
grep -c "export const .* = pgTable(" {{SCHEMA_PATH}}
- Note any tables with type annotations (e.g.,
PgTableWithColumns<any>)
Layer 2 — Zod Schemas
- Read
{{SCHEMAS_DIR}}/index.ts (first ~80 lines for structure, imports, BaseFiltersSchema)
- List other files in
{{SCHEMAS_DIR}}/ (custom schemas)
- Read
{{SCRIPTS_DIR}}/generate-zod-schemas.ts (first ~100 lines for pattern)
- Read
{{SCRIPTS_DIR}}/validate-semantic-alignment.ts to understand validation logic
- Note the four-schema pattern and type exports
Layer 3 — Services
- Read
{{SERVICES_DIR}}/base.service.ts for the Result pattern, class signature, and methods
- Sample one entity service file for the actual pattern
- List
src/lib/services/custom/ contents
- Read
{{SCRIPTS_DIR}}/generate-services.ts (first ~80 lines)
- Read
{{SCRIPTS_DIR}}/validate-services-alignment.ts
Layer 4 — API Routes
- Sample one route file from
{{API_DIR}}/ for the actual handler pattern
- List
src/app/api/custom/ directories
- Read
{{SCRIPTS_DIR}}/generate-routes.ts (first ~80 lines)
- Read
{{SCRIPTS_DIR}}/validate-routes-alignment.ts
Layer 5 — React Hooks
- Sample one hook file from
{{HOOKS_DIR}}/ for the actual pattern (keys, hooks, fetchApi, buildQueryString)
- List
{{HOOKS_DIR}}/custom/ contents
- Read
{{SCRIPTS_DIR}}/generate-hooks.ts (first ~80 lines)
- Read
{{SCRIPTS_DIR}}/validate-hooks-alignment.ts
- Check
src/app/providers.tsx for QueryClientProvider
Layer 6 — UI Components
- Sample one component from
{{COMPONENTS_DIR}}/simplified/ for the actual pattern
- Read
{{SCRIPTS_DIR}}/generate-ui-components.ts (first ~80 lines)
- Read
{{SCRIPTS_DIR}}/validate-ui-alignment.ts
Cross-Cutting
- Read
{{CONFIG_PATH}} (first ~30 lines) for tenant scoping context
- Read
src/lib/tenant.ts for getTenantOrgId
- Count entities at each layer to verify consistency
Audit Checklist
Compare every claim in the docs against ground truth. Flag and fix:
- Incorrect counts — table counts, entity counts, file counts
- Wrong patterns — code examples that don't match actual generated code
- Missing information — layers, patterns, or conventions not documented
- Stale references — files, paths, or commands that no longer exist
- Naming convention errors — incorrect camelCase/PascalCase/kebab-case mappings
- Validator behavior — what each validator actually checks vs. what docs claim
- Generator behavior — what each generator does (overwrites vs. skips existing) vs. what docs claim
- Custom code gaps — custom services, hooks, routes not mentioned or incorrectly described
- contentCategories discrepancy — verify the 148 vs 147 explanation is still accurate
- Lock-Before-Proceed protocol — ensure the protocol description matches actual validator exit codes and workflow
- Commands — ensure all pnpm commands listed match package.json
- Cross-references — ensure layer docs reference each other correctly
Update Rules
- Fix errors in place — do not create new files unless a section genuinely needs its own file
- Use actual code snippets from the codebase, not invented examples
- Keep the same document structure and voice — just make it accurate
- Update counts, paths, patterns, and examples to match reality
- If a doc file covers something that no longer exists, remove that section
- If the codebase has something undocumented, add it to the appropriate doc
- Update
{{TYPE_DOCS_DIR}}/validation/VALIDATION_STATUS.md with current actual status (run validators if possible)
- Update the README.md index if any files were added or removed
After Updating
- Review each updated file for internal consistency
- Ensure no doc references a pattern that contradicts another doc
- Verify all code examples are syntactically correct
- Confirm the README.md index accurately lists all files in
{{TYPE_DOCS_DIR}}/
1---2name: audit-docs3description: Audits type safety documentation against the live codebase and fixes errors, gaps, or stale information to keep docs authoritative.4---56# Type Safety Documentation Audit & Update78Audit every file in `{{TYPE_DOCS_DIR}}/` against the live codebase and fix any errors, gaps, or stale information so the docs are the authoritative single source of truth for the six-layer type safety chain.910## Before Starting11121. Read every file in `{{TYPE_DOCS_DIR}}/` (README.md, TYPE_SAFETY.md, all files in layers/, validation/, and any other files present).132. Gather ground truth from the codebase for each layer — use the actual source files, generators, and validators as the authority.1415## Ground Truth Collection1617For each layer, collect the following from the **actual codebase** (not from existing docs):1819### Layer 1 — Drizzle Schema20- Read `{{SCHEMA_PATH}}` (first ~100 lines for structure, then count pgTable exports)21- Read `{{SCRIPTS_DIR}}/validate-db-alignment.ts` to understand what the validator actually checks22- Read `{{SCRIPTS_DIR}}/generate-schema.ts` (if it exists) to understand schema generation23- Count: `grep -c "export const .* = pgTable(" {{SCHEMA_PATH}}`24- Note any tables with type annotations (e.g., `PgTableWithColumns<any>`)2526### Layer 2 — Zod Schemas27- Read `{{SCHEMAS_DIR}}/index.ts` (first ~80 lines for structure, imports, BaseFiltersSchema)28- List other files in `{{SCHEMAS_DIR}}/` (custom schemas)29- Read `{{SCRIPTS_DIR}}/generate-zod-schemas.ts` (first ~100 lines for pattern)30- Read `{{SCRIPTS_DIR}}/validate-semantic-alignment.ts` to understand validation logic31- Note the four-schema pattern and type exports3233### Layer 3 — Services34- Read `{{SERVICES_DIR}}/base.service.ts` for the Result<T> pattern, class signature, and methods35- Sample one entity service file for the actual pattern36- List `src/lib/services/custom/` contents37- Read `{{SCRIPTS_DIR}}/generate-services.ts` (first ~80 lines)38- Read `{{SCRIPTS_DIR}}/validate-services-alignment.ts`3940### Layer 4 — API Routes41- Sample one route file from `{{API_DIR}}/` for the actual handler pattern42- List `src/app/api/custom/` directories43- Read `{{SCRIPTS_DIR}}/generate-routes.ts` (first ~80 lines)44- Read `{{SCRIPTS_DIR}}/validate-routes-alignment.ts`4546### Layer 5 — React Hooks47- Sample one hook file from `{{HOOKS_DIR}}/` for the actual pattern (keys, hooks, fetchApi, buildQueryString)48- List `{{HOOKS_DIR}}/custom/` contents49- Read `{{SCRIPTS_DIR}}/generate-hooks.ts` (first ~80 lines)50- Read `{{SCRIPTS_DIR}}/validate-hooks-alignment.ts`51- Check `src/app/providers.tsx` for QueryClientProvider5253### Layer 6 — UI Components54- Sample one component from `{{COMPONENTS_DIR}}/simplified/` for the actual pattern55- Read `{{SCRIPTS_DIR}}/generate-ui-components.ts` (first ~80 lines)56- Read `{{SCRIPTS_DIR}}/validate-ui-alignment.ts`5758### Cross-Cutting59- Read `{{CONFIG_PATH}}` (first ~30 lines) for tenant scoping context60- Read `src/lib/tenant.ts` for getTenantOrgId61- Count entities at each layer to verify consistency6263## Audit Checklist6465Compare every claim in the docs against ground truth. Flag and fix:66671. **Incorrect counts** — table counts, entity counts, file counts682. **Wrong patterns** — code examples that don't match actual generated code693. **Missing information** — layers, patterns, or conventions not documented704. **Stale references** — files, paths, or commands that no longer exist715. **Naming convention errors** — incorrect camelCase/PascalCase/kebab-case mappings726. **Validator behavior** — what each validator actually checks vs. what docs claim737. **Generator behavior** — what each generator does (overwrites vs. skips existing) vs. what docs claim748. **Custom code gaps** — custom services, hooks, routes not mentioned or incorrectly described759. **contentCategories discrepancy** — verify the 148 vs 147 explanation is still accurate7610. **Lock-Before-Proceed protocol** — ensure the protocol description matches actual validator exit codes and workflow7711. **Commands** — ensure all pnpm commands listed match package.json7812. **Cross-references** — ensure layer docs reference each other correctly7980## Update Rules8182- Fix errors in place — do not create new files unless a section genuinely needs its own file83- Use actual code snippets from the codebase, not invented examples84- Keep the same document structure and voice — just make it accurate85- Update counts, paths, patterns, and examples to match reality86- If a doc file covers something that no longer exists, remove that section87- If the codebase has something undocumented, add it to the appropriate doc88- Update `{{TYPE_DOCS_DIR}}/validation/VALIDATION_STATUS.md` with current actual status (run validators if possible)89- Update the README.md index if any files were added or removed9091## After Updating92931. Review each updated file for internal consistency942. Ensure no doc references a pattern that contradicts another doc953. Verify all code examples are syntactically correct964. Confirm the README.md index accurately lists all files in `{{TYPE_DOCS_DIR}}/`