Scope: This is a sub-workflow of Step 2.5 (Gap Analysis). It is invoked when the AI agent determines a project has an existing frontend but no formal design system. The parent SKILL handles detection (scanner + structure analyzer); this reference handles the extraction and codification workflow.
Boundary: This workflow produces a design system SPEC (tokens, component classification, documentation structure). The technical IMPLEMENTATION (monorepo packages, build pipeline) is handled separately via references/design-system-sources.md.
Sequence: Audit existing code (this file) → Define spec → Implement architecture (design-system-sources.md)
All tokens, components, and patterns MUST come from existing code. Do not introduce new visual styles, design languages, or interaction patterns. The design system codifies what already works.
If the codebase already has a reusable atomic component, use it. Do not create duplicates. Merge components that are visually or behaviorally identical but named differently.
The goal is abstraction and constraint, not large-scale refactoring. New and old implementations can coexist. New development must follow the design system; old code migrates incrementally.
Inline CSS in the codebase must be abstracted into:
- Design tokens (CSS custom properties)
- Tailwind utility classes
- Component props
No inline CSS in design system components.
Only codify high-frequency, cross-page, reusable UI/UX. One-off implementations stay outside the design system. The spec should be "enough to be useful", not "covers everything".
The design system documentation IS the authoritative spec. No separate design docs, no verbal conventions. The doc structure, naming, and examples themselves are the constraints.
- Run the scanner to detect hand-rolled patterns (
design-systemdomain: hardcoded colors, inline styles, className concatenation) - Run the structure analyzer to assess monorepo architecture (missing token layer, missing shared config)
- Catalog existing components:
- List all files in
components/directories across the monorepo - Identify duplicates (same component, different names or locations)
- Identify inline styles that should be tokens
- List all files in
- Catalog existing design values:
- Extract all hardcoded hex colors from TSX/JSX files
- Extract all font-size, spacing, border-radius values
- Group into a preliminary token palette
From the audit, create the token layer:
- Colors: Extract unique hex/rgb values, group into semantic categories (primary, secondary, destructive, muted, etc.)
- Typography: Extract font families, sizes, weights, line heights
- Spacing: Extract padding/margin values, normalize into a scale (4px grid)
- Radius: Extract border-radius values
- Shadow: Extract box-shadow values
- Motion: Extract transition/animation values (if any)
Token format: use the project's existing convention. If Tailwind, use CSS custom properties with RGB/HSL space-separated format for alpha-value support.
Smallest reusable UI units. These exist as individual components:
- Button, Input, Select, Checkbox, Radio, Badge, Avatar, Tooltip, etc.
- Criteria: used in 3+ places, single responsibility, no business logic
Composed from multiple atoms for specific business patterns:
- Confirmation modal, Filter bar, Metric card, Page header, etc.
- Criteria: reusable business-level compositions, used in 2+ pages
Structural patterns that describe HOW to compose, not WHAT:
- Form layout, Table patterns, Navigation, Empty states, Charts, etc.
- Criteria: recurring structural decisions, not individual components
Documentation site uses Mintlify. Writing style references: Vercel, Supabase, Primer, Radix UI.
Each top-level section is one MDX file. Structure:
docs/
├── getting-started/
│ ├── introduction.mdx
│ ├── how-to-use.mdx
│ └── contribution.mdx
├── foundations/
│ ├── accessibility.mdx
│ ├── color-usage.mdx
│ ├── typography.mdx
│ ├── theming.mdx
│ ├── tailwind-classes.mdx
│ ├── icons.mdx
│ └── copywriting.mdx
├── patterns/
│ ├── introduction.mdx
│ ├── charts.mdx
│ ├── empty-states.mdx
│ ├── forms.mdx
│ ├── layout.mdx
│ ├── modality.mdx
│ ├── navigation.mdx
│ └── tables.mdx
├── fragments/
│ ├── introduction.mdx
│ └── {fragment-name}.mdx ← one per fragment component
├── components/
│ ├── introduction.mdx
│ └── {component-name}.mdx ← one per atom component
└── snippets/
└── {demo-name}.mdx ← reusable JSX demo fragments
Foundations pages:
## Overview
## Design rationale (from existing UI)
## Usage guidelines
## Do / Don'tComponent pages (atom and fragment):
## Demo
## Usage
## Props
## Examples
## AccessibilityDemo MUST be extracted from real pages. Examples prioritize real business scenarios.
UI Pattern pages:
## When to use
## Structure
## Composition
## Examples
## Related componentsAfter extraction and documentation, choose the implementation:
- See
references/design-system-sources.mdfor architecture patterns (tokens-first vs shared-config) - Organize into monorepo packages:
packages/design-tokens/,packages/ui/,packages/tailwind-config/ - Wire apps to use shared packages
- Do NOT introduce visual styles not present in the existing codebase
- Do NOT "design a better looking version" of existing components
- Do NOT use inline CSS in design system components
- Do NOT create components with overlapping responsibilities or ambiguous semantics
- Do NOT codify one-off, single-use implementations