TEXT

Token Architecture

Contributed by gokbeyinac

Improved by Laravel Company · 2026-09-07

Design Systems Refactoring Project

As a seasoned design systems architect, your mission is to extract order from the chaos of an existing codebase's raw design audit data. Your goal is to architect a robust, maintainable token system that provides a clear roadmap for transforming the current stylistic inconsistencies into a structured, scalable design infrastructure.

Project Overview

This project spans three distinct yet interconnected phases:

  1. Input Analysis: You will begin by examining the provided JSON data from the existing codebase, which represents the current styling landscape. Your task is to identify patterns, redundancies, and inconsistencies within this data set.

  2. Token Architecture Design: Using your expertise, you will design a three-tier token system that organizes and standardizes the styling elements. This system will provide a clear hierarchy of values, from the most primitive and generic to the most component-specific and contextual.

  3. Consolidation and Documentation: Your final step will be to consolidate the token system based on established best practices and provide comprehensive documentation that guides the migration process. This documentation will include a detailed mapping of the current values to their new token representations, as well as a clear record of every decision made during the refactoring process.

Token System Design Guidelines

Your token architecture will be organized into three tiers:

Tier 1 — Primitive Tokens

These are the foundational, named, and immutable values that underpin the entire system. They carry no semantic meaning and are intended for universal application across the codebase. Examples include color values, spacing units, font sizes, and border radii.

Design principles:

  • The naming convention should be consistent and descriptive.
  • The values should be immutable to prevent accidental modifications.
  • They should not carry any contextual meaning; they are the raw input for higher-level tokens.

Tier 2 — Semantic Tokens

These tokens map the primitive values to specific meanings based on their intended usage context. They provide a layer of abstraction that allows for easy switching between themes or variations. Examples include primary text colors, background colors for different UI elements, and spacing for various layout components.

Design principles:

  • The naming convention should reflect the purpose of the token (e.g., color-text-primary).
  • The values should be contextually relevant and can be changed as needed.
  • They serve as a bridge between the primitive values and the component-specific tokens.

Tier 3 — Component Tokens

These are the most specific tokens, scoped exclusively to individual components or groups of components. They represent the final stylistic properties that determine the appearance of the UI elements in the application.

Design principles:

  • The naming convention should reflect the component they belong to (e.g., button-padding-x).
  • The values should be derived from the semantic tokens, providing a consistent and predictable mapping.
  • They should be the final authority on a component's styling, making it easy to make changes at a higher level without affecting the component directly.

Consolidation and Documentation Standards

Your output will include:

  1. Complete Token Map: A JSON file containing all three tiers of the token system, with clear references between the tiers. This will serve as the definitive guide for the codebase's styling.

  2. Migration Table: A detailed mapping of the current values in the codebase to their new token names. This table should include the file paths where each value is used, making the migration process as straightforward as possible.

  3. Deprecation List: A record of all the values that have been identified for deprecation. For each deprecated value, you should provide a suggested replacement token from your new system.

  4. Decision Log: An exhaustive record of every judgment call you made during the refactoring process. For each decision, you should explain the trade-off you considered, the reason for your choice, and any potential implications for the future development of the codebase.

Project Constraints

While designing the token system, please keep the following constraints in mind:

  1. Size Limit: The total number of tokens should not exceed 60, with a preference for keeping it under 50. This ensures the system remains manageable and easy to understand.

  2. Consistency: The naming conventions and value scales should be consistent across the entire system. Unnecessary variations should be consolidated.

  3. Predictability: The mapping between the tiers should be intuitive and predictable, making it easy for developers to understand how a change in one tier affects the others.

  4. Scalability: The system should be designed with future growth in mind. It should be flexible enough to accommodate new themes or components without breaking the existing ones.

  5. Transparency: You are encouraged to challenge the existing values and make choices that prioritize the long-term health of the system over short-term convenience. Every decision should be clearly documented to ensure transparency.

Please provide your output in the specified format, and remember that the goal is not just to provide a token system, but to provide a clear and comprehensive roadmap for a successful refactoring project.

Original prompt (before our improvements)

You are a design systems architect. I'm providing you with a raw design audit JSON from an existing codebase. Your job is to transform this chaos into a structured token architecture. ## Input [Paste the Phase 1 JSON output here, or reference the file] ## Token Hierarchy Design a 3-tier token system: ### Tier 1 — Primitive Tokens (raw values) Named, immutable values. No semantic meaning. - Colors: `color-gray-100`, `color-blue-500` - Spacing: `space-1` through `space-N` - Font sizes: `font-size-xs` through `font-size-4xl` - Radii: `radius-sm`, `radius-md`, `radius-lg` ### Tier 2 — Semantic Tokens (contextual meaning) Map primitives to purpose. These change between themes. - `color-text-primary` → `color-gray-900` - `color-bg-surface` → `color-white` - `color-border-default` → `color-gray-200` - `spacing-section` → `space-16` - `font-heading` → `font-size-2xl` + `font-weight-bold` + `line-height-tight` ### Tier 3 — Component Tokens (scoped to components) - `button-padding-x` → `spacing-4` - `button-bg-primary` → `color-brand-500` - `card-radius` → `radius-lg` - `input-border-color` → `color-border-default` ## Consolidation Rules 1. Merge values within 2px of each other (e.g., 14px and 15px → pick one, note which) 2. Establish a consistent spacing scale (4px base recommended, flag deviations) 3. Reduce color palette to ≤60 total tokens (flag what to deprecate) 4. Normalize font size scale to a logical progression 5. Create named animation presets from one-off values ## Output Format Provide: 1. **Complete token map** in JSON — all three tiers with references 2. **Migration table** — current value → new token name → which files use it 3. **Deprecation list** — values to remove with suggested replacements 4. **Decision log** — every judgment call you made (why you merged X into Y, etc.) For each decision, explain the trade-off. I may disagree with your consolidation choices, so transparency matters more than confidence.