JS Guide
HomeQuestionsTopicsCompaniesResources
BookmarksSearch

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionssystem-design
PrevNext

Learn the concept

Component Architecture at Scale

system-design
mid
component-architecture

How do you design a component library / design system for multiple teams?

design-system
component-library
design-tokens
theming
storybook
versioning
tree-shaking
accessibility
governance
monorepo
system-design
Quick Answer

A scalable design system uses design tokens for themeable foundations, a tiered component hierarchy (primitives, patterns, templates), semver versioning with a clear breaking change policy, Storybook for documentation, and an RFC governance process for multi-team contributions.

Detailed Explanation

A design system is the single source of truth for UI across an organization. At scale, it serves dozens of teams and hundreds of engineers. Getting the architecture right is critical because migration costs grow exponentially with adoption.

Requirements

Functional Requirements:

  • Shared component library consumable as an npm package
  • Consistent theming across products (light/dark, brand variants)
  • Documentation with live playground and usage examples
  • Visual regression testing to catch unintended changes
  • Accessibility baked into every component (WCAG 2.2 AA)

Non-Functional Requirements:

  • Tree-shakeable (unused components are not bundled)
  • Framework-agnostic tokens (CSS custom properties)
  • Fast adoption: teams can integrate in < 1 day
  • Backward-compatible updates (semver discipline)
  • < 50KB gzipped for the base component set

Token-Based Design Foundation

Design tokens are the atomic values of your design system: colors, spacing, typography, shadows, border radii, and motion. They are the contract between design and engineering.

