design-token-system
Skill9 starsChanged 5 months agoApache-2.0View on GitHub
Architects a framework-agnostic design-token system with primitive/semantic/component tiers, theming and multi-brand/dark-mode alias contracts, and multi-platform export (CSS vars, Tailwind, JS/TS, iOS/Android) from one W3C-DTCG source via Style Dictionary.
In this repository147 other files it gives its agents.
- second-brain/AGENTS.mdAGENTS.md
- second-brain/CLAUDE.mdCLAUDE.md
- agent-tool-mcp-builderSkill
- api-design-reviewSkill
- async-concurrency-correctnessSkill
- audit-accessibility-wcagSkill
- audit-license-complianceSkill
- audit-technical-seoSkill
- auth-jwt-sessionSkill
- author-codemodSkill
- brainstorm-designSkill
- build-audit-loggingSkill
- build-cdc-streaming-pipelineSkill
- build-cli-toolSkill
- build-data-tableSkill
- build-etl-pipelineSkill
- build-form-validationSkill
- build-native-mobile-uiSkill
- build-office-docsSkill
- build-offline-first-syncSkill
- build-react-componentSkill
- build-realtime-channelSkill
- build-spreadsheetSkill
- build-vector-searchSkill
- caching-strategySkill
- cicd-pipeline-authorSkill
- cloud-cost-optimizeSkill
- code-commentsSkill
- code-reviewSkill
- compose-local-dev-stackSkill
- configure-bundler-buildSkill
- configure-dns-tlsSkill
- configure-reverse-proxy-lbSkill
- configure-security-headers-cspSkill
- contract-testingSkill
- datetime-timezone-correctnessSkill
- db-migration-safetySkill
- debug-ci-pipeline-failureSkill
- debug-flaky-testsSkill
- debug-frontend-browserSkill
- debug-root-causeSkill
- defend-llm-prompt-injectionSkill
- deliver-webhooksSkill
- dependency-upgradeSkill
- deploy-releaseSkill
- design-api-paginationSkill
- design-authorization-modelSkill
- design-backup-dr-recoverySkill
- design-event-sourcing-cqrsSkill
- design-multi-tenancySkill
- design-protobuf-grpc-serviceSkill
- design-relational-schemaSkill
- design-search-index-infraSkill
- design-state-machineSkill
- diff-table-paritySkill
- distributed-locks-leasesSkill
- dockerfile-optimizeSkill
- encrypt-sensitive-dataSkill
- error-messageSkill
- estimate-workSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 1 is distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 36
Default to 2 tiers (primitive + semantic).
- Very specific: line 38
One source of truth in W3C DTCG JSON: Use the spec's $value / $type and {dot.path} references so any compliant tool (Style Dictionary v4+, …
- Very specific: line 77
Run style-dictionary build.
- Very specific: line 81
Forbid raw values in app code with a linter: Add stylelint-declaration-strict-value (web CSS) or an ESLint/lint rule that bans hex, rgb(, …
- Very specific: line 89
Semantic tokens holding literal values: instead of {references}. The indirection is the entire point — a literal hex in a semantic token …
- Very specific: line 101
Aliases resolve: every semantic $value is a {reference}, not a literal.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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
When to Use
Reach for this skill when the problem is the token architecture and export pipeline, not a single component's styling:
- "Set up design tokens / a theme system from scratch"
- "Add dark mode without forking every color"
- "Support multiple brands / white-label from one codebase"
- "Export the same tokens to CSS, Tailwind, and our iOS + Android apps"
- "Adopt Style Dictionary / the W3C Design Tokens (DTCG) format"
- "We have 300 hardcoded hex/px values — give us a governed token layer"
NOT this skill:
- Writing the markup/utility classes that consume tokens → style-responsive-tailwind
- Picking the actual palette, type pairing, or visual mood → brainstorm-design
- Translating one Figma frame into a component → implement-from-design
- Building the React component that renders from tokens → build-react-component
- Wiring a cross-platform app shell/build → scaffold-cross-platform-app
- Certifying contrast ratios meet WCAG → audit-accessibility-wcag (this skill structures color; it does not verify contrast)
Steps
Build exactly three tiers — never let a component read a primitive. This is the whole architecture; get it wrong and theming is impossible.
Tier Names mean References Example Rule Primitive (global/core) nothing — raw scale literal values only blue.500 = #2563EB,space.4 = 16pxNo semantics. Never themed. Never imported by components. Semantic (alias) role/intent → primitives color.bg.surface → gray.50,color.intent.danger → red.600The only layer that swaps per theme/brand. Component (scoped) one part → semantics button.primary.bg → color.intent.brandOptional; add only when a component overrides a semantic. Default to 2 tiers (primitive + semantic); add component tokens only where a component genuinely diverges. Components and Tailwind/CSS consume semantic tokens only.
One source of truth in W3C DTCG JSON. Use the spec's
$value/$typeand{dot.path}references so any compliant tool (Style Dictionary v4+, Tokens Studio) can read it. No per-platform hand-edited files.// tokens/primitive/color.json { "color": { "blue": { "500": { "$type": "color", "$value": "#2563EB" } } } } // tokens/semantic/color.json — alias, NOT a literal { "color": { "intent": { "brand": { "$type": "color", "$value": "{color.blue.500}" } }, "bg": { "surface": { "$type": "color", "$value": "{color.gray.50}" } } } }A semantic token whose
$valueis a literal hex is a bug — it must be a{reference}.- Theming = swap the semantic layer, never fork the palette. Light, dark, and each brand are alternate semantic files pointing at the same primitives. One
primitive/set;semantic/light.json,semantic/dark.json,semantic/brand-acme.json. Dark mode flipsbg.surface → gray.900instead ofgray.50— the primitives don't move. Never createblue.500.dark. - Author color in OKLCH so themes shift predictably. Build scales in OKLCH (fall back to HSL only if tooling can't): equal lightness steps stay perceptually even and a brand hue rotation keeps contrast. Hardcoded hex per shade drifts. Emit hex/rgb as a build output for legacy targets, not as the source.
- Cover every token type — color is the easy half. Define and
$typeall of:color,dimension(spacing/sizing),fontFamily/fontWeight/fontSize/lineHeight/letterSpacing(typography),borderRadius,shadow(elevation),duration/cubicBezier(motion), and z-index. Derive primitives from a base scale (4px grid for spacing, a modular ratio for type); semantics name the use (space.inline.sm,text.heading.lg). Export everything from one Style Dictionary config. One source → many platforms, each with the right transform group and output format:
// style-dictionary.config.js (v4 — ESM) export default { source: ['tokens/primitive/**/*.json', 'tokens/semantic/light.json'], platforms: { css: { transformGroup: 'css', buildPath: 'build/css/', files: [{ destination: 'vars.css', format: 'css/variables', options: { outputReferences: true } }] }, // keeps var(--x) chains tailwind: { transformGroup: 'js', buildPath: 'build/tw/', files: [{ destination: 'tokens.cjs', format: 'javascript/module-flat' }] }, ts: { transformGroup: 'js', buildPath: 'build/ts/', files: [{ destination: 'tokens.ts', format: 'javascript/es6' }] }, ios: { transformGroup: 'ios-swift', buildPath: 'build/ios/', files: [{ destination: 'Tokens.swift', format: 'ios-swift/class.swift' }] }, android: { transformGroup: 'android', buildPath: 'build/android/', files: [{ destination: 'tokens.xml', format: 'android/resources' }] } } };Run
style-dictionary build. For each extra theme, run the same config withsemantic/dark.jsonswapped intosourceand scope output under[data-theme="dark"](CSSoptions.selector).- Wire Tailwind to the generated tokens — do not retype them.
tailwind.configimportsbuild/tw/tokens.cjsintotheme.colors/spacing/.... CSS vars drive runtime theme switching: Tailwind utilities resolvevar(--color-bg-surface), and the[data-theme]attribute swaps which value that var resolves to. One toggle, zero recompiled CSS. - Forbid raw values in app code with a linter. Add
stylelint-declaration-strict-value(web CSS) or an ESLint/lint rule that bans hex,rgb(, and barepxoutsidetokens/andbuild/. Raw values must fail CI, not slip through code review. - Govern it as a published API. Fix a naming grammar
category.role.variant.state(e.g.color.bg.surface.hover); semver the published token package (removed/renamed semantic token = major, added = minor, primitive value tweak = patch); keep a CHANGELOG; treat thesemanticlayer as the public API and primitives as private/internal.
Common Errors
- Components reading primitives (
button { color: blue.500 }). Dark mode and rebrand degrade to find-and-replace. Components must reference semantics only. - Forking the palette per theme (
blue.500.dark). Palette count explodes and brands drift. Themes swap the semantic alias target; primitives are shared and immutable. - Semantic tokens holding literal values instead of
{references}. The indirection is the entire point — a literal hex in a semantic token can't be retargeted by a theme. outputReferences: false(the default) flattening CSS vars. The build bakes#2563EBinto every rule, killing runtime theme switching. Setoptions: { outputReferences: true }sovar(--color-intent-brand)chains survive.- Duplicating tokens into
tailwind.configby hand. They desync within the first week. Import the Style Dictionary build output; never maintain two sources. - No grid/scale — arbitrary
13px,17pxprimitives. Defeats consistency. Primitives come from a 4px (or 8px) grid and a modular type ratio. - Treating contrast as solved because colors are tokenized. Tokens organize color; they don't guarantee
bg.surface/text.primarymeet 4.5:1. Run audit-accessibility-wcag on each theme. - Component tokens for everything, including parts that never override a semantic. Pure bloat. Add a component token only where it diverges from the semantic.
- Per-platform manual edits to
build/outputs. They're regenerated; your edit vanishes on the next build. Fix the source and rebuild. - No versioning/changelog on the token package. A renamed semantic token silently breaks every consumer. Semver it; a rename is a breaking (major) change.
Verify
- Tier discipline:
grepapp/component source — zero references to primitive names (blue.500,space.4) and zero raw hex/rgb(/barepx. Every match is a violation. - Aliases resolve: every semantic
$valueis a{reference}, not a literal;style-dictionary buildreports 0 unresolved references and exits0. - One source, many outputs: a single
style-dictionary buildproduces CSS, Tailwind, TS, iOS, and Android artifacts from the sametokens/tree (no hand-edited platform file). - Theme swap is alias-only: diff
semantic/light.jsonvssemantic/dark.json— they differ only in reference targets;primitive/is byte-identical across themes. Adding a brand touches no primitive. - Runtime switch works: toggling
[data-theme="dark"]on the built CSS recolors the page with no CSS recompile (provesoutputReferenceschains survived). - Lint gate is live: committing a raw
#fffor12pxin app code fails CI, not review. - Native parity: the same semantic token (e.g.
color.intent.brand) yields the same color inbuild/css/vars.css,build/ios/Tokens.swift, andbuild/android/tokens.xml. - Governance: naming matches
category.role.variant.state, the package carries a semver + CHANGELOG, and a token rename ships as a major bump.
Done = one W3C-DTCG source builds all platforms with zero unresolved references, components reference semantics only (lint-enforced in CI), themes/brands swap via alias targets over shared immutable primitives, and runtime theme switching recolors with no recompile.
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.

