--- name: component-audit description: "Deep audit of a component library: inventory, usage, duplication, complexity, coverage gaps. Triggers: audit my components, unused components, what components do I have, assess my library. Not for a whole-system view (system-health) or AI index files (codebase-index)." allowed-tools: Read, Write, Grep, Glob, Bash(cat:*), Bash(find:*), Bash(head:*), Bash(ls:*), Bash(sort:*), Bash(tail:*), Bash(wc:*), Bash(npm view:*) references: - ../../knowledge-notes/component-governance.md - ../../knowledge-notes/component-bestiary-reference.md - ../../knowledge-notes/output-discipline.md --- # Component audit A skill for auditing a design system's component library across four dimensions: usage signals, complexity distribution, duplication, and coverage gaps. Produces an inventory with tiered findings and a prioritised action list. ## Before you begin: verify references Confirm that every path in this skill's frontmatter `references:` exists relative to this SKILL.md. If any is missing, stop: the install is incomplete, usually because a flattening installer (for example `npx skills install`) dropped the repo-root `knowledge-notes/` directory. Tell the user to reinstall by a method in `1-INSTALL.md` and run `verify-install.sh` from the install root. Proceed without the references only if the user explicitly says to, and then say in the output that it was produced without the pack's reference material. ## Context Component libraries accumulate silently. New components arrive through contributions. Old components persist because nobody wants to be the one who removes them. Variants proliferate because each edge case adds one more. The result is a library that grows in mass without growing proportionally in value. A component audit brings the library back into focus: what is there, what is used, what duplicates what, and what is missing that teams have been building around. It is the maintenance work that makes the next year of development faster. --- ## Configuration If `.ds-ops-config.yml` exists, follow the configuration-and-recurring knowledge note (`../../knowledge-notes/configuration-and-recurring.md`) for loading, integration fallbacks and recurring runs. This skill reads: - `system.framework` — pre-selects framework-specific inventory guidance - `system.component_count` — pre-populates the small-system gate - `severity.*` — finding severity overrides - `integrations.*` — component data sources (see below) - `recurring.*` — comparison with the previous audit ## Auto-pull integrations **Figma MCP** (`integrations.figma.enabled: true`): - Read the published library from `integrations.figma.file_key` via Figma MCP - Extract the component inventory: names, variant counts, description status - Figma library analytics (detach and insertion counts per component) are available only through the REST Library Analytics API on an Enterprise plan. If the team has it, pull detach rates; if not, say so and don't list detach rates as a signal - Cross-reference the Figma inventory against the code inventory to detect components that exist in design but not in code (or vice versa) **npm registry** (`integrations.npm.enabled: true`): - Pull download statistics for `integrations.npm.package_name` (or each package in `integrations.npm.scoped_packages` for monorepos) using `npm view [package] --json` or the npm registry API - Use download trends (last 30 days, last 90 days) as a usage signal in Dimension 1 - For monorepos: note that per-package downloads are unreliable (see monorepo handling) — use as a directional signal only **Storybook** (`integrations.storybook.enabled: true`): - Fetch the story index from `integrations.storybook.url/index.json` - Extract component list, story counts per component, and documentation status - Components with zero stories are likely undocumented — flag in Dimension 1 **GitHub** (`integrations.github.enabled: true`): - Use `gh api search/code` to find consuming repositories that import each component, then read or clone those repos to count (see the note's GitHub caution) - Pull PR activity for the component library — no PRs in 12+ months is a maintenance signal, not evidence the component is unused - Pull open issues tagged with component names to surface known problems **Documentation platform** (`integrations.documentation.enabled: true`): - If platform is `zeroheight`: use the Zeroheight API to pull page list and last-updated dates per component - If platform is `supernova`: use the Supernova API to pull component documentation coverage - If platform is `storybook`: same as Storybook integration above (docs tab status) - Map documentation coverage to the component inventory — components without docs pages are flagged in Dimension 3 ## Step 0: Identify what you're looking at Before auditing components, determine what kind of shared UI this is. The library type changes which dimensions matter and how findings should be framed. **Classify from codebase signals:** - **Design system** — Full template applies. All four audit dimensions (usage, complexity, duplication, coverage) plus composition graph and AI readiness. - **Component library** — Focus on complexity distribution, duplication, and coverage gaps. Usage signals may not exist yet — note this rather than flagging it as a problem. Skip AI readiness unless the team has signalled interest. - **Pattern library** — Focus on duplication and documentation completeness per pattern. Complexity distribution is less meaningful because patterns are reference implementations, not consumed packages. Coverage gaps should be framed as "patterns your team builds frequently but hasn't documented" rather than "components missing from the system." - **Utility collection** — Focus on duplication and naming consistency. A utility collection with overlapping helpers is actively harmful; one with clear, non-overlapping utilities is doing its job. Skip coverage gaps — a utility collection is not trying to be comprehensive. **Include the classification in the report header** as "Library type: [Design system / Component library / Pattern library / Utility collection]" and skip dimensions that don't apply. --- ## Step 1: Gather the component inventory Ask for or confirm (skip questions already answered by auto-pull): - Access to the component library: Figma library, Storybook, npm package, or component documentation - The framework and component format: React (JSX/TSX), Vue SFC (`.vue`), Twig/Fractal (`.twig`), Svelte (`.svelte`), or Web Components - Whether this is a monorepo or single-package library (see monorepo handling below) - Any usage data available: adoption signals, access logs, consumer surveys, or engineering usage stats - Any known problem areas: components teams avoid, components with open bug reports, components that frequently generate support questions If usage data is not available, the audit focuses on structural assessment rather than usage analysis. Note in the output which findings are based on direct analysis and which are inferred from structure. **Small-system note (fewer than 5 components):** With 1–4 components, the audit shifts from pattern detection to per-component deep dive. Skip complexity distribution analysis (Step 3, Dimension 2) — it is not meaningful at this scale. Instead, focus on: completeness of each component's API and state coverage, documentation status per component, and whether the system covers the team's highest-frequency needs. The coverage gaps dimension (Step 3, Dimension 4) becomes the most valuable — what common patterns are teams building locally because the system does not yet provide them? The answer to that question is the system's roadmap. ## Step 1b: Record which usage signals exist Don't ask the user to choose signals; record which ones are actually in reach, then say what the usage assessment can and can't claim: - **Code imports** — the one signal that is almost always available: count imports of each component across the repos in reach (with a positive control on a component you know is used). In a design system repo with no consumers checked out, this counts nothing useful; say so - **Figma instantiations and detach rates** — Enterprise Library Analytics only - **npm downloads** — direction only, and unreliable for monorepos (below) - **Support tickets, surveys, production analytics** — only if the user hands them over; never say a team was surveyed unless the user did the survey If none is in reach, the audit is structural: every component's usage status is "Unknown", the report says so once at the top, and Dimension 1 is skipped rather than filled with inference. If no component source, Figma library or Storybook index is in reach either, stop and ask where the components live; an inventory can't be built from a description. **Monorepo handling:** Monorepo structures break standard usage signals. A component published as `@system/button` in its own package may show high npm downloads while `@system/date-picker` shows low — but the download count reflects bundling behaviour, not actual component usage by teams. Apply these adjustments: - **Per-package download counts are unreliable.** In monorepos, teams often install the umbrella package or a subset of packages. Use import analysis across consuming products instead of download counts where possible. - **Detect versioning patterns:** Components with `-next` or `-v2` suffixes (e.g. `button-next`, `DataTableV2`) indicate in-flight migrations. Count both versions but flag the pair — the older version is a deprecation candidate, the newer is not yet fully adopted. Neither version's usage number is accurate in isolation. - **Classify private vs. public components:** Components with underscore prefixes (`_InternalBase`, `_LayoutHelper`), components in directories named `internal/`, `private/`, or `utils/`, and components not re-exported from the package's public barrel file (`index.ts`) are internal implementation details. Exclude them from the public component count and from coverage gap analysis. Count them separately as "internal utilities." - **Distinguish utility components from user-facing components:** Layout primitives (`Box`, `Stack`, `Flex`, `Grid`, `VisuallyHidden`, `Portal`) are infrastructure components, not user-facing UI. They should be counted in the inventory but categorised separately. A library with 30 components where 15 are layout utilities and 15 are UI components has a different health profile than one with 30 UI components. **Framework-specific inventory notes:** - **Vue SFC:** Each `.vue` file in the components directory is typically one component. Check for `