Spaces:
Runtime error
Runtime error
File size: 6,435 Bytes
abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 d041f14 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 abab3e7 d69ae21 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | ---
title: Design System Automation
emoji: π¨
colorFrom: purple
colorTo: blue
sdk: docker
pinned: false
license: mit
---
# Design System Automation
> Extract, analyze, and improve any website's design system β then drop it into Figma as a visual spec. In 15 minutes, not 5 days.
   
## What It Does
Point it at any live website. The system:
1. **Extracts** every design token (colors, typography, spacing, shadows, radius) from 8 sources
2. **Classifies** colors deterministically using CSS evidence (815 lines, no AI)
3. **Audits** accessibility (WCAG AA/AAA), type scale consistency, spacing grid alignment
4. **Analyzes** with 4 specialized AI agents β brand identification, industry benchmarking, best practices, synthesis
5. **Exports** W3C DTCG-compliant JSON
6. **Generates** a full Figma visual spec via custom plugin
**Cost:** ~$0.003 per analysis. The free rule-based layers do 90% of the work.
## Architecture: Three Layers
```
Layer 1 β Extraction + Normalization (Free, ~90s)
Playwright visits site at 2 viewports, extracts from 8 CSS sources
Normalizer: dedup colors, parse radius/shadows, name with numeric shades
Layer 2 β Classification + Rule Engine (Free, <1s)
Color Classifier: CSS evidence -> category -> token name (deterministic)
Rule Engine: WCAG contrast, type scale ratio, spacing grid, color stats
Layer 3 β 4 AI Agents (~$0.003)
AURORA: Brand color advisor (Qwen 72B)
ATLAS: Industry benchmark advisor (Llama 3.3 70B)
SENTINEL: Best practices auditor (Qwen 72B)
NEXUS: Head synthesizer (Llama 3.3 70B)
```
AI agents are **advisory only** β a strict naming authority chain ensures deterministic, reproducible output:
1. Color Classifier (primary) β 2. AURORA LLM (secondary, semantic roles only) β 3. Normalizer (fallback)
## Quick Start
### Run the App
```bash
git clone https://github.com/hiriazmo/design-system-automation.git
cd design-system-automation
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
playwright install chromium
cp config/.env.example config/.env
# Add your HF_TOKEN in .env
python app.py
```
Open `http://localhost:7860`
### Or Use the Hosted Version
**[Live Demo on HuggingFace Spaces](https://huggingface.co/spaces/riazmo/Design-System-Automation)**
### Import to Figma
1. Extract tokens from any website using the app
2. Download the DTCG JSON
3. Load the [Figma plugin](./figma-plugin/) into Figma
4. Upload JSON β get Variables, Styles, and a Visual Spec page
See the [Figma Plugin README](./figma-plugin/README.md) for setup instructions.
## The Workflow
```
Enter URL β Extract AS-IS β Download JSON β Import to Figma (Visual Spec)
β
Review AS-IS spec
β
Run AI Analysis β Accept/Reject suggestions
β
Export TO-BE JSON β Import to Figma
β
Compare AS-IS vs TO-BE side by side
```
## Output Format (W3C DTCG v1)
```json
{
"color": {
"brand": {
"primary": {
"$type": "color",
"$value": "#005aa3",
"$description": "[classifier] brand: primary_action",
"$extensions": {
"com.design-system-automation": {
"frequency": 47,
"confidence": "high",
"category": "brand"
}
}
}
}
},
"radius": {
"md": { "$type": "dimension", "$value": "8px" }
},
"shadow": {
"sm": {
"$type": "shadow",
"$value": {
"offsetX": "0px",
"offsetY": "2px",
"blur": "8px",
"spread": "0px",
"color": "#00000026"
}
}
}
}
```
Compatible with Tokens Studio, Style Dictionary v4, and any DTCG-compliant tool.
## Project Structure
```
design-system-automation/
βββ app.py # Main Gradio application (~5000 lines)
βββ figma-plugin/ # Figma plugin for token import + visual spec
β βββ manifest.json
β βββ src/code.js # Plugin logic (v7)
β βββ ui/ui.html # Plugin UI
βββ agents/
β βββ crawler.py # Page discovery
β βββ extractor.py # 8-source CSS extraction (Playwright)
β βββ firecrawl_extractor.py # Deep CSS extraction (Firecrawl)
β βββ normalizer.py # Token dedup, naming, normalization
β βββ llm_agents.py # AURORA, ATLAS, SENTINEL, NEXUS
β βββ ...
βββ core/
β βββ color_classifier.py # Deterministic color classification (815 lines)
β βββ rule_engine.py # WCAG, type scale, spacing grid analysis
β βββ color_utils.py # Color math, contrast, ramp generation
β βββ token_schema.py # Pydantic models (DTCG compliant)
β βββ ...
βββ config/
β βββ .env.example # Environment template
β βββ settings.py # Configuration
β βββ agents.yaml # Agent configurations
βββ tests/ # 148 tests (82 deterministic + 27 agent + 35 live + 4 pipeline)
βββ docs/ # Medium article, LinkedIn post, image guide
```
## Tech Stack
| Component | Technology |
|-----------|-----------|
| UI | Gradio |
| Extraction | Playwright + Firecrawl |
| Classification | Custom rule-based (Python) |
| AI Agents | Qwen 72B + Llama 3.3 70B via HuggingFace Inference API |
| Hosting | HuggingFace Spaces (Docker) |
| Figma | Custom plugin (Variables API + Styles API) |
| Token Format | W3C DTCG v1 (October 2025) |
| Tests | pytest β 148 passing |
## Tests
```bash
python -m pytest tests/ -q
```
## License
MIT
---
Built by [Riaz](https://medium.com/@designwithriaz) β a UX Design Manager automating design systems with AI.
|