Design Grammar Retrofit Expertise
When to Use This Skill
Load this skill when you need to:
- Add the Design Grammar to a project that doesn't have it
- Set up project-specific design tokens from the grammar token schema
- Connect an existing component library to grammar definitions
- Configure the token build pipeline (Style Dictionary)
- Set up Tokens Studio for Figma ↔ repo token sync
- Map existing components to grammar types (atoms, molecules, organisms)
Common triggers:
- Module Installation phase (after Discovery selects Design Grammar)
- Brownfield project needs shared design vocabulary
- Project has ad-hoc tokens/components, needs grammar alignment
- Team wants Figma round-trip for an existing codebase
Quick Reference
The Design Grammar (.design-grammar/) is the shared cross-project vocabulary. It defines WHAT components exist and HOW they compose. Projects consume it — they never modify it.
A Project Design System (tokens/, src/components/) is the project-specific implementation. It fills in the grammar's token schema with real values and implements components following grammar definitions.
.design-grammar/ (shared, read-only) → tokens/ (project, writable)
├── tokens-schema/ → ├── colors.json
├── primitives/ → ├── typography.json
├── organisms/marketing/hero.json → └── spacing.json
└── schemas/organism.schema.json → src/components/organisms/Hero.tsx
Retrofit is 5 steps:
- Create project tokens from grammar token schema
- Configure build pipeline (Style Dictionary)
- Map existing components to grammar types
- Align Storybook to extended atomic hierarchy
- (Optional) Set up Tokens Studio for Figma sync
Rules
Token Rules
- MUST create tokens following grammar token schema — Use
.design-grammar/tokens-schema/ as the shape, fill with project values
- MUST use W3C DTCG format —
{ "$value": "...", "$type": "..." } not plain JSON
- MUST separate light/dark tokens — Use
$extensions.mode or separate files
- MUST NOT invent token names — Use names from the grammar schema only
- Token files go in project
tokens/ — Never in .design-grammar/
Build Pipeline Rules
- MUST install pipeline dependencies — Copy
.design-grammar/pipeline/package.json deps into project
- MUST configure Style Dictionary — Use
.design-grammar/pipeline/sd.config.js as reference, adapt paths
- MUST generate CSS + Tailwind output —
build/css/variables.css, build/tailwind/theme.js
- MUST add build scripts to project —
npm run tokens:validate, npm run tokens:build
- SHOULD add pre-commit validation — Warn when
tokens/** files change without running build
Component Mapping Rules
- MUST audit existing components first — List all components, classify by grammar level
- Map, don't rewrite — Document which existing component maps to which grammar type
- Fill gaps, don't duplicate — Only create new components for grammar types not yet covered
- MUST use grammar prop names — When refactoring, align prop names to grammar definitions
- Prioritise organisms — They deliver the most visible grammar alignment
Storybook Rules
- MUST restructure titles — Use extended hierarchy:
Atoms/Button, Organisms/Hero
- MUST add
primitives/ folder if project has unstyled behavioural components
- MUST create view components for page-level UI —
src/components/views/
- Stories import views — Both stories and pages use the same view component
Workflows
Workflow: Full Retrofit
When: Project selected Design Grammar in Discovery, entering Module Installation.
Prerequisites:
- Project has existing components/tokens (even if informal)
.design-grammar/ available (via AgentFlow sync)
- Node.js 18+ for Style Dictionary
Steps:
Audit existing tokens
- Find where design values live (CSS vars, Tailwind config, theme files)
- List all colors, typography, spacing, radii, shadows
- Note any light/dark theme support
Create project tokens/ directory
tokens/
├── colors.json ← DTCG format, project-specific values
├── typography.json
└── spacing.json
- Reference:
.design-grammar/examples/tokens/ for format
- Reference:
.design-grammar/tokens-schema/ for required shape
Set up build pipeline
- Install:
npm install -D style-dictionary @tokens-studio/sd-transforms
- Copy and adapt:
.design-grammar/pipeline/sd.config.js
- Add scripts:
tokens:validate, tokens:build
- Run:
npm run tokens:build → verify CSS + Tailwind output
Audit existing components
- List all components in
src/components/
- Classify each against grammar hierarchy:
- Primitives: unstyled behaviour wrappers
- Atoms: single-purpose styled elements
- Molecules: small compositions (2-3 atoms)
- Organisms: page sections
- Templates: page layouts
- Check
.design-grammar/sources/tailwind-plus/catalogue.json for variant references
Restructure component folders
src/components/
├── primitives/ ← behavioural (Pressable, Slot) + layout (Stack, Grid)
├── atoms/ ← Button, Badge, Input
├── molecules/ ← FormField, NavItem
├── organisms/ ← Hero, Pricing, DataTable
├── templates/ ← LandingTemplate, DashboardTemplate
└── views/ ← PricingView, DashboardView (shared by stories + pages)
Align Storybook
- Update story titles to use atomic prefixes
- Create view components for page-level stories
- Add responsive + theme variants if missing
(Optional) Set up Tokens Studio
- Follow
.design-grammar/tokens-studio/README.md
- Install Figma plugin, configure git sync to
tokens/
- Test round-trip: change token in Figma → PR → merge → CSS updated
Workflow: Lightweight Retrofit
When: Project wants grammar alignment without full restructure.
- Create
tokens/ with DTCG format (step 2 above)
- Set up build pipeline (step 3 above)
- Document component-to-grammar mapping in
docs/design/component-mapping.md — don't restructure folders yet
- Gradually align as components are touched (boy scout rule)
Common Pitfalls
| Pitfall |
Solution |
| Rewriting all components at once |
Map first, refactor gradually |
| Inventing new token names |
Use grammar schema names only |
Putting tokens in .design-grammar/ |
Project tokens go in tokens/ |
| Skipping DTCG format |
Use $value/$type — Style Dictionary requires it |
| Not running token build |
Add tokens:build to CI and pre-commit |
| Flat component folders |
Restructure to primitives/atoms/molecules/organisms/templates/ |
| Missing view components |
Create src/components/views/ for page-level rendering |
Essential Reading
Grammar documentation:
.design-grammar/README.md — Grammar overview, directory structure
.design-grammar/pipeline/SPEC.md — Build pipeline specification
Retrofit guide (step-by-step with examples):
Related skills:
af-design-ui-components — Component design patterns, Storybook workflow
af-setup-project — Module installation (where retrofit happens)
af-sync-figma-designs — Figma round-trip (optional visual layer)
Platform mappings:
.design-grammar/platform-mappings/web-react.json — ShadCN/Tailwind mapping
.design-grammar/platform-mappings/flutter-material.json — Flutter Material 3 mapping
1---2name: af-retrofit-design-grammar3description: Retrofit the Design Grammar into existing projects that lack it. Use when adding token setup, integrating grammar definitions, or migrating an existing UI to grammar-compliant patterns.4---5
6# Design Grammar Retrofit Expertise
7
8## When to Use This Skill
9
10Load this skill when you need to:
11- Add the Design Grammar to a project that doesn't have it
12- Set up project-specific design tokens from the grammar token schema
13- Connect an existing component library to grammar definitions
14- Configure the token build pipeline (Style Dictionary)
15- Set up Tokens Studio for Figma ↔ repo token sync
16- Map existing components to grammar types (atoms, molecules, organisms)
17
18**Common triggers:**
19- Module Installation phase (after Discovery selects Design Grammar)
20- Brownfield project needs shared design vocabulary
21- Project has ad-hoc tokens/components, needs grammar alignment
22- Team wants Figma round-trip for an existing codebase
23
24## Quick Reference
25
26**The Design Grammar** (`.design-grammar/`) is the shared cross-project vocabulary. It defines WHAT components exist and HOW they compose. Projects consume it — they never modify it.
27
28**A Project Design System** (`tokens/`, `src/components/`) is the project-specific implementation. It fills in the grammar's token schema with real values and implements components following grammar definitions.
29
30```
31.design-grammar/ (shared, read-only) → tokens/ (project, writable)
32├── tokens-schema/ → ├── colors.json
33├── primitives/ → ├── typography.json
34├── organisms/marketing/hero.json → └── spacing.json
35└── schemas/organism.schema.json → src/components/organisms/Hero.tsx
36```
37
38**Retrofit is 5 steps:**
391. Create project tokens from grammar token schema
402. Configure build pipeline (Style Dictionary)
413. Map existing components to grammar types
424. Align Storybook to extended atomic hierarchy
435. (Optional) Set up Tokens Studio for Figma sync
44
45## Rules
46
47### Token Rules
48
491. **MUST create tokens following grammar token schema** — Use `.design-grammar/tokens-schema/` as the shape, fill with project values
502. **MUST use W3C DTCG format** — `{ "$value": "...", "$type": "..." }` not plain JSON
513. **MUST separate light/dark tokens** — Use `$extensions.mode` or separate files
524. **MUST NOT invent token names** — Use names from the grammar schema only
535. **Token files go in project `tokens/`** — Never in `.design-grammar/`
54
55### Build Pipeline Rules
56
576. **MUST install pipeline dependencies** — Copy `.design-grammar/pipeline/package.json` deps into project
587. **MUST configure Style Dictionary** — Use `.design-grammar/pipeline/sd.config.js` as reference, adapt paths
598. **MUST generate CSS + Tailwind output** — `build/css/variables.css`, `build/tailwind/theme.js`
609. **MUST add build scripts to project** — `npm run tokens:validate`, `npm run tokens:build`
6110. **SHOULD add pre-commit validation** — Warn when `tokens/**` files change without running build
62
63### Component Mapping Rules
64
6511. **MUST audit existing components first** — List all components, classify by grammar level
6612. **Map, don't rewrite** — Document which existing component maps to which grammar type
6713. **Fill gaps, don't duplicate** — Only create new components for grammar types not yet covered
6814. **MUST use grammar prop names** — When refactoring, align prop names to grammar definitions
6915. **Prioritise organisms** — They deliver the most visible grammar alignment
70
71### Storybook Rules
72
7316. **MUST restructure titles** — Use extended hierarchy: `Atoms/Button`, `Organisms/Hero`
7417. **MUST add `primitives/` folder** if project has unstyled behavioural components
7518. **MUST create view components** for page-level UI — `src/components/views/`
7619. **Stories import views** — Both stories and pages use the same view component
77
78## Workflows
79
80### Workflow: Full Retrofit
81
82**When:** Project selected Design Grammar in Discovery, entering Module Installation.
83
84**Prerequisites:**
85- Project has existing components/tokens (even if informal)
86- `.design-grammar/` available (via AgentFlow sync)
87- Node.js 18+ for Style Dictionary
88
89**Steps:**
90
911. **Audit existing tokens**
92 - Find where design values live (CSS vars, Tailwind config, theme files)
93 - List all colors, typography, spacing, radii, shadows
94 - Note any light/dark theme support
95
962. **Create project `tokens/` directory**
97 ```
98 tokens/
99 ├── colors.json ← DTCG format, project-specific values
100 ├── typography.json
101 └── spacing.json
102 ```
103 - Reference: `.design-grammar/examples/tokens/` for format
104 - Reference: `.design-grammar/tokens-schema/` for required shape
105
1063. **Set up build pipeline**
107 - Install: `npm install -D style-dictionary @tokens-studio/sd-transforms`
108 - Copy and adapt: `.design-grammar/pipeline/sd.config.js`
109 - Add scripts: `tokens:validate`, `tokens:build`
110 - Run: `npm run tokens:build` → verify CSS + Tailwind output
111
1124. **Audit existing components**
113 - List all components in `src/components/`
114 - Classify each against grammar hierarchy:
115 - Primitives: unstyled behaviour wrappers
116 - Atoms: single-purpose styled elements
117 - Molecules: small compositions (2-3 atoms)
118 - Organisms: page sections
119 - Templates: page layouts
120 - Check `.design-grammar/sources/tailwind-plus/catalogue.json` for variant references
121
1225. **Restructure component folders**
123 ```
124 src/components/
125 ├── primitives/ ← behavioural (Pressable, Slot) + layout (Stack, Grid)
126 ├── atoms/ ← Button, Badge, Input
127 ├── molecules/ ← FormField, NavItem
128 ├── organisms/ ← Hero, Pricing, DataTable
129 ├── templates/ ← LandingTemplate, DashboardTemplate
130 └── views/ ← PricingView, DashboardView (shared by stories + pages)
131 ```
132
1336. **Align Storybook**
134 - Update story titles to use atomic prefixes
135 - Create view components for page-level stories
136 - Add responsive + theme variants if missing
137
1387. **(Optional) Set up Tokens Studio**
139 - Follow `.design-grammar/tokens-studio/README.md`
140 - Install Figma plugin, configure git sync to `tokens/`
141 - Test round-trip: change token in Figma → PR → merge → CSS updated
142
143### Workflow: Lightweight Retrofit
144
145**When:** Project wants grammar alignment without full restructure.
146
1471. Create `tokens/` with DTCG format (step 2 above)
1482. Set up build pipeline (step 3 above)
1493. Document component-to-grammar mapping in `docs/design/component-mapping.md` — don't restructure folders yet
1504. Gradually align as components are touched (boy scout rule)
151
152## Common Pitfalls
153
154| Pitfall | Solution |
155|---------|----------|
156| Rewriting all components at once | Map first, refactor gradually |
157| Inventing new token names | Use grammar schema names only |
158| Putting tokens in `.design-grammar/` | Project tokens go in `tokens/` |
159| Skipping DTCG format | Use `$value`/`$type` — Style Dictionary requires it |
160| Not running token build | Add `tokens:build` to CI and pre-commit |
161| Flat component folders | Restructure to `primitives/atoms/molecules/organisms/templates/` |
162| Missing view components | Create `src/components/views/` for page-level rendering |
163
164## Essential Reading
165
166**Grammar documentation:**
167- `.design-grammar/README.md` — Grammar overview, directory structure
168- `.design-grammar/pipeline/SPEC.md` — Build pipeline specification
169
170**Retrofit guide (step-by-step with examples):**
171- [Design Grammar Retrofit Guide](../../docs/guides/design-grammar-retrofit-guide.md)
172
173**Related skills:**
174- `af-design-ui-components` — Component design patterns, Storybook workflow
175- `af-setup-project` — Module installation (where retrofit happens)
176- `af-sync-figma-designs` — Figma round-trip (optional visual layer)
177
178**Platform mappings:**
179- `.design-grammar/platform-mappings/web-react.json` — ShadCN/Tailwind mapping
180- `.design-grammar/platform-mappings/flutter-material.json` — Flutter Material 3 mapping