---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://framesfield.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
title: "Design System Audit and Tailwind v4 Migration"
description: "Eliminate hardcoded hex sprawl, broken mobile tables, and fragile dark mode across an existing Astro, React, or Next.js frontend in under 45 minutes: grep raw color leaks, consolidate a 3-tier CSS custom property contract inside Tailwind CSS v4 @theme inline, swap SVG strokes to currentColor, and gate every route at 1440px and 390px via Playwright MCP and an isolated UI Design Critic subagent."
canonical: "https://framesfield.com/workflows/design-system-audit-and-token-migration"
---

# Design System Audit and Tailwind v4 Migration

> Eliminate hardcoded hex sprawl, broken mobile tables, and fragile dark mode across an existing Astro, React, or Next.js frontend in under 45 minutes: grep raw color leaks, consolidate a 3-tier CSS custom property contract inside Tailwind CSS v4 @theme inline, swap SVG strokes to currentColor, and gate every route at 1440px and 390px via Playwright MCP and an isolated UI Design Critic subagent.

- **Canonical URL:** https://framesfield.com/workflows/design-system-audit-and-token-migration
- **Difficulty:** Intermediate
- **Estimated Time:** 35 – 45 min
- **Estimated Cost:** $0 API (uses existing coding-agent session)
- **Last Verified:** 2026-12-01
- **Tools Used:** Recraft V4.1 (https://framesfield.com/specs/recraft-v4-1), Black Forest Labs FLUX 3 Image (https://framesfield.com/specs/flux-3)

## Pipeline Architecture

01. **Baseline Hex & DOM Scan** (Grep + Playwright MCP): Find hardcoded hexes, CLS traps & overflow routes
02. **3-Tier Token Contract** (Tailwind v4 @theme inline): Map :root & [data-theme='dark'] semantic vars
03. **Component & SVG Sweep** (Coding Agent + Skill 32): Replace arbitrary utilities + bind SVG currentColor
04. **Visual & A11y Sign-Off** (Playwright + @ui-design-critic): Verify 1440px & 390px PNGs + WCAG AA contrast

## Playbook

## Why AI-built frontends accumulate visual debt so fast

Even experienced teams shipping rapidly with AI coding assistants quickly notice their stylesheets fragmenting after three or four sprints: one page uses `bg-dr-paper`, another uses `bg-stone-50`, a third invents `text-dr-muted`, and an inline SVG icon disappears completely when dark mode turns on. Once arbitrary colors and magic pixel widths scatter across 40 components, every redesign turns into a brittle find-and-replace exercise.

This workflow gives you a deterministic 45-minute cleanup loop that locks a **3-tier semantic token architecture** in Tailwind CSS v4 and gates every future visual edit through **Playwright MCP** and an isolated **UI Design Critic subagent**.

## Step 1: Run the baseline leak scan

Copy `audit-design-tokens.sh` from the box below and execute it at your project root. In five seconds, it exposes four real design-system leaks that standard TypeScript checks ignore:

1. **Arbitrary hex Tailwind utilities** (`bg-dr-paper`, `text-dr-muted`, `border-dr-text`) that bypass your token system and break dark mode.
2. **Inline hex styles** hidden inside JSX or Astro template strings.
3. **`<img>` elements lacking explicit `width` and `height`**, which trigger Cumulative Layout Shift (`CLS`) on slower mobile connections.
4. **Hardcoded black SVG icon strokes** (`stroke="#000000"`) that vanish against dark surfaces instead of inheriting CSS `currentColor`.

Save the output count as your starting baseline—your target at the end of Step 4 is **`0` leaks across all four checks**.

## Step 2: Consolidate a 3-tier token contract in Tailwind v4

Install [Skill 32: CSS Design Tokens and Tailwind v4 Theme Skill](/skills/design-tokens-tailwind-v4-skill) (and [Skill 03: Figma MCP Design-to-Code Sync](/skills/figma-mcp-design-sync) if syncing directly from Figma Variables). Consolidate all color, border, typography, and radius decisions into one clean cascade:

| Token Tier | Where It Lives | Allowed in Component JSX? | Example |
| --- | --- | --- | --- |
| **Tier 1: Primitive Scale** | `:root` raw palette block | **Never** | `--raw-stone-50: #F7F7F5;` |
| **Tier 2: Semantic Intent** | `:root` + `[data-theme="dark"]` | Indirectly via Tier 3 | `--surface-canvas: var(--raw-stone-50);` |
| **Tier 3: Tailwind v4 `@theme inline`** | `@theme inline { ... }` | **Yes (Exclusive API)** | `class="bg-canvas text-ink border-hairline"` |

Verify that every muted foreground token (`--ink-muted`) paired against both `--surface-canvas` and `--surface-card` exceeds **WCAG 2.1 AA contrast (`>= 4.5:1`)** in light and dark modes before touching component markup.

## Step 3: Sweep components, SVGs, and media assets cleanly

Refactor components directory by directory rather than rewriting your entire repository in one massive diff:

- **Replace raw color classes with semantic utilities:** Map every off-white background to `bg-canvas` or `bg-surface`, every subtle border to `border-hairline`, every secondary paragraph to `text-ink-muted`, and every primary brand accent to `text-signal` / `bg-signal`.
- **Unify SVG icon ownership:** Optimize generated or exported vector icons (such as brand sets produced in [Recraft V4.1](/specs/recraft-v4-1)) using [Skill 30: SVG Optimization and Brand Icon System Skill](/skills/svg-optimization-and-icon-system-skill), removing flat background `<rect>` elements and switching monochrome strokes to `currentColor`.
- **Standardize raster media:** Re-encode oversized raw PNG hero banners (such as high-res [Black Forest Labs FLUX 3 Image](/specs/flux-3) 2K–4K renders) into responsive WebP/AVIF sets with exact numeric `width` and `height` dimensions via [Skill 31: Sharp WebP, AVIF and Responsive Image Skill](/skills/sharp-responsive-webp-image-pipeline-skill).
- **Guard mobile overflow:** Wrap every data `<table>` and `<pre>` code block inside `overflow-x-auto` and add `min-w-0` onto flex and grid children that contain long code strings or URLs.

## Step 4: Gate both light/dark and 1440px/390px via Playwright MCP + Subagent

Never sign off a CSS migration solely on a clean `npm run build`. Start your local preview server (`npm run dev` or `npm run preview`) and wire [Skill 26: Playwright Visual QA MCP Server](/skills/playwright-visual-qa-mcp-setup) alongside [Skill 35: UI Design Critic and Accessibility Subagent](/skills/ui-design-critic-and-a11y-agent).

Delegate your primary pages (`/`, `/pricing`, detail pages) to `@ui-design-critic`:
1. Captures real rendered screenshots at **`1440×900` desktop** and **`390×844` mobile** (in both light and dark modes if supported).
2. Asserts `document.documentElement.scrollWidth <= window.innerWidth` so zero horizontal scrollbar leaks onto mobile phones.
3. Confirms `0` browser console errors, `0` failed image/font network responses (`>= 400`), visible keyboard `:focus-visible` outlines, and clean WCAG AA contrast.
4. Re-runs `audit-design-tokens.sh` confirming **`0` arbitrary hex utilities** remain.

Pair this migration guide with [Guide 10: AI Design-to-Code: Figma MCP, Tokens and Visual QA](/guides/design-to-code-ai-engineering-guide) and [Workflow 04: Figma Design to Production Astro Landing Section via MCP](/workflows/figma-design-to-astro-landing-section) to keep every new section locked to your design system permanently.

## Copyable Asset: One-Command Design System Leak Audit & Tailwind v4 Token Starter (audit-design-tokens.sh)

```bash
#!/usr/bin/env bash
set -euo pipefail

echo "=== 1. Arbitrary Hex Utilities in Components & Pages (Target: 0) ==="
grep -rnE '(bg|text|border|fill|stroke)-\[#[0-9a-fA-F]{3,8}\]' src/components src/pages || echo "PASS: 0 arbitrary hex Tailwind classes found."

echo ""
echo "=== 2. Inline Hex Color Declarations Inside Markup (Target: 0) ==="
grep -rnE 'style="[^"]*#[0-9a-fA-F]{3,6}' src/components src/pages || echo "PASS: 0 inline hex styles found."

echo ""
echo "=== 3. Images Missing Explicit width= or height= (CLS Risk) ==="
grep -rn '<img ' src/components src/pages | grep -vE 'width=.*height=|height=.*width=' || echo "PASS: Every <img> carries explicit width & height."

echo ""
echo "=== 4. Raw SVG Icons with Hardcoded Black Strokes/Fills ==="
grep -rnE '(stroke|fill)="#(000|000000|111|111111)"' src/components public/images/icons 2>/dev/null || echo "PASS: No hardcoded black SVG icon fills detected."
```

## FAQ

### Why use @theme inline instead of @theme in Tailwind CSS v4?

Writing @theme { --color-canvas: #F7F7F5; } hardcodes static hex values into compiled utility classes, breaking runtime theme toggling. Writing @theme inline { --color-canvas: var(--surface-canvas); } binds Tailwind utilities directly to live CSS custom properties so toggling [data-theme='dark'] re-themes every component in one block.

### Do I need Figma to run this design-system audit and migration?

No. If your team maintains Figma Variables, connecting Figma MCP lets your agent verify 1:1 token naming parity. If you do not have Figma, the audit script, Tailwind v4 token hierarchy, and Playwright visual QA loop still clean up any existing codebase.

### How do I prevent coding agents from re-introducing hardcoded hexes in future PRs?

Keep Skill 32 installed in .claude/skills/ or .cursor/skills/, document your semantic token table inside AGENTS.md, and add the grep command from audit-design-tokens.sh into your npm run audit or GitHub Actions CI workflow.
