🪄 refactor-ui — Atomic UI Design & Interface Refactoring Engine
Systematically evaluate, refine, and refactor user interfaces using the 10 atomic
heuristics of Wathan & Schoger's Refactoring UI, extended with modern techniques
(container queries, WCAG 2.2, theming parity, z-scale discipline) distilled from a
127-source corpus of production UI skills. Design treated as deterministic,
engineering-grade visual decisions — routed through six execution modes so the
agent loads only what the task needs.
When to Use
Triggers (mode chosen by phrase, default review):
- "Review this UI / screen / component" — verdict + severity table, no edits.
- "Audit this UI for contrast, spacing, anti-patterns" — scripted scan + scored report.
- "Refactor this UI / make it look professional / improve this design" — the 5-step refactor.
- "Make all pages consistent / refactor the whole dashboard" — multi-page sweep.
- "Extract design tokens / too many grays / set up a type scale" — rename-and-centralize.
- "Final pass before launch / ship-readiness" — polish triage.
Anti-triggers:
- Extracting tokens from a live URL or screenshot without refactoring existing code — use
designscope.
- Motion choreography, easings, entrance/exit sequences — use the
animate skill (this skill owns only the static-cue rule).
- Backend logic, state architecture, or novel branding/illustration from scratch.
Quick Reference
Mode router (full contracts in references/modes.md)
| Mode |
Scope |
Writes |
Blocking gate |
| review (default) |
One component; verdict |
Nothing |
— |
| audit |
One surface; scripted + heuristic scan |
.agents/artifacts/ui-audit-report-<ts>.md |
WCAG 2.2 AA failure = Block |
| improve |
One surface; 5-step refactor |
Component code |
5-state + contrast gates |
| sweep |
Multi-page system |
Code + sweep-matrix-<ts>.md |
Consistency matrix |
| tokens |
Styling layer |
Token defs + call sites |
Zero literals remain |
| polish |
Whole path, all states |
Narrow fixes |
Zero P1 drift |
The Atomic Heuristics
| # |
Heuristic Domain |
Core Problem Solved |
Primary Tool / Technique |
| 01 |
Visual Hierarchy |
Everything competing for attention |
Primary focal point + aggressive de-emphasis of secondary elements |
| 02 |
Typography Scale |
Inconsistent, uncalibrated font sizes |
6-tier scale with proportional line-heights and optical font weights |
| 03 |
Color Palette |
Garish, saturated, or arbitrary colors |
9-step neutrals + primary brand hue + functional status semantics |
| 04 |
Spacing Grid |
Arbitrary margins and cramped layouts |
Fixed 4px/8px spacing ramp; generous component padding |
| 05 |
Button Hierarchy |
Competing CTAs of equal visual weight |
Primary (Solid), Secondary (Ghost/Outline), Tertiary (Link/Minimal) |
| 06 |
Visual Clutter |
Border soup, redundant labels, noisy boxes |
Surface contrast, directional spacing, removing self-evident labels |
| 07 |
Empty States |
Blank, lifeless screens that confuse users |
Action-oriented onboarding, illustrative placeholder, direct CTA |
| 08 |
Shadows & Depth |
Flat cards, muddy dropshadows |
Layered 2-part shadows; shadows = depth, borders = structure |
| 09 |
Color Contrast |
Low-contrast text failing accessibility |
WCAG 2.2 AA (≥ 4.5:1 text, ≥ 3:1 UI/large) — blocking gate |
| 10 |
Grouping & Proximity |
Related items drifting apart |
Inter-group gap ≥ 2× intra-group; space before surfaces before lines |
| 11 |
Anti-Slop 5-State Gate |
Happy-path only components break in prod |
Explicit Empty, Loading, Error, Success, and Overflow state handling |
v1.1.0 additions (details in references/modern-techniques.md)
Concentric radius law (inner = outer − padding) · optical alignment & icon-stroke
matching · container-aware responsive doctrine (components adapt to their container;
logical properties; safe areas) · modern typography mechanics (60–75ch measure,
line-height by role, size-specific tracking, tabular-nums, 16px mobile inputs) ·
named z-scale tokens (no raw 9999) · surface ladder via lightness steps in dark
mode · theme parity (verify light AND dark) · static-cue rule (motion routes to
animate).
Procedure
The 5-step sequence below is the improve mode. Every other mode has its own
scoped procedure in references/modes.md — load only the mode you're running.
┌─────────────────┐ ┌─────────────────────┐ ┌──────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
│ 1. Triage & │ ──▶ │ 2. Structural & │ ──▶ │ 3. Polish & │ ──▶ │ 4. Verification & │ ──▶ │ 5. Anti-Slop │
│ Hierarchy │ │ Spacing System │ │ Visual Weight │ │ Contrast Oracle │ │ 5-State Coverage │
└─────────────────┘ └─────────────────────┘ └──────────────────┘ └─────────────────────┘ └─────────────────────┘
Step 1 — Element Inventory & Hierarchy Triage
- Identify the Single Primary Focal Point: the one action or data point that matters most in this viewport section.
- Assign Tiers (1 to 3): Tier 1 (key metric, main CTA, primary header) · Tier 2 (supporting text, inputs, table rows) · Tier 3 (timestamps, labels, breadcrumbs, hints).
- Execute De-emphasis: tone down all Tier 3 elements before increasing the size of Tier 1.
Step 2 — Spatial Grid & Whitespace Architecture
- Strip Border Soup: delete interior 1px borders dividing cards, rows, sidebar items.
- Establish Proximity: label↔input
gap-1.5 (4–6px) · between fields gap-4 (16px) · between sections gap-8–gap-12 (32–48px). Enforce the 2× grouping ratio.
- Increase Breathing Room: cramped container → double inner padding (
p-3 → p-6).
Step 3 — Typography, Color & Elevation Systematization
- Apply the stepped type scale (page titles
text-2xl–text-3xl bold/track-tight · section headers text-lg–text-xl semibold · body text-sm–text-base relaxed · metadata text-xs muted). Add the modern mechanics: measure cap, line-height by role, size-specific tracking.
- Standardize color tokens (
text-foreground → text-muted-foreground → /70); accent reserved for actionable targets.
- Natural elevation: layered 2-part shadows, background surface shifts; concentric radius on nested elements; named z-scale.
Step 4 — Verification & Contrast Oracle
- Run the mechanical receipts:
bun refactor-ui/scripts/audit-ui.ts <paths> then bun refactor-ui/scripts/check-contrast.ts <fg> <bg> for every rendered text pair (normal + large). Paste outputs.
- Verify WCAG 2.2 AA (≥4.5:1 normal text, ≥3:1 large text/UI components). A failure blocks completion.
- Theme parity: re-check the surface in light AND dark.
Step 5 — The 5-State Anti-Slop Coverage Gate
- Empty: dataset empty → soft icon, explanation, direct CTA.
- Loading: pulse skeleton matching geometry (
animate-pulse bg-muted) to kill CLS.
- Error: inline non-blocking banner with human diagnosis + Retry.
- Success: immediate confirmation (toast, badge, transient check).
- Overflow:
min-w-0 on flex items, truncate + title, line-clamp-2/3, responsive wrapping.
Pitfalls
- Happy-Path Blindness: shipping against mock data that is always present, short, and error-free.
- Invisible Focus Rings:
outline-none without a focus-visible:ring-2 alternative — keyboard navigation must stay visible.
- Mismatched Nested Radii: the most common "feels off" cause — apply the concentric law.
- Viewport-Breakpoint Reflex: reaching for
md: when the component should adapt to its container.
- Raw z-Index Values:
z-[9999] leaks stacking across surfaces; use the named scale.
- Relying Exclusively on Font Size for Hierarchy: weight and muted color create contrast without size bloat.
- Centering Everything: left-align text by default; centered body copy reads amateur.
- Pure Black on Pure White: harsh optical vibration — use deep slate/zinc neutrals.
- Icons Without Optical Balance: size icons down 1 step and match stroke to text weight.
- Burying Actions in Low-Contrast Grays: never fail WCAG AA for aesthetics.
- Smuggled Redesigns: polish mode refines; it never conceals a redesign — say "recommend redesign" instead.
- Unsupported Findings: search hits are candidates; without Contract + Runtime + Correction proof, discard them.
Verification
Before signing off any mode:
📚 Disclosed Reference Guides
Mode contracts and the research additions live in references/ — load only
what the running mode needs:
- modes.md — router table, per-mode procedures, report format, cross-skill routing.
- modern-techniques.md — v1.1.0 corpus-derived rules composing with the heuristics.
- 01-visual-hierarchy.md — Sizing, optical weight, and focal points.
- 02-typography-scale.md — Modular type scales and line-height ratios.
- 03-color-palette.md — Neutrals, primary brand, and semantic state hues.
- 04-spacing-layout.md — 4px/8px spatial rhythm and component layouts.
- 05-button-hierarchy.md — Primary, secondary, tertiary, and destructive button patterns.
- 06-visual-clutter.md — Eliminating border soup, redundant labels, and visual noise.
- 07-empty-states.md — High-value empty states, onboarding patterns, and action CTAs.
- 08-shadows-elevation.md — Directional lighting, layered shadows, and elevation systems.
- 09-contrast-accessibility.md — WCAG contrast formulas and accessible color pairing.
- 10-grouping-alignment.md — Gestalt proximity, alignment grids, and optical balancing.
- 11-five-state-anti-slop.md — Mandatory 5-state lifecycle coverage and anti-slop patterns.
📜 Attribution & Licensing
- Original Principles & Methodology: Derived from the landmark design book Refactoring UI by Adam Wathan and Steve Schoger (© Tailwind Labs Inc.). All conceptual design principles belong to the original authors.
- v1.1.0 Modern-techniques layer: Clean-room synthesis from public agent-skill corpus research (container queries, WCAG 2.2, theming, z-scale discipline); independent formulation, no source text reproduced.
- Skill Formulation & Architecture: Engineered by Harsh Singh for the Muse Skills open-source ecosystem.
- Inspiration: Acknowledgment to George Nurijanian (
gnurio/refactoring-ui-plugin) for the initial concept of packaging Refactoring UI rules for agent runtimes.
- License: MIT License. Compatible with all autonomous agent runtimes.
1---2name: refactor-ui3description: Audit, polish, and refactor user interfaces using the 10 atomic design heuristics from Refactoring UI plus modern container-query, typography, and theming techniques. Six quick modes: review (default verdict with severity table), audit (scripted anti-pattern + WCAG 2.2 AA scan with scored report), improve (5-step refactor), sweep (multi-page consistency matrix), tokens (extract-and-centralize, pixels don't move), and polish (launch readiness with drift triage). Ships zero-dependency Bun scripts: audit-ui.ts anti-pattern scanner and check-contrast.ts WCAG contrast checker. Trigger on 'review this UI', 'audit UI contrast and spacing', 'refactor this component', 'make this dashboard consistent', 'extract design tokens', 'final polish before launch', or whenever reviewing frontend templates, JSX, CSS, or Tailwind layouts.4license: MIT5---67# 🪄 refactor-ui — Atomic UI Design & Interface Refactoring Engine89Systematically evaluate, refine, and refactor user interfaces using the 10 atomic10heuristics of Wathan & Schoger's *Refactoring UI*, extended with modern techniques11(container queries, WCAG 2.2, theming parity, z-scale discipline) distilled from a12127-source corpus of production UI skills. Design treated as deterministic,13engineering-grade visual decisions — routed through six execution modes so the14agent loads only what the task needs.1516---1718## When to Use1920**Triggers** (mode chosen by phrase, default `review`):21- *"Review this UI / screen / component"* — verdict + severity table, no edits.22- *"Audit this UI for contrast, spacing, anti-patterns"* — scripted scan + scored report.23- *"Refactor this UI / make it look professional / improve this design"* — the 5-step refactor.24- *"Make all pages consistent / refactor the whole dashboard"* — multi-page sweep.25- *"Extract design tokens / too many grays / set up a type scale"* — rename-and-centralize.26- *"Final pass before launch / ship-readiness"* — polish triage.2728**Anti-triggers:**29- Extracting tokens from a live URL or screenshot without refactoring existing code — use [`designscope`](../designscope/SKILL.md).30- Motion choreography, easings, entrance/exit sequences — use the `animate` skill (this skill owns only the static-cue rule).31- Backend logic, state architecture, or novel branding/illustration from scratch.3233---3435## Quick Reference3637### Mode router (full contracts in `references/modes.md`)3839| Mode | Scope | Writes | Blocking gate |40|:---|:---|:---|:---|41| **review** (default) | One component; verdict | Nothing | — |42| **audit** | One surface; scripted + heuristic scan | `.agents/artifacts/ui-audit-report-<ts>.md` | WCAG 2.2 AA failure = Block |43| **improve** | One surface; 5-step refactor | Component code | 5-state + contrast gates |44| **sweep** | Multi-page system | Code + `sweep-matrix-<ts>.md` | Consistency matrix |45| **tokens** | Styling layer | Token defs + call sites | Zero literals remain |46| **polish** | Whole path, all states | Narrow fixes | Zero P1 drift |4748### The Atomic Heuristics4950| # | Heuristic Domain | Core Problem Solved | Primary Tool / Technique |51| :--- | :--- | :--- | :--- |52| **01** | **Visual Hierarchy** | Everything competing for attention | Primary focal point + aggressive de-emphasis of secondary elements |53| **02** | **Typography Scale** | Inconsistent, uncalibrated font sizes | 6-tier scale with proportional line-heights and optical font weights |54| **03** | **Color Palette** | Garish, saturated, or arbitrary colors | 9-step neutrals + primary brand hue + functional status semantics |55| **04** | **Spacing Grid** | Arbitrary margins and cramped layouts | Fixed 4px/8px spacing ramp; generous component padding |56| **05** | **Button Hierarchy** | Competing CTAs of equal visual weight | Primary (Solid), Secondary (Ghost/Outline), Tertiary (Link/Minimal) |57| **06** | **Visual Clutter** | Border soup, redundant labels, noisy boxes | Surface contrast, directional spacing, removing self-evident labels |58| **07** | **Empty States** | Blank, lifeless screens that confuse users | Action-oriented onboarding, illustrative placeholder, direct CTA |59| **08** | **Shadows & Depth** | Flat cards, muddy dropshadows | Layered 2-part shadows; shadows = depth, borders = structure |60| **09** | **Color Contrast** | Low-contrast text failing accessibility | WCAG 2.2 AA (≥ 4.5:1 text, ≥ 3:1 UI/large) — blocking gate |61| **10** | **Grouping & Proximity** | Related items drifting apart | Inter-group gap ≥ 2× intra-group; space before surfaces before lines |62| **11** | **Anti-Slop 5-State Gate** | Happy-path only components break in prod | Explicit Empty, Loading, Error, Success, and Overflow state handling |6364### v1.1.0 additions (details in `references/modern-techniques.md`)6566Concentric radius law (`inner = outer − padding`) · optical alignment & icon-stroke67matching · container-aware responsive doctrine (components adapt to their container;68logical properties; safe areas) · modern typography mechanics (60–75ch measure,69line-height by role, size-specific tracking, tabular-nums, 16px mobile inputs) ·70named z-scale tokens (no raw 9999) · surface ladder via lightness steps in dark71mode · theme parity (verify light AND dark) · static-cue rule (motion routes to72`animate`).7374---7576## Procedure7778The 5-step sequence below is the **improve** mode. Every other mode has its own79scoped procedure in `references/modes.md` — load only the mode you're running.8081```82┌─────────────────┐ ┌─────────────────────┐ ┌──────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐83│ 1. Triage & │ ──▶ │ 2. Structural & │ ──▶ │ 3. Polish & │ ──▶ │ 4. Verification & │ ──▶ │ 5. Anti-Slop │84│ Hierarchy │ │ Spacing System │ │ Visual Weight │ │ Contrast Oracle │ │ 5-State Coverage │85└─────────────────┘ └─────────────────────┘ └──────────────────┘ └─────────────────────┘ └─────────────────────┘86```8788### Step 1 — Element Inventory & Hierarchy Triage891. **Identify the Single Primary Focal Point**: the one action or data point that matters most in this viewport section.902. **Assign Tiers (1 to 3)**: Tier 1 (key metric, main CTA, primary header) · Tier 2 (supporting text, inputs, table rows) · Tier 3 (timestamps, labels, breadcrumbs, hints).913. **Execute De-emphasis**: tone down all Tier 3 elements before increasing the size of Tier 1.9293### Step 2 — Spatial Grid & Whitespace Architecture941. **Strip Border Soup**: delete interior 1px borders dividing cards, rows, sidebar items.952. **Establish Proximity**: label↔input `gap-1.5` (4–6px) · between fields `gap-4` (16px) · between sections `gap-8`–`gap-12` (32–48px). Enforce the 2× grouping ratio.963. **Increase Breathing Room**: cramped container → double inner padding (`p-3` → `p-6`).9798### Step 3 — Typography, Color & Elevation Systematization991. **Apply the stepped type scale** (page titles `text-2xl`–`text-3xl` bold/track-tight · section headers `text-lg`–`text-xl` semibold · body `text-sm`–`text-base` relaxed · metadata `text-xs` muted). Add the modern mechanics: measure cap, line-height by role, size-specific tracking.1002. **Standardize color tokens** (`text-foreground` → `text-muted-foreground` → `/70`); accent reserved for actionable targets.1013. **Natural elevation**: layered 2-part shadows, background surface shifts; concentric radius on nested elements; named z-scale.102103### Step 4 — Verification & Contrast Oracle1041. Run the mechanical receipts: `bun refactor-ui/scripts/audit-ui.ts <paths>` then `bun refactor-ui/scripts/check-contrast.ts <fg> <bg>` for every rendered text pair (normal + large). Paste outputs.1052. Verify WCAG 2.2 AA (≥4.5:1 normal text, ≥3:1 large text/UI components). A failure blocks completion.1063. Theme parity: re-check the surface in light AND dark.107108### Step 5 — The 5-State Anti-Slop Coverage Gate1091. **Empty**: dataset empty → soft icon, explanation, direct CTA.1102. **Loading**: pulse skeleton matching geometry (`animate-pulse bg-muted`) to kill CLS.1113. **Error**: inline non-blocking banner with human diagnosis + Retry.1124. **Success**: immediate confirmation (toast, badge, transient check).1135. **Overflow**: `min-w-0` on flex items, `truncate` + `title`, `line-clamp-2/3`, responsive wrapping.114115---116117## Pitfalls118119- **Happy-Path Blindness**: shipping against mock data that is always present, short, and error-free.120- **Invisible Focus Rings**: `outline-none` without a `focus-visible:ring-2` alternative — keyboard navigation must stay visible.121- **Mismatched Nested Radii**: the most common "feels off" cause — apply the concentric law.122- **Viewport-Breakpoint Reflex**: reaching for `md:` when the component should adapt to its container.123- **Raw z-Index Values**: `z-[9999]` leaks stacking across surfaces; use the named scale.124- **Relying Exclusively on Font Size for Hierarchy**: weight and muted color create contrast without size bloat.125- **Centering Everything**: left-align text by default; centered body copy reads amateur.126- **Pure Black on Pure White**: harsh optical vibration — use deep slate/zinc neutrals.127- **Icons Without Optical Balance**: size icons down 1 step and match stroke to text weight.128- **Burying Actions in Low-Contrast Grays**: never fail WCAG AA for aesthetics.129- **Smuggled Redesigns**: polish mode refines; it never conceals a redesign — say "recommend redesign" instead.130- **Unsupported Findings**: search hits are candidates; without Contract + Runtime + Correction proof, discard them.131132---133134## Verification135136Before signing off any mode:137138- [ ] **Mode contract honored**: only the mode's reads/writes performed.139- [ ] **Script receipts pasted**: `audit-ui.ts` and `check-contrast.ts` outputs included when audit/improve ran.140- [ ] **WCAG 2.2 AA**: all rendered text/UI pairs pass — blocking gate.141- [ ] **5-State Anti-Slop Coverage**: Empty, Loading, Error, Success, Overflow implemented and verified.142- [ ] **Theme parity**: surface verified in light and dark mode.143- [ ] **Responsive proof**: container/smallest/largest checks (or `Not verified` declared).144- [ ] **Visible Focus Rings**: all interactive controls have `focus-visible` states.145- [ ] **Squint Test Passed**: primary action unmistakable when blurred.146- [ ] **Zero Arbitrary Values**: spacing/sizes map 1:1 to scale tokens.147- [ ] **Single Primary Action** per section; proximity law upheld; no border overload.148- [ ] **Honest verdict**: Block if any HIGH or AA failure remains; unrun checks listed as `Not verified`.149150---151152## 📚 Disclosed Reference Guides153154Mode contracts and the research additions live in `references/` — load only155what the running mode needs:156157- [modes.md](references/modes.md) — router table, per-mode procedures, report format, cross-skill routing.158- [modern-techniques.md](references/modern-techniques.md) — v1.1.0 corpus-derived rules composing with the heuristics.159- [01-visual-hierarchy.md](references/01-visual-hierarchy.md) — Sizing, optical weight, and focal points.160- [02-typography-scale.md](references/02-typography-scale.md) — Modular type scales and line-height ratios.161- [03-color-palette.md](references/03-color-palette.md) — Neutrals, primary brand, and semantic state hues.162- [04-spacing-layout.md](references/04-spacing-layout.md) — 4px/8px spatial rhythm and component layouts.163- [05-button-hierarchy.md](references/05-button-hierarchy.md) — Primary, secondary, tertiary, and destructive button patterns.164- [06-visual-clutter.md](references/06-visual-clutter.md) — Eliminating border soup, redundant labels, and visual noise.165- [07-empty-states.md](references/07-empty-states.md) — High-value empty states, onboarding patterns, and action CTAs.166- [08-shadows-elevation.md](references/08-shadows-elevation.md) — Directional lighting, layered shadows, and elevation systems.167- [09-contrast-accessibility.md](references/09-contrast-accessibility.md) — WCAG contrast formulas and accessible color pairing.168- [10-grouping-alignment.md](references/10-grouping-alignment.md) — Gestalt proximity, alignment grids, and optical balancing.169- [11-five-state-anti-slop.md](references/11-five-state-anti-slop.md) — Mandatory 5-state lifecycle coverage and anti-slop patterns.170171---172173## 📜 Attribution & Licensing174175- **Original Principles & Methodology**: Derived from the landmark design book [*Refactoring UI*](https://refactoringui.com/) by **Adam Wathan** and **Steve Schoger** (© Tailwind Labs Inc.). All conceptual design principles belong to the original authors.176- **v1.1.0 Modern-techniques layer**: Clean-room synthesis from public agent-skill corpus research (container queries, WCAG 2.2, theming, z-scale discipline); independent formulation, no source text reproduced.177- **Skill Formulation & Architecture**: Engineered by **Harsh Singh** for the **Muse Skills** open-source ecosystem.178- **Inspiration**: Acknowledgment to **George Nurijanian** (`gnurio/refactoring-ui-plugin`) for the initial concept of packaging Refactoring UI rules for agent runtimes.179- **License**: MIT License. Compatible with all autonomous agent runtimes.