stack-design-system
Skill0 starsChanged 5 months agoApache-2.0View on GitHub
Design-system craft — three-tier token architecture, component API conventions, theming, extraction recipes — for projects building or consolidating a shared UI library. Loaded by design-system-developer, design-system-architect, design-system-extractor, ui-ux-reviewer, and by frontend-developer/mobile-developer when a task touches the shared design-system library.
In this repository17 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- flow-adoptionSkill
- flow-legacy-migrationSkill
- stack-awsSkill
- stack-azureSkill
- stack-gcpSkill
- stack-javaSkill
- stack-kafkaSkill
- stack-mongodbSkill
- stack-natsSkill
- stack-nestjsSkill
- stack-nextjs-reactSkill
- stack-nxSkill
- stack-playwrightSkill
- stack-postgresqlSkill
- stack-quarkusSkill
- stack-react-nativeSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 52
Every interactive primitive forwards its ref and passes through data-testid + ARIA props — the §7.3 registry values belong to the CONSUMING …
- Very specific: line 58
No theme conditionals inside component source (isDark ?
- Very specific: line 71
Run by design-system-extractor.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Skill: Design System
This file owns the deep design-system craft: the token doctrine, component API conventions, theming mechanics, and the extraction recipes the audit flow runs. Agent contracts (gates, layers, handoffs) live in the agent files; the FE↔E2E data-testid contract lives in .claude/skills/stack-nextjs-react/SKILL.md; Playwright runner craft lives in .claude/skills/stack-playwright/SKILL.md. Where the host's generated docs/ declare different placements or targets, the host docs win.
When this applies
- Any task with
Layer: dev-design-system(executed bydesign-system-developervia/dev-design-system) dev-frontend/dev-mobiletasks that consume or modify the shared UI library (libs/design-systemor the host's equivalent perdocs/ARCHITECTURE.md)- Extraction/consolidation flows:
/extract-design-system(inventory →docs/DESIGN_AUDIT.md),/design-system-plan(architecture →docs/DESIGN_SYSTEM_PLAN.md) - Detection markers (any of): a
libs/design-system/directory (or a package named@<org>/design-system); a token source (tokens/**/*.json,style-dictionary.config.*, a populatedtheme/theme.extendblock intailwind.config.*); component stories/docs for shared primitives
Implementation patterns
Three-tier token architecture (the doctrine)
Tokens are the SINGLE source of truth for every visual decision. Three tiers, strict direction:
- Primitive — raw values, no meaning (
blue.600,space.4). Never imported by component source. - Semantic — meaning, no rawness (
action.primary,surface.raised). References primitives only. - Component — per-widget hooks (
button.bg,input.border). References semantic (or, rarely, primitive for true one-offs — flag those).
Concrete source shape (style-dictionary-style JSON; the host's token build may differ in syntax, never in tiering):
// tokens/source/color.json — the one source every platform output is built from
{
"color": {
"primitive": { "blue": { "600": { "value": "#1d4ed8" } } },
"semantic": { "action": { "primary": { "value": "{color.primitive.blue.600}" } } },
"component": { "button": { "bg": { "value": "{color.semantic.action.primary}" } } }
}
}Platform outputs are BUILT from that one source (Style Dictionary or the host's equivalent) — never hand-maintained in parallel:
- Web: CSS custom properties (
--color-action-primary) consumed by CSS/Tailwind config - TS: a typed theme object for styled/system consumption (closed key unions, not
string) - React Native: plain JS exports — unitless numbers and color strings only; no
rem/calc()/CSS-only constructs RN cannot parse
A raw hex/px/font literal in component source is a review finding (grep pattern under Live validation) — the value either already has a token or needs one proposed, never inlined.
Component API conventions
variant/size/toneprops with CLOSED unions. Adding a variant means adding a union value + its component tokens — never forking the component (PrimaryButton2.tsxis a finding).- Compound components (
<Menu>/<Menu.Item>) for multi-part widgets — shared state flows via context, not prop drilling through consumer code. - Polymorphic
asprop: use ONLY on layout primitives (Box,Stack,Text). On stateful/interactive widgets the type complexity explodes and ref forwarding breaks silently — give those a fixed element and explicit props instead. - Every interactive primitive forwards its ref and passes through
data-testid+ ARIA props — the §7.3 registry values belong to the CONSUMING app's spec, so the primitive must accept them, never hardcode them.
Theming
- A theme is a swap of the SEMANTIC layer only. Primitive and component tiers stay put; dark mode is a second semantic value set under the same keys, not a parallel component set.
- Density/scale variants work the same way: a second semantic spacing/type set, same keys.
- No theme conditionals inside component source (
isDark ? … : …is a finding). Components read tokens; the theme provider / CSS scope decides the values.
Monorepo placement
Per docs/DEFAULT_TARGET_ARCHITECTURE.md: libs/design-system serves apps/web (Next.js) AND apps/mobile (React Native). Subpath exports keep platforms apart:
@<org>/design-system/tokens— platform-neutral data (safe everywhere)@<org>/design-system/web— DOM primitives (Next.js/React only)@<org>/design-system/native— RN primitives
Importing /web from mobile code or /native from web code is a boundary violation. Shared logic that both primitives need lives in an internal core module, not in either platform entry.
Extraction recipes (brownfield harvest)
Run by design-system-extractor; every harvested value carries file:line evidence so the audit is verifiable, not impressionistic.
# Hex colors (3/6/8-digit) across style and component sources
grep -rnE '#[0-9a-fA-F]{8}\b|#[0-9a-fA-F]{6}\b|#[0-9a-fA-F]{3}\b' \
--include='*.css' --include='*.scss' --include='*.ts' --include='*.tsx' \
--include='*.js' --include='*.jsx' src/ apps/ libs/ 2>/dev/null | sort
# px/rem/em literals — spacing and type-scale candidates
grep -rnE '\b[0-9]+(\.[0-9]+)?(px|rem|em)\b' \
--include='*.css' --include='*.scss' --include='*.tsx' --include='*.jsx' src/ apps/ libs/ 2>/dev/null
# Font declarations
grep -rnE 'font-(family|size|weight)\s*:' --include='*.css' --include='*.scss' -r src/ apps/ 2>/dev/null- Tailwind: the
theme/theme.extendblock intailwind.config.*IS a proto-token set — read it directly, do not grep for class strings. - styled-components/emotion: the greps above hit template literals; values inside
css/styledblocks count the same as CSS. - AST when grep lies: for JSX style props and computed values, an AST query (e.g.
ast-grepforstyle={{…}}attributes) beats regex — use it when the grep output is visibly noisy.
Near-duplicate clustering heuristics (turn 400 raw values into ~30 token candidates):
- Colors: group by hue family, then by lightness steps — 14 near-identical grays are usually 4 intended ones. Report each cluster with member values, counts, and
file:linesamples. - Spacing: snap to the nearest 4px grid value; off-grid survivors with high usage counts are intentional, low counts are drift.
- Components: same UI role + ≥70% overlapping prop surface across files ⇒ duplication candidate. Count call sites; the highest-traffic implementation is the default canonical survivor, the rest become migration entries.
Testing on this stack
- Component unit tests — per declared component state (default / disabled / error / loading / per-variant): render + interaction (user-event level) + an a11y assertion (axe run or explicit role/accessible-name assertions). A variant shipped without per-state tests is incomplete, not minimal.
- Visual regression rides the EXISTING
.claude/skills/stack-playwright/SKILL.mdrunner — no parallel snapshot tool. Snapshot strategy: snapshot the component gallery/story page per variant × theme, NOT app pages. Do NOT snapshot animated states, live/relative data (dates, avatars), or full pages — those are flake amplifiers; mask dynamic regions. Anti-flakiness discipline (web-first assertions, nowaitForTimeout) comes from that skill unchanged. - Token contract tests — the reference graph is testable: every semantic token resolves to a primitive (no dangling
{…}reference); every component token resolves through the semantic tier; no orphan tokens (defined, never consumed — the token build's reference graph answers this); all themes define the SAME semantic key set — a key present in light but absent in dark is a contract failure, not a styling bug.
Spec validation checks
Checks the spec validators, code-reviewer, and ui-ux-reviewer delegate here for design-system-touching diffs:
| Check | Severity |
| Raw hex/px/font literal in component source (token files exempt) | BLOCKER |
| Semantic key set differs between themes (light/dark/density) | BLOCKER |
/web entry imported from native code, or /native from web | BLOCKER |
| Hand-edited platform output (CSS vars / TS theme / RN export) instead of token source | BLOCKER |
| Component imports a primitive token directly, bypassing the semantic tier | MAJOR |
| Theme conditional inside component source instead of a semantic-layer swap | MAJOR |
New variant delivered as a forked component instead of a variant union value | MAJOR |
| Interactive primitive without ref forwarding or accessible-name passthrough | MAJOR |
| DS primitive re-implemented in an app instead of consumed from the library | MAJOR |
| Token added without a consumer (speculative token) | MINOR |
Live validation commands
R-VAL obligations for design-system changes — exact invocations live in the host docs/DEV_SETUP.md; the rows below are the obligations:
| Check | Typical shape | |
| Token source parses and builds ALL platform outputs | npx style-dictionary build (or the host's token build target) — one source, every output regenerated | |
| No raw hex/px in component dirs | `grep -rnE '#[0-9a-fA-F]{3,8}\b | \b[0-9]+px\b' --include='.tsx' --include='.ts' libs/design-system/src/components/` → MUST return empty (token source/output files exempt) |
| Token contract tests green | the host's unit-test target for the token package (reference resolution + theme key parity) | |
| A11y lint pass | eslint-plugin-jsx-a11y for web primitives / the host's RN a11y lint config | |
| Stories/docs build | the host's Storybook (or equivalent) build target — a primitive without a story/doc entry is undocumented API |
"Pass" means observed, not assumed — run the command, read the output. All rows must pass before commit per .claude/rules/LIVE_VALIDATION.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