Token hierarchy:

  1. Global tokens — raw values (color-blue-500: #3B82F6)
  2. Semantic tokens — purpose-based aliases (color-primary: var(--color-blue-500))
  3. Component tokens — scoped to a component (button-bg: var(--color-primary))

Why CSS custom properties?

  • Runtime theming without rebuilding
  • No JavaScript runtime overhead
  • Works with any framework (React, Vue, Svelte, vanilla)
  • Native browser support, devtools-inspectable

Component Tiers

Organize components in three tiers:

Tier 1: Primitives (Atoms)

Low-level, unstyled building blocks:

  • Button, Input, Select, Checkbox, Radio
  • Text, Heading, Icon, Badge
  • Box, Stack, Grid (layout primitives)

These have zero opinions about layout or content — they only handle behavior, accessibility, and token consumption.

Tier 2: Patterns (Molecules)

Composed from primitives with opinionated layouts:

  • SearchInput (Input + Icon + Button)
  • FormField (Label + Input + ErrorMessage)
  • Card (Box + Heading + Text + Actions)
  • DataTable (Table + Sorting + Pagination)

Tier 3: Templates (Organisms)

Page-level compositions for common layouts:

  • PageHeader, Sidebar, NavigationBar
  • DashboardLayout, FormLayout
  • ErrorPage, EmptyState

Teams consume the tier they need: use primitives for custom UIs, patterns for standard features, templates for rapid page building.

Versioning Strategy

Follow strict semver with a clear policy:

  • Patch (1.0.x): Bug fixes, accessibility improvements, no API changes
  • Minor (1.x.0): New components, new props with defaults, deprecation warnings
  • Major (x.0.0): Removed props, changed defaults, token renames

Breaking change policy:

  1. Deprecate with console warnings for 2 minor versions
  2. Provide codemods for automated migration
  3. Major releases include a migration guide
  4. Never more than 1 major release per quarter

Documentation (Storybook)

Storybook is the industry standard for component documentation:

  • Stories for each component variant and state
  • Controls panel for interactive prop exploration
  • Docs page with API reference auto-generated from TypeScript types
  • Design tokens page showing all tokens with visual swatches
  • Accessibility tab showing a11y audit results per component
  • Playground for composing components without a local dev environment

Deploy Storybook to a URL like design.company.com so designers and PMs can reference it.

Testing Strategy

  1. Unit tests (Vitest/Jest): Component logic, prop combinations, event handlers
  2. Accessibility audits (axe-core): Automated a11y checks in CI for every component
  3. Visual regression (Chromatic/Percy): Screenshot comparison to catch unintended visual changes
  4. Integration tests: Verify composed patterns work correctly together
  5. Bundle size tracking: Fail CI if the bundle exceeds the budget

Distribution

Publish as an npm package from a monorepo (Turborepo or Nx):

@company/design-tokens    → CSS variables + JSON
@company/primitives       → Tier 1 components
@company/patterns         → Tier 2 components
@company/theme            → ThemeProvider + presets

Split packages allow teams to import only what they need. Each package is individually versioned and tree-shakeable.

Tree-shaking setup:

  • Set sideEffects: false in package.json
  • Export components via named exports (no barrel files that defeat tree-shaking)
  • Use preserveModules: true in the bundler config

Theming Architecture

Support multiple themes (light, dark, brand variants) via a ThemeProvider that sets CSS custom properties on a root element:

  • Themes are JSON objects mapping semantic token names to values
  • ThemeProvider applies them as CSS custom properties on a wrapper div
  • Components consume only semantic tokens — never raw colors
  • This enables runtime theme switching without rebuilding

Governance: RFC Process

For multi-team adoption, you need a contribution process:

  1. RFC (Request for Comments): Anyone can propose a new component or breaking change
  2. Review: Design system team + 2 consuming team representatives review
  3. Prototype: Build in a branch with Storybook preview
  4. Approval: Merge after accessibility audit and visual review
  5. Release: Follow the versioning strategy above

This prevents the design system from becoming a bottleneck while maintaining quality.

Code Examples

Design token system with CSS custom properties and theme switchingTypeScript
// tokens/colors.ts — Global tokens
export const colors = {
  blue: {
    50: '#EFF6FF',
    100: '#DBEAFE',
    500: '#3B82F6',
    600: '#2563EB',
    700: '#1D4ED8',
    900: '#1E3A8A',
  },
  gray: {
    50: '#F9FAFB',
    100: '#F3F4F6',
    200: '#E5E7EB',
    700: '#374151',
    800: '#1F2937',
    900: '#111827',
  },
} as const;

// tokens/themes.ts — Semantic tokens per theme
export interface Theme {
  'color-bg-primary': string;
  'color-bg-secondary': string;
  'color-text-primary': string;
  'color-text-secondary': string;
  'color-border': string;
  'color-accent': string;
  'color-accent-hover': string;
  'shadow-sm': string;
  'shadow-md': string;
  'radius-sm': string;
  'radius-md': string;
  'radius-lg': string;
  'spacing-xs': string;
  'spacing-sm': string;
  'spacing-md': string;
  'spacing-lg': string;
}

export const lightTheme: Theme = {
  'color-bg-primary': colors.gray[50],
  'color-bg-secondary': '#FFFFFF',
  'color-text-primary': colors.gray[900],
  'color-text-secondary': colors.gray[700],
  'color-border': colors.gray[200],
  'color-accent': colors.blue[600],
  'color-accent-hover': colors.blue[700],
  'shadow-sm': '0 1px 2px rgba(0,0,0,0.05)',
  'shadow-md': '0 4px 6px rgba(0,0,0,0.07)',
  'radius-sm': '4px',
  'radius-md': '8px',
  'radius-lg': '12px',
  'spacing-xs': '4px',
  'spacing-sm': '8px',
  'spacing-md': '16px',
  'spacing-lg': '24px',
};

export const darkTheme: Theme = {
  'color-bg-primary': colors.gray[900],
  'color-bg-secondary': colors.gray[800],
  'color-text-primary': colors.gray[50],
  'color-text-secondary': colors.gray[200],
  'color-border': colors.gray[700],
  'color-accent': colors.blue[500],
  'color-accent-hover': colors.blue[600],
  'shadow-sm': '0 1px 2px rgba(0,0,0,0.3)',
  'shadow-md': '0 4px 6px rgba(0,0,0,0.4)',
  'radius-sm': '4px',
  'radius-md': '8px',
  'radius-lg': '12px',
  'spacing-xs': '4px',
  'spacing-sm': '8px',
  'spacing-md': '16px',
  'spacing-lg': '24px',
};

// Apply theme as CSS custom properties
export function applyTheme(theme: Theme, root: HTMLElement = document.documentElement) {
  for (const [key, value] of Object.entries(theme)) {
    root.style.setProperty(`--${key}`, value);
  }
}

Real-World Applications

Use Cases

Multi-Product Brand Consistency

Organizations with multiple products (e.g., Atlassian with Jira, Confluence, Trello) use a shared design system to ensure visual consistency, reduce design debt, and allow engineers to move between teams without relearning UI patterns.

White-Label SaaS Platforms

SaaS companies that offer white-label products use token-based theming to allow each customer to apply their own branding (colors, logos, typography) without changing the underlying component code.

Design-Engineering Handoff

Design tokens exported to Figma variables and CSS custom properties simultaneously create a single source of truth that eliminates translation errors between design mocks and implemented components.

Mini Projects

Token-Based Theme Playground

intermediate

Build an interactive playground where users can adjust design tokens (colors, spacing, border radius) via sliders and color pickers, seeing a set of components update in real time. Export the custom theme as CSS or JSON.

Mini Component Library with Storybook

advanced

Create a small component library (Button, Input, Card, Badge) with design tokens, TypeScript types, Storybook stories with controls, and automated accessibility audits via axe-core. Publish as an npm package.

Industry Examples

Shopify

Polaris design system provides tokens, components, and patterns for thousands of Shopify apps to maintain consistency across the Shopify ecosystem, with public governance and contribution guidelines

Atlassian

Atlassian Design System serves Jira, Confluence, Bitbucket, and Trello with shared tokens and components, using a multi-tier token system (global, semantic, component) for scalable theming

GitHub

Primer design system provides React components, CSS utilities, and design tokens for GitHub's web interface, with public Storybook documentation and Figma libraries

Resources

Storybook Documentation

docs

Style Dictionary - Design Token Build System

docs

Design Tokens W3C Community Group

docs

Related Questions

What makes a good component API for a design system?

junior
component-architecture

How do you approach a frontend system design interview?

junior
fundamentals
Previous
Design a real-time notification system for a web application
Next
Design a social media news feed with infinite scroll
PrevNext