| name | subsystem-audit |
| description | Audit all design docs against the canonical system design for coverage, drift, duplication, interfaces, YAML schema, self-containment, and dependency graph validity. Use when adding new subsystems, verifying spec quality, or preparing for task decomposition. |
| argument-hint | [--fix] [--doc <name>] |
| metadata | {"short-description":"Audit design docs against canonical source of truth"} |
Subsystem Design Doc Audit
Audit all design docs at specs/design/ against the canonical source of truth at specs/original-system-design.md. Identifies gaps, drift, duplication, missing interfaces, invalid YAML, broken dependencies, and incomplete specs. Optionally fixes issues in-place.
Canonical source: specs/original-system-design.md is the single source of truth. When there is a conflict between a design doc and the canonical source, the canonical source wins.
Workflow State Machine
START
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 0: READ CANONICAL SOURCE โ
โ โ
โ Read specs/original-system-design.md section 3 โ
โ (Subsystems) to get the authoritative list of 17 โ
โ subsystems. Also check for unlisted subsystems โ
โ (e.g. Knowledge Base at /v1/knowledge/). โ
โ โ
โ If --doc <name> is provided, audit only that doc. โ
โ Otherwise audit all 15 design docs. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 1: SUBSYSTEM COVERAGE โ
โ โ
โ Map each of the 17 subsystems to a design doc. โ
โ Report any subsystem without a dedicated doc. โ
โ โ
โ Current mapping (15 docs โ 17+1 subsystems): โ
โ tenancy-model โ #1 Auth, #2 Org/Team โ
โ billing-pricing โ #3 Billing, #4 Credit โ
โ notifications โ #5 Notifications โ
โ webhooks โ #6 Webhooks โ
โ assets โ #7 Assets, #8 Uploader, #9 Ret. โ
โ social-platform โ #10 OAuth, #11 Publisher โ
โ analytics โ #12 Analytics โ
โ ai-generation โ #13 AI Generation โ
โ prompt-bandit โ #14 Experiments โ
โ temporal-wf โ #15 Workflows โ
โ rendering-arch โ Campaigns + Rendering โ
โ content-pipeline โ Content lifecycle โ
โ knowledge-base โ Knowledge Base (unlisted) โ
โ scraping โ Trend Discovery (deferred) โ
โ overview โ Cross-cutting โ
โ โ
โ โโ GAP FOUND โ If --fix, create new design doc โ
โ โ using the design-doc skill pattern โ
โ โโ ALL COVERED โ Continue โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 2: INTERFACES CHECK โ
โ โ
โ Grep for `_No interfaces defined yet._` across all โ
โ design docs. โ
โ โ
โ โโ FOUND โ If --fix, write Effect-style interfaces: โ
โ โ - Read packages/core/src/domains/ for patterns โ
โ โ - Context.Tag ports, services, layers โ
โ โ - Repository ports with ListParams/PaginatedResultโ
โ โ - Application services with CoreError โ
โ โ - Middleware (if applicable) โ
โ โ - API route contracts โ
โ โโ NONE โ Continue โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 3: YAML SCHEMA VALIDATION โ
โ โ
โ Check all invariants/failure_modes/verification โ
โ YAML blocks for correct tx schema: โ
โ โ
โ invariants: โ
โ - id: INV-XXX-NNN # ^INV-[A-Z0-9-]+$ โ
โ statement: "..." โ
โ severity: critical|high|medium|low โ
โ verified_by: [REQ-XXX-NNN] # minItems(1) โ
โ โ
โ failure_modes: โ
โ - condition: "..." โ
โ impact: "..." โ
โ handling: "..." โ
โ โ
โ verification: โ
โ - requirement_id: REQ-XXX-NNN # ^REQ-[A-Z0-9-]+$ โ
โ test_type: unit|integration|e2e|property|manual โ
โ target: "..." โ
โ โ
โ WRONG field names to catch: โ
โ invariants: descriptionโstatement, no verified_by โ
โ failure_modes: triggerโcondition, mitigationโhandlingโ
โ verification: idโrequirement_id, typeโtest_type, โ
โ descriptionโtarget, VER-โREQ- โ
โ โ
โ โโ ISSUES โ If --fix, rewrite with correct fields โ
โ โโ CLEAN โ Continue โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 4: DUPLICATION AUDIT โ
โ โ
โ Check for content duplicated across docs. โ
โ Each subsystem doc should own its content โ no โ
โ copy-paste between docs. Cross-cutting concerns โ
โ belong in overview-design.md only. โ
โ โ
โ Check for: โ
โ - Same DB table schema in multiple docs โ
โ - Same Effect port defined in multiple docs โ
โ - Identical paragraphs copy-pasted โ
โ - Same ASCII diagrams repeated โ
โ โ
โ Ownership rules: โ
โ agent_threads/messages โ ai-generation-design โ
โ credit_ledger/usage_records โ billing-pricing โ
โ team_media_assets โ assets-design โ
โ social_accounts โ social-platform-design โ
โ campaigns โ rendering-architecture-design โ
โ content items/assets/posts โ content-pipeline โ
โ post_performance โ analytics-design โ
โ knowledge/diffs โ knowledge-base-design โ
โ โ
โ โโ DUPES โ If --fix, keep in owner doc, replace โ
โ โ duplicate with cross-reference: โ
โ โ "See [x-design](x-design.md) for Y." โ
โ โโ CLEAN โ Continue โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 5: SELF-CONTAINMENT CHECK โ
โ โ
โ Each design doc must have these H1 sections: โ
โ - Summary โ
โ - Architecture (enough detail to implement from) โ
โ - Data Model (tables this subsystem OWNS) โ
โ - Interfaces (Effect ports + services + API routes) โ
โ - Invariants (non-empty YAML) โ
โ - Failure Modes (non-empty YAML) โ
โ - Verification (non-empty YAML) โ
โ โ
โ โโ INCOMPLETE โ If --fix, add missing sections โ
โ โโ COMPLETE โ Continue โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 6: CANONICAL DRIFT CHECK โ
โ โ
โ For each design doc, read its corresponding section โ
โ from specs/original-system-design.md. โ
โ โ
โ Section mapping: โ
โ ยง1 โ tenancy-model-design โ
โ ยง2 โ assets-design โ
โ ยง4 โ content-pipeline-design โ
โ ยง5 โ rendering-architecture-design โ
โ ยง6 โ social-platform-integration-design โ
โ ยง9 โ billing-and-pricing-design โ
โ ยง10 โ analytics-design โ
โ ยง11 โ scraping-and-trend-discovery-design โ
โ ยง13 โ temporal-workflows-design โ
โ ยง3,7,8,12,14-20 โ overview-design โ
โ โ
โ Report: โ
โ MISSING โ canonical has it, design doc doesn't โ
โ CONTRADICTION โ design doc disagrees with canonical โ
โ OK โ content matches โ
โ โ
โ โโ DRIFT โ If --fix, add missing content / fix โ
โ โ contradictions (canonical wins) โ
โ โโ ALIGNED โ Continue โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 7: DEPENDENCY GRAPH VALIDATION โ
โ โ
โ Read `depends_on` from all doc frontmatter. โ
โ Build the full dependency graph. โ
โ โ
โ Validate: โ
โ - No circular dependencies โ
โ - Graph forms a clean DAG โ
โ - depends_on reflects BUILD ORDER โ
โ - Every doc that uses tables/ports from another โ
โ subsystem lists it in depends_on โ
โ โ
โ Print topological sort (build order): โ
โ โ
โ Layer 0: overview, temporal-workflows, tenancy-modelโ
โ Layer 1: assets, billing, notifications, scraping, โ
โ social-platform, webhooks โ
โ Layer 2: ai-generation, analytics, content-pipeline โ
โ Layer 3: knowledge-base, rendering-architecture โ
โ Layer 4: experiments-design โ
โ โ
โ โโ ISSUES โ If --fix, update depends_on โ
โ โโ VALID DAG โ Continue โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 8: SYNC โ
โ โ
โ source ~/.zshrc >/dev/null 2>&1; eval 'tx doc sync' โ
โ โ
โ โโ ALL SYNCED โ Print summary report โ
โ โโ ERRORS โ Fix and re-sync โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
DONE โ Print summary table