Design System Architecture: Building, Scaling & Governing the System
Part of Cognikit. A kit that gives AI agents cognitive abilities.
This skill is about the engineering of a design system itself, not the
visual style it contains. Use a visual design skill for choosing visual
direction (brutalism, minimalist, etc.). This skill focuses on the
engineering, not the aesthetics. Use this skill for the architecture,
governance, token pipeline, contribution model, versioning, drift detection,
and scaling of the system as a product.
AI execution flow (follow in order)
- Assess: Determine the system's maturity (Step 1 below). Is it
new, growing, or mature with many consumers?
- Architecture: Design or audit the token pipeline, monorepo
structure, and component package boundaries (Step 2).
- Governance: Establish or audit the contribution model, decision
rights, and review tiers (Step 3).
- Versioning: Set up SemVer, changelog, deprecation policy, and
codemod workflow (Step 4).
- Drift detection: Install CI gates, token validation, and
component-usage scanning (Step 5).
- Adoption: Measure adoption, coverage, and health score (Step 6).
- AI readiness: Generate
AGENTS.md, llms.txt, and component
manifests so AI agents build within the system, not around it (Step 7).
- Verify: Run the pre-flight checklist at the bottom of this file.
When to use
- Building a new design system from scratch (token architecture, package
structure, governance)
- Scaling an existing system to 10+ consumer teams
- Setting up a Figma-to-code token pipeline
- Establishing a contribution model (who can add components, tokens)
- Versioning and deprecating design system packages
- Detecting and preventing design drift (hardcoded values, reinvented
components)
- Multi-brand or multi-theme orchestration
- Making a design system AI-agent ready (CLAUDE.md, AGENTS.md, manifests)
- Auditing a design system's health and adoption
When NOT to use
- Choosing a visual style (brutalism, minimalist, etc.)
- Building individual UI components
- Responsive/adaptive layout decisions
Those are visual design tasks, not system architecture tasks.
Step 1: Assess maturity
| Stage |
Consumers |
Tokens |
Components |
Governance |
Action |
| New |
0-2 |
Ad hoc |
5-20 |
None |
Build foundation (Step 2) |
| Growing |
3-9 |
Some structure |
20-50 |
Informal |
Add governance (Step 3) |
| Mature |
10+ |
Three-tier |
50-200 |
Hybrid model |
Optimize, drift detect (Step 5) |
| Scaling |
50+ |
Multi-brand |
200+ |
Federated |
Multi-brand orchestration |
Step 2: Architecture
Token pipeline
The token pipeline is the contract. Components are replaceable
implementations of a tokenized system.
Three-tier token architecture (industry standard since W3C DTCG spec,
October 2025):
- Reference (primitive) tokens: raw values, no opinions.
blue.600: #2563EB, space.4: 16px. Names may describe values here
only. This is the only tier where value-naming is allowed.
- Semantic tokens: meaning and purpose.
color.action.primary: {blue.600}, color.text.body: {gray.900}. Name by purpose, never
value. This is where the design language lives.
- Component tokens: scoped to specific UI.
button.bg.primary: {color.action.primary}. Build this tier only when needed. Most teams
before Series C only need tiers 1 and 2.
Rules:
- Name tokens by purpose, not value.
color.action.primary is correct.
blue-500 as a semantic name is wrong.
- Start with 30-50 tokens covering color, space, type, and radius. A
400-token vocabulary nobody adopts fails.
- One token source drives Figma, CSS, iOS, and Android without a
hand-built translation layer (W3C DTCG format).
- Dark mode, theming, and rebranding are token swaps, not rewrites.
- Motion tokens (duration, easing, spring) are part of the system,
alongside color and type.
See references/token-architecture.md for the full pipeline spec,
DTCG format, and Style Dictionary configuration.
Monorepo structure
design-system/
├── package.json # Root: scripts, dev tooling
├── pnpm-workspace.yaml # Workspace config
├── figma.config.json # Figma Code Connect
├── packages/ # Published packages
│ ├── tokens/ # Design tokens (DTCG JSON)
│ ├── theme/ # Theme engine (token compilation)
│ ├── react/ # React component library
│ ├── icons/ # Icon library
│ ├── utils/ # Shared utilities
│ └── cli/ # CLI tooling (optional)
├── apps/ # Applications (not published)
│ ├── docs/ # Documentation site
│ └── demo/ # Demo app
├── scripts/ # Build scripts (token sync, icon gen)
└── .github/workflows/ # CI (lint, test, drift detect, publish)
Rules:
- Inter-package dependencies use
workspace:*.
- Public API is the package root export. Internal modules are restricted
(ESLint
restricted-imports bans deep imports).
- One publish pipeline per package. Independent versioning per package
or unified versioning (choose based on release cadence).
See references/monorepo-structure.md for detailed package roles,
build pipelines, and publish workflows.
Component package boundaries
Each component package exports:
- The component (React, Vue, Flutter, etc.)
- TypeScript types / Dart classes
- Props table (documented API)
- Accessibility spec (ARIA patterns, keyboard nav, focus management)
- Motion spec (duration token, easing token, reduced-motion behavior)
- Usage examples
- When to use / when not to use
Component API rules:
- Props are typed and documented. No
any types.
- Variant props use a union type, not boolean combinations.
variant: "primary" | "secondary" | "ghost" not primary?: boolean, secondary?: boolean, ghost?: boolean.
- Compound components (Button.Icon, Button.Label) for composition over
prop explosion.
- Forward ref always (React). Expose imperative API only when necessary.
- Default props are token references, not hardcoded values.
See references/component-api.md for full API design patterns.
Step 3: Governance
Contribution models
| Model |
Owner |
Scales |
Use when |
| Centralized |
Single dedicated team |
Slow |
System is young, < 5 consumers |
| Federated |
Many teams, no single owner |
Fast short-term, expensive long-term |
Rare. Not recommended. |
| Hybrid (cyclical) |
Small core + embedded contributors |
Well |
10+ consumers. Almost always right. |
Hybrid model (recommended for 10+ consumers):
- Small core team (2-4 people) owns tokens, accessibility review, release
cadence.
- Embedded contributors from product teams ship components and propose
changes.
- Core team reviews for consistency. Product teams own domain-specific
patterns.
Document the model in CONTRIBUTING.md at the repo root: who can merge
to main, who can propose components, who decides on tokens, what the SLA
on PR review is.
Contribution tiers
| Tier |
Scope |
Review intensity |
Who can propose |
| Core |
Tokens, primitives, architecture, policy |
Highest |
Core team only |
| Federated |
Patterns, product-area components, mature variations |
Medium |
Any team, core review |
| Community |
Fixes, docs, examples, minor guidance updates |
Light |
Anyone, auto-merge for docs |
Core protects: decisions that create downstream cost. Token changes,
accessibility behavior, API logic, naming rules, cross-platform
consistency. These are not gatekeeping. They are cost control.
Community keeps the system from becoming precious. Documentation
fixes, usage examples, content clarifications should be easy to submit
and easy to merge. If these require a committee, contributors learn that
helping is not worth the effort.
Decision rights
Answer these in CONTRIBUTING.md:
- Who owns the system roadmap?
- Who can approve a new component, token, variant, or breaking change?
- How does a product team request a pattern the system does not cover?
- What quality gates must a contribution pass before release?
- How are teams told about changes, migration work, and deprecations?
- Which data proves the system is used in shipped products?
Contribution workflow
One path for all changes:
- Propose: submit use case, evidence, affected products, reuse
potential.
- Review: core team checks overlap with existing patterns, decides
if it belongs in the system.
- Build: design and code move together. Tokens, states, responsive
behavior, and accessibility covered.
- Document: when to use, when not to use, common mistakes.
- Release: version note, migration guidance, support window.
- Measure: usage, overrides, issues, feedback inform next release.
See references/governance.md for full governance templates.
Step 4: Versioning
Semantic versioning
Use SemVer at the package level. MAJOR.MINOR.PATCH.
| Bump |
When |
Migration |
| MAJOR |
Breaking API change, token rename, removed component |
Codemod + migration guide + 6-month deprecation window |
| MINOR |
New component, new token, new variant |
No migration needed |
| PATCH |
Bug fix, accessibility fix, docs update |
No migration needed |
Changelog
Every release ships a changelog. Format:
## [1.4.0] - 2026-01-15
### Added
- `DatePicker` component with calendar and input modes
- `motion.duration.slow` token (400ms)
### Changed
- `Button` variant prop now accepts "ghost" (was "text")
### Deprecated
- `Button` variant "text" will be removed in 2.0.0. Use "ghost".
### Fixed
- `Modal` focus trap now works with nested modals
Deprecation policy
Every deprecation ships with:
- A codemod (automated migration script).
- A six-month support window.
- Console warnings in development.
- Migration documentation.
Deprecation timeline:
- Month 0: Mark as deprecated. Console warning. Codemod released.
- Month 3: Reminder. Usage metrics shared with teams still on old API.
- Month 6: Remove in next MAJOR release.
See references/versioning.md for codemod templates and deprecation
workflows.
Step 5: Drift detection
Design drift is when code uses hardcoded values or reinvents components
instead of using the design system. AI agents are the biggest source of
drift in 2026.
Drift types
| Drift type |
Example |
Detection |
| Hardcoded tokens |
color: #3b82f6 instead of color.brand.primary |
Regex / AST scan for raw values |
| Reinvented components |
Custom <div> button instead of <Button> |
DOM structure matching against component library |
| Magic breakpoints |
@media (min-width: 768px) not in the system |
Media query scan |
| Prop misuse |
<Button variant="text"> (deprecated) |
TypeScript / prop type check |
| Token aliasing |
Background color token used for text |
Semantic token usage audit |
| Orphaned components |
Component in code, missing from Figma/Storybook |
Cross-reference scan |
| Unused tokens |
Token defined, never referenced |
Token usage scan |
| Naming drift |
Inconsistent naming across codebase |
Naming convention linter |
| Framework sprawl |
Multiple UI frameworks competing |
Import scan |
| Accessibility gaps |
Missing ARIA, focus management |
a11y audit |
CI gates
Install drift detection in CI. Every PR is scanned before merge.
# .github/workflows/drift-check.yml
name: Design System Drift Check
on: [pull_request]
jobs:
drift:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run tokens:validate
- run: npm run drift:check
- run: npm run a11y:audit
Gate rules:
- Hardcoded tokens: error (block merge).
- Reinvented components: warning (comment on PR).
- Accessibility gaps: error (block merge).
- Deprecated patterns: warning (comment with migration link).
- Coverage delta: comment on PR (show adoption change).
Health score
Score the system 0-100 based on:
- Token adoption (percentage of styles using tokens vs hardcoded)
- Component adoption (percentage of UI using system components vs custom)
- Accessibility compliance (percentage passing WCAG AA)
- Documentation coverage (percentage of components with docs)
- Test coverage (percentage of components with tests)
- Drift trend (improving or worsening over time)
See references/drift-detection.md for scanner setup, CI configuration,
and health score calculation.
Step 6: Adoption metrics
Track these to prove the system is used:
| Metric |
What it measures |
Target |
| Adoption rate |
% of product files/repos using approved libraries |
> 80% |
| Component coverage |
% of UI built with system components |
> 70% |
| Token coverage |
% of styles using tokens vs hardcoded |
> 90% |
| Drift rate |
New drift instances per sprint |
< 5 |
| Time to adopt |
Time for a new team to start using the system |
< 1 sprint |
| PR review SLA |
Time from proposal to decision |
< 5 days |
| Component reuse |
Average usage count per component |
> 3 |
Report quarterly. Treat the system as a product with users (internal
teams), not infrastructure.
Step 7: AI-agent readiness
AI agents (Claude Code, Cursor, Windsurf, Codex) must build within the
system, not around it. Make the system AI-readable.
AGENTS.md
Write an AGENTS.md at the repo root that tells AI agents:
- Which components exist and when to use them.
- Which tokens to reference (never hardcode values).
- Which patterns are approved vs banned.
- Where the documentation lives.
- How to contribute new components.
Component manifest
Generate a machine-readable manifest of all components, tokens, and
patterns. AI agents read this to know what exists before generating new
code.
{
"version": "1.4.0",
"tokens": ["color.action.primary", "color.text.body", "space.4", ...],
"components": [
{
"name": "Button",
"props": ["variant", "size", "disabled", "loading"],
"variants": ["primary", "secondary", "ghost", "destructive"],
"import": "@designsystem/react"
}
]
}
CLAUDE.md / llms.txt
For AI tools that read CLAUDE.md or llms.txt:
- List every available component with a one-line description.
- List every token with its semantic name.
- State the rule: "If a component exists, use it. Do not reinvent. If a
token exists, reference it. Do not hardcode values."
- State the drift policy: "Hardcoded values and reinvented components
are bugs."
See references/ai-readiness.md for full templates.
References
Load these for detailed guidance. All files exist under references/.
| File |
What's inside |
When to load |
token-architecture.md |
Three-tier token pipeline, DTCG format, Style Dictionary config, Figma-to-code sync |
When building or auditing the token pipeline |
monorepo-structure.md |
Package roles, workspace config, build pipelines, publish workflows |
When structuring the design system repo |
component-api.md |
Component API design patterns, prop types, compound components, variant matrices |
When designing component APIs |
governance.md |
Contribution model templates, decision rights, review tiers, CONTRIBUTING.md template |
When establishing or auditing governance |
versioning.md |
SemVer policy, changelog format, deprecation timeline, codemod templates |
When versioning or deprecating |
drift-detection.md |
Drift types, scanner setup, CI gates, health score calculation |
When installing drift detection |
ai-readiness.md |
AGENTS.md, CLAUDE.md, llms.txt, component manifest templates |
When making the system AI-agent ready |
Pre-flight checklist
Before considering a design system architecture task complete:
1---2name: design-system-architecture3description: Use when building, scaling, auditing, or governing a design system as an engineering product. Triggers on "design system architecture", "design tokens pipeline", "design system governance", "design drift", "component contribution model", "design system versioning", "multi-brand design system", "Figma to code sync", "design system audit", "design system health score", "design system monorepo", "component API design", "design system deprecation", "design system adoption metrics", or any task about the structure, scaling, and maintenance of a design system itself (not the visual style). Covers token architecture, governance models, contribution tiers, versioning, deprecation, drift detection, multi-brand orchestration, Figma-to-code pipelines, CI gates, adoption metrics, and AI-agent readiness.4license: MIT5---67# Design System Architecture: Building, Scaling & Governing the System89> Part of [Cognikit](https://cognikit.com). A kit that gives AI agents cognitive abilities.1011This skill is about the **engineering of a design system itself**, not the12visual style it contains. Use a visual design skill for choosing visual13direction (brutalism, minimalist, etc.). This skill focuses on the14engineering, not the aesthetics. Use this skill for the architecture,15governance, token pipeline, contribution model, versioning, drift detection,16and scaling of the system as a product.1718## AI execution flow (follow in order)19201. **Assess**: Determine the system's maturity (Step 1 below). Is it21 new, growing, or mature with many consumers?222. **Architecture**: Design or audit the token pipeline, monorepo23 structure, and component package boundaries (Step 2).243. **Governance**: Establish or audit the contribution model, decision25 rights, and review tiers (Step 3).264. **Versioning**: Set up SemVer, changelog, deprecation policy, and27 codemod workflow (Step 4).285. **Drift detection**: Install CI gates, token validation, and29 component-usage scanning (Step 5).306. **Adoption**: Measure adoption, coverage, and health score (Step 6).317. **AI readiness**: Generate `AGENTS.md`, `llms.txt`, and component32 manifests so AI agents build within the system, not around it (Step 7).338. **Verify**: Run the pre-flight checklist at the bottom of this file.3435## When to use3637- Building a new design system from scratch (token architecture, package38 structure, governance)39- Scaling an existing system to 10+ consumer teams40- Setting up a Figma-to-code token pipeline41- Establishing a contribution model (who can add components, tokens)42- Versioning and deprecating design system packages43- Detecting and preventing design drift (hardcoded values, reinvented44 components)45- Multi-brand or multi-theme orchestration46- Making a design system AI-agent ready (CLAUDE.md, AGENTS.md, manifests)47- Auditing a design system's health and adoption4849## When NOT to use5051- Choosing a visual style (brutalism, minimalist, etc.)52- Building individual UI components53- Responsive/adaptive layout decisions5455Those are visual design tasks, not system architecture tasks.5657## Step 1: Assess maturity5859| Stage | Consumers | Tokens | Components | Governance | Action |60|---|---|---|---|---|---|61| New | 0-2 | Ad hoc | 5-20 | None | Build foundation (Step 2) |62| Growing | 3-9 | Some structure | 20-50 | Informal | Add governance (Step 3) |63| Mature | 10+ | Three-tier | 50-200 | Hybrid model | Optimize, drift detect (Step 5) |64| Scaling | 50+ | Multi-brand | 200+ | Federated | Multi-brand orchestration |6566## Step 2: Architecture6768### Token pipeline6970The token pipeline is the contract. Components are replaceable71implementations of a tokenized system.7273**Three-tier token architecture (industry standard since W3C DTCG spec,74October 2025):**75761. **Reference (primitive) tokens**: raw values, no opinions.77 `blue.600: #2563EB`, `space.4: 16px`. Names may describe values here78 only. This is the only tier where value-naming is allowed.792. **Semantic tokens**: meaning and purpose. `color.action.primary:80 {blue.600}`, `color.text.body: {gray.900}`. Name by purpose, never81 value. This is where the design language lives.823. **Component tokens**: scoped to specific UI. `button.bg.primary:83 {color.action.primary}`. Build this tier only when needed. Most teams84 before Series C only need tiers 1 and 2.8586**Rules:**87- Name tokens by purpose, not value. `color.action.primary` is correct.88 `blue-500` as a semantic name is wrong.89- Start with 30-50 tokens covering color, space, type, and radius. A90 400-token vocabulary nobody adopts fails.91- One token source drives Figma, CSS, iOS, and Android without a92 hand-built translation layer (W3C DTCG format).93- Dark mode, theming, and rebranding are token swaps, not rewrites.94- Motion tokens (duration, easing, spring) are part of the system,95 alongside color and type.9697See `references/token-architecture.md` for the full pipeline spec,98DTCG format, and Style Dictionary configuration.99100### Monorepo structure101102```103design-system/104├── package.json # Root: scripts, dev tooling105├── pnpm-workspace.yaml # Workspace config106├── figma.config.json # Figma Code Connect107├── packages/ # Published packages108│ ├── tokens/ # Design tokens (DTCG JSON)109│ ├── theme/ # Theme engine (token compilation)110│ ├── react/ # React component library111│ ├── icons/ # Icon library112│ ├── utils/ # Shared utilities113│ └── cli/ # CLI tooling (optional)114├── apps/ # Applications (not published)115│ ├── docs/ # Documentation site116│ └── demo/ # Demo app117├── scripts/ # Build scripts (token sync, icon gen)118└── .github/workflows/ # CI (lint, test, drift detect, publish)119```120121**Rules:**122- Inter-package dependencies use `workspace:*`.123- Public API is the package root export. Internal modules are restricted124 (ESLint `restricted-imports` bans deep imports).125- One publish pipeline per package. Independent versioning per package126 or unified versioning (choose based on release cadence).127128See `references/monorepo-structure.md` for detailed package roles,129build pipelines, and publish workflows.130131### Component package boundaries132133Each component package exports:134- The component (React, Vue, Flutter, etc.)135- TypeScript types / Dart classes136- Props table (documented API)137- Accessibility spec (ARIA patterns, keyboard nav, focus management)138- Motion spec (duration token, easing token, reduced-motion behavior)139- Usage examples140- When to use / when not to use141142**Component API rules:**143- Props are typed and documented. No `any` types.144- Variant props use a union type, not boolean combinations.145 `variant: "primary" | "secondary" | "ghost"` not `primary?: boolean,146 secondary?: boolean, ghost?: boolean`.147- Compound components (Button.Icon, Button.Label) for composition over148 prop explosion.149- Forward ref always (React). Expose imperative API only when necessary.150- Default props are token references, not hardcoded values.151152See `references/component-api.md` for full API design patterns.153154## Step 3: Governance155156### Contribution models157158| Model | Owner | Scales | Use when |159|---|---|---|---|160| Centralized | Single dedicated team | Slow | System is young, < 5 consumers |161| Federated | Many teams, no single owner | Fast short-term, expensive long-term | Rare. Not recommended. |162| Hybrid (cyclical) | Small core + embedded contributors | Well | 10+ consumers. Almost always right. |163164**Hybrid model (recommended for 10+ consumers):**165- Small core team (2-4 people) owns tokens, accessibility review, release166 cadence.167- Embedded contributors from product teams ship components and propose168 changes.169- Core team reviews for consistency. Product teams own domain-specific170 patterns.171172Document the model in `CONTRIBUTING.md` at the repo root: who can merge173to main, who can propose components, who decides on tokens, what the SLA174on PR review is.175176### Contribution tiers177178| Tier | Scope | Review intensity | Who can propose |179|---|---|---|---|180| Core | Tokens, primitives, architecture, policy | Highest | Core team only |181| Federated | Patterns, product-area components, mature variations | Medium | Any team, core review |182| Community | Fixes, docs, examples, minor guidance updates | Light | Anyone, auto-merge for docs |183184**Core protects:** decisions that create downstream cost. Token changes,185accessibility behavior, API logic, naming rules, cross-platform186consistency. These are not gatekeeping. They are cost control.187188**Community keeps the system from becoming precious.** Documentation189fixes, usage examples, content clarifications should be easy to submit190and easy to merge. If these require a committee, contributors learn that191helping is not worth the effort.192193### Decision rights194195Answer these in `CONTRIBUTING.md`:1961. Who owns the system roadmap?1972. Who can approve a new component, token, variant, or breaking change?1983. How does a product team request a pattern the system does not cover?1994. What quality gates must a contribution pass before release?2005. How are teams told about changes, migration work, and deprecations?2016. Which data proves the system is used in shipped products?202203### Contribution workflow204205One path for all changes:2061. **Propose**: submit use case, evidence, affected products, reuse207 potential.2082. **Review**: core team checks overlap with existing patterns, decides209 if it belongs in the system.2103. **Build**: design and code move together. Tokens, states, responsive211 behavior, and accessibility covered.2124. **Document**: when to use, when not to use, common mistakes.2135. **Release**: version note, migration guidance, support window.2146. **Measure**: usage, overrides, issues, feedback inform next release.215216See `references/governance.md` for full governance templates.217218## Step 4: Versioning219220### Semantic versioning221222Use SemVer at the package level. `MAJOR.MINOR.PATCH`.223224| Bump | When | Migration |225|---|---|---|226| MAJOR | Breaking API change, token rename, removed component | Codemod + migration guide + 6-month deprecation window |227| MINOR | New component, new token, new variant | No migration needed |228| PATCH | Bug fix, accessibility fix, docs update | No migration needed |229230### Changelog231232Every release ships a changelog. Format:233```234## [1.4.0] - 2026-01-15235236### Added237- `DatePicker` component with calendar and input modes238- `motion.duration.slow` token (400ms)239240### Changed241- `Button` variant prop now accepts "ghost" (was "text")242243### Deprecated244- `Button` variant "text" will be removed in 2.0.0. Use "ghost".245246### Fixed247- `Modal` focus trap now works with nested modals248```249250### Deprecation policy251252Every deprecation ships with:2531. A codemod (automated migration script).2542. A six-month support window.2553. Console warnings in development.2564. Migration documentation.257258**Deprecation timeline:**259- Month 0: Mark as deprecated. Console warning. Codemod released.260- Month 3: Reminder. Usage metrics shared with teams still on old API.261- Month 6: Remove in next MAJOR release.262263See `references/versioning.md` for codemod templates and deprecation264workflows.265266## Step 5: Drift detection267268Design drift is when code uses hardcoded values or reinvents components269instead of using the design system. AI agents are the biggest source of270drift in 2026.271272### Drift types273274| Drift type | Example | Detection |275|---|---|---|276| Hardcoded tokens | `color: #3b82f6` instead of `color.brand.primary` | Regex / AST scan for raw values |277| Reinvented components | Custom `<div>` button instead of `<Button>` | DOM structure matching against component library |278| Magic breakpoints | `@media (min-width: 768px)` not in the system | Media query scan |279| Prop misuse | `<Button variant="text">` (deprecated) | TypeScript / prop type check |280| Token aliasing | Background color token used for text | Semantic token usage audit |281| Orphaned components | Component in code, missing from Figma/Storybook | Cross-reference scan |282| Unused tokens | Token defined, never referenced | Token usage scan |283| Naming drift | Inconsistent naming across codebase | Naming convention linter |284| Framework sprawl | Multiple UI frameworks competing | Import scan |285| Accessibility gaps | Missing ARIA, focus management | a11y audit |286287### CI gates288289Install drift detection in CI. Every PR is scanned before merge.290291```yaml292# .github/workflows/drift-check.yml293name: Design System Drift Check294on: [pull_request]295jobs:296 drift:297 runs-on: ubuntu-latest298 steps:299 - uses: actions/checkout@v4300 - run: npm ci301 - run: npm run tokens:validate302 - run: npm run drift:check303 - run: npm run a11y:audit304```305306**Gate rules:**307- Hardcoded tokens: error (block merge).308- Reinvented components: warning (comment on PR).309- Accessibility gaps: error (block merge).310- Deprecated patterns: warning (comment with migration link).311- Coverage delta: comment on PR (show adoption change).312313### Health score314315Score the system 0-100 based on:316- Token adoption (percentage of styles using tokens vs hardcoded)317- Component adoption (percentage of UI using system components vs custom)318- Accessibility compliance (percentage passing WCAG AA)319- Documentation coverage (percentage of components with docs)320- Test coverage (percentage of components with tests)321- Drift trend (improving or worsening over time)322323See `references/drift-detection.md` for scanner setup, CI configuration,324and health score calculation.325326## Step 6: Adoption metrics327328Track these to prove the system is used:329330| Metric | What it measures | Target |331|---|---|---|332| Adoption rate | % of product files/repos using approved libraries | > 80% |333| Component coverage | % of UI built with system components | > 70% |334| Token coverage | % of styles using tokens vs hardcoded | > 90% |335| Drift rate | New drift instances per sprint | < 5 |336| Time to adopt | Time for a new team to start using the system | < 1 sprint |337| PR review SLA | Time from proposal to decision | < 5 days |338| Component reuse | Average usage count per component | > 3 |339340Report quarterly. Treat the system as a product with users (internal341teams), not infrastructure.342343## Step 7: AI-agent readiness344345AI agents (Claude Code, Cursor, Windsurf, Codex) must build within the346system, not around it. Make the system AI-readable.347348### AGENTS.md349350Write an `AGENTS.md` at the repo root that tells AI agents:351- Which components exist and when to use them.352- Which tokens to reference (never hardcode values).353- Which patterns are approved vs banned.354- Where the documentation lives.355- How to contribute new components.356357### Component manifest358359Generate a machine-readable manifest of all components, tokens, and360patterns. AI agents read this to know what exists before generating new361code.362363```json364{365 "version": "1.4.0",366 "tokens": ["color.action.primary", "color.text.body", "space.4", ...],367 "components": [368 {369 "name": "Button",370 "props": ["variant", "size", "disabled", "loading"],371 "variants": ["primary", "secondary", "ghost", "destructive"],372 "import": "@designsystem/react"373 }374 ]375}376```377378### CLAUDE.md / llms.txt379380For AI tools that read `CLAUDE.md` or `llms.txt`:381- List every available component with a one-line description.382- List every token with its semantic name.383- State the rule: "If a component exists, use it. Do not reinvent. If a384 token exists, reference it. Do not hardcode values."385- State the drift policy: "Hardcoded values and reinvented components386 are bugs."387388See `references/ai-readiness.md` for full templates.389390## References391392Load these for detailed guidance. All files exist under `references/`.393394| File | What's inside | When to load |395|---|---|---|396| `token-architecture.md` | Three-tier token pipeline, DTCG format, Style Dictionary config, Figma-to-code sync | When building or auditing the token pipeline |397| `monorepo-structure.md` | Package roles, workspace config, build pipelines, publish workflows | When structuring the design system repo |398| `component-api.md` | Component API design patterns, prop types, compound components, variant matrices | When designing component APIs |399| `governance.md` | Contribution model templates, decision rights, review tiers, CONTRIBUTING.md template | When establishing or auditing governance |400| `versioning.md` | SemVer policy, changelog format, deprecation timeline, codemod templates | When versioning or deprecating |401| `drift-detection.md` | Drift types, scanner setup, CI gates, health score calculation | When installing drift detection |402| `ai-readiness.md` | AGENTS.md, CLAUDE.md, llms.txt, component manifest templates | When making the system AI-agent ready |403404## Pre-flight checklist405406Before considering a design system architecture task complete:407408- [ ] Token architecture is three-tier (reference, semantic, component)409- [ ] Tokens named by purpose, not value410- [ ] Token pipeline drives all platforms from one source411- [ ] Monorepo structure with clear package boundaries412- [ ] Component APIs are typed, documented, variant-based413- [ ] Contribution model documented in CONTRIBUTING.md414- [ ] Contribution tiers defined (Core, Federated, Community)415- [ ] Decision rights answered (who owns what)416- [ ] SemVer versioning with changelog per release417- [ ] Deprecation policy with codemod and 6-month window418- [ ] Drift detection installed in CI419- [ ] Hardcoded tokens block merge (error gate)420- [ ] Accessibility gaps block merge (error gate)421- [ ] Health score tracked (0-100)422- [ ] Adoption metrics reported quarterly423- [ ] AGENTS.md written for AI agents424- [ ] Component manifest generated425- [ ] CLAUDE.md / llms.txt states the drift policy