agentleFS
isabelle-barpisabelle-barp/agent-brain/skills/stack-design-system/SKILL.md

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.

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
  1. Very specific:

    Every interactive primitive forwards its ref and passes through data-testid + ARIA props — the §7.3 registry values belong to the CONSUMING …

    line 52
  2. Very specific:

    No theme conditionals inside component source (isDark ?

    line 58
  3. Very specific:

    Run by design-system-extractor.

    line 71

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 by design-system-developer via /dev-design-system)
  • dev-frontend / dev-mobile tasks that consume or modify the shared UI library (libs/design-system or the host's equivalent per docs/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 populated theme/theme.extend block in tailwind.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:

  1. Primitive — raw values, no meaning (blue.600, space.4). Never imported by component source.
  2. Semantic — meaning, no rawness (action.primary, surface.raised). References primitives only.
  3. 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 / tone props with CLOSED unions. Adding a variant means adding a union value + its component tokens — never forking the component (PrimaryButton2.tsx is a finding).
  • Compound components (<Menu> / <Menu.Item>) for multi-part widgets — shared state flows via context, not prop drilling through consumer code.
  • Polymorphic as prop: 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.extend block in tailwind.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/styled blocks count the same as CSS.
  • AST when grep lies: for JSX style props and computed values, an AST query (e.g. ast-grep for style={{…}} 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:line samples.
  • 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.md runner — 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, no waitForTimeout) 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:

CheckSeverity
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 webBLOCKER
Hand-edited platform output (CSS vars / TS theme / RN export) instead of token sourceBLOCKER
Component imports a primitive token directly, bypassing the semantic tierMAJOR
Theme conditional inside component source instead of a semantic-layer swapMAJOR
New variant delivered as a forked component instead of a variant union valueMAJOR
Interactive primitive without ref forwarding or accessible-name passthroughMAJOR
DS primitive re-implemented in an app instead of consumed from the libraryMAJOR
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:

CheckTypical shape
Token source parses and builds ALL platform outputsnpx 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 greenthe host's unit-test target for the token package (reference resolution + theme key parity)
A11y lint passeslint-plugin-jsx-a11y for web primitives / the host's RN a11y lint config
Stories/docs buildthe 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.