Skip to main content

Every design system I have rebuilt had the same root problem. The components looked fine, but the values underneath them were scattered. One button used a hex code, another used a variable, a third used a colour someone picked in a hurry two years ago. Getting design tokens and component library architecture right is what stops that from happening again, and it is the part most teams skip because it feels invisible.

This guide explains how I structure both on enterprise and government products, and how the two layers connect. If you are planning a system from scratch, read it alongside my scalable design system guide.

What design tokens and component library architecture actually do

Design tokens are named design decisions: a colour, a spacing step, a radius, a font size, a shadow, a motion duration. A component library is the set of reusable building blocks, such as buttons, inputs, tables and cards, that are built only from those tokens.

The relationship is one way. Tokens never know about components. Components always read from tokens. When that rule holds, a brand refresh, a dark theme or an Arabic typography change becomes an update to tokens, and every component follows automatically.

Three layers of design tokens

I always split tokens into three layers. It looks like extra work at first. It saves weeks later.

1. Base tokens (the palette)

These are raw values with neutral names: neutral.50 to neutral.900, gold.500, green.500, space.4, radius.md. Base tokens describe what a value is, not where it is used. Components are never allowed to use them directly.

2. Semantic tokens (the meaning)

Semantic tokens point to base tokens and describe purpose: surface.card, surface.sider, text.muted, border.subtle, brand.accent, status.danger. This is the layer designers and developers talk in, and it is the layer that changes between themes. Dark mode is mostly a second set of semantic mappings to the same base palette.

3. Component tokens (the exceptions)

A small number of components need their own tokens, such as button.primary.bg or table.row.hover. I keep this layer thin and only add to it when a component genuinely needs to differ from the semantic default. If every component has fifty private tokens, the system has quietly become a collection of one-off designs again.

Where the tokens live

The single most useful decision I made was to stop copying values by hand. Tokens are defined once, read from the design file through a connector, and stored as JSON in the repository using the open design tokens format. A build step turns them into CSS variables and theme files for the component framework.

That gives one direction of travel: design file to tokens to code. Nobody edits a colour in a component file, and nobody has to ask which grey is the right one.

Component library architecture in tiers

Tokens solve values. The component library has to solve structure. I organise it in three tiers.

  • Primitives: button, input, select, checkbox, tag, avatar, icon. Small, stable, heavily tested, and owned by the design system team.
  • Composites: data table with filters, form section, card with actions, page header, empty state. Built only from primitives and tokens.
  • Patterns: full layouts such as a dashboard shell, a list and detail view or a multi-step form. These describe how composites work together and often live as templates rather than components.

The rule between tiers is strict. Features import only from the shared UI layer, never from each other, and never build a new primitive. When a team needs something that does not exist, they propose it to the system instead of building a private copy. This boundary is checked by a lint rule, not by memory.

Component APIs that stay predictable

A good component library feels boring to use, in the best way. I follow a few API rules on every project:

  • Variant and colour are separate props. variant describes shape (solid, outline, ghost) and color describes meaning (primary, danger, neutral). Mixing them creates combinations nobody can remember.
  • Every state is designed. Default, hover, focus, active, disabled, loading and error, for every interactive component.
  • Every string is translatable. No hard-coded text inside components.
  • Logical CSS only. margin-inline-start, never margin-left, so components mirror correctly in Arabic.

Designing tokens for Arabic and RTL

Most of my products ship in English and Arabic from day one. That affects the token architecture more than people expect. Arabic text needs its own font family and often a larger size and line height to stay readable, so typography tokens are split by script rather than assumed to be universal. Icons that imply direction, such as arrows and chevrons, are marked as mirrorable in the library. Spacing tokens are direction neutral by design, because they are only ever applied through logical properties.

When these choices are made in the tokens, every component inherits them. When they are left to individual components, Arabic breaks in a different way on every screen.

Making the library usable by AI agents

A large share of first drafts on my projects is now written by AI coding agents. Left alone, they invent colours and rebuild buttons. A clean token and component architecture is what makes them useful instead of risky. Each repository includes a short rules file that tells the agent to use semantic tokens only, to import from the shared UI layer and to never create a new primitive. Lint checks then block anything that slips through. I wrote more about this shift in From Screens to Systems: Generative UI and the New Job of the Designer.

Common mistakes to avoid

  • Naming tokens by appearance, such as blue-button, instead of by purpose.
  • Letting components use base tokens directly, which makes theming impossible.
  • Growing the component token layer until it duplicates every semantic token.
  • Building composites before the primitives are stable.
  • Treating RTL as a late translation task instead of a token decision.

Frequently asked questions

What is the difference between design tokens and a component library?

Design tokens are the named values, such as colours, spacing and type. A component library is the set of reusable UI parts built from those values. Tokens describe the decisions. Components apply them.

How many design tokens should a system have?

There is no fixed number, but a healthy system usually has a broad base palette, a focused semantic layer of a few dozen to a hundred tokens, and very few component tokens. If the semantic layer keeps growing, check for tokens that mean the same thing.

Should tokens live in the design file or in code?

Both, from one source. I define them in the design file, pull them into the repository automatically, and generate code from there. What matters is that nobody edits them in two places.

If you are planning or untangling a design system, I offer product design consulting focused on tokens, component architecture and Arabic-first interfaces.

Getting design tokens and component library architecture right early pays off for years. The W3C Design Tokens Community Group maintains the shared format I build on, and it makes design tokens and component library work portable across tools and teams.