Architecture Overview
UX Master v4 Pipeline
INPUT
PROCESSING
OUTPUT
🌐
Website URL
Input target for extraction
↓
🔍
Browser Crawler
Headless Chromium, visual stability wait
↓
🤖
AI Extractor (harvester_v4.js)
Color histograms, typography, layout grids
↓
🏗️
Semi Design Mapper
150+ CSS variables, 7-state color variants
↓
⚛️
Component Generator
React/Vue/Semi/shadcn code
↓
📦 Outputs
- 📄 design-system.css (150+ CSS variables)
- 📄 design-system.json (Structured tokens)
- 📄 figma-tokens.json (Tokens Studio format)
- 📄 DESIGN.md (Stitch-compatible)
- 📁 components/ (React/Vue/Semi/shadcn)
Stage 1: Browser Extraction
What Happens
Python
class HarvesterBrowser:
async def extract(self, url: str) -> HarvestResult:
"""
1. Launch headless Chromium
2. Navigate to URL
3. Wait for visual stability
4. Inject harvester_v4.js
5. Execute AI extraction
6. Capture screenshot
7. Return structured data
"""
Key Features
| Feature | Implementation | Purpose |
|---|---|---|
| Headless Browser | Playwright Chromium | Accurate rendering |
| Visual Stability | wait_seconds parameter | Let animations finish |
| Mobile Detection | Viewport emulation | Responsive design analysis |
| Error Resilience | Try/catch in browser | Handle broken sites |
Stage 2: AI Extraction
Core Algorithm
JavaScript
class HarvesterV4 {
extract(options) {
return {
// Visual Analysis
colors: this.extractColors(),
typography: this.extractTypography(),
spacing: this.extractSpacing(),
components: this.extractComponents(),
// Structural
layout: this.analyzeLayout(),
pageType: this.detectPageType(),
// Metadata
_version: 4,
_timestamp: Date.now()
};
}
}
Color Extraction
JavaScript
extractColors() {
const elements = document.querySelectorAll('*');
const frequency = new Map();
// Collect all colors
elements.forEach(el => {
const style = window.getComputedStyle(el);
const bg = style.backgroundColor;
const text = style.color;
const border = style.borderColor;
[bg, text, border].forEach(color => {
if (color && color !== 'transparent') {
frequency.set(color, (frequency.get(color) || 0) + 1);
}
});
});
// Sort by frequency
const sorted = [...frequency.entries()]
.sort((a, b) => b[1] - a[1]);
return {
histogram: { background, text, border },
dominant: this.extractDominant(sorted)
};
}
Component Detection
JavaScript
extractComponents() {
const blueprints = [];
// Button detection
document.querySelectorAll('button, [role="button"]')
.forEach(el => blueprints.push(this.analyzeButton(el)));
// Input detection
document.querySelectorAll('input, textarea, select')
.forEach(el => blueprints.push(this.analyzeInput(el)));
// Card detection
document.querySelectorAll('.card, [class*="card"]')
.forEach(el => blueprints.push(this.analyzeCard(el)));
return { blueprints, count: blueprints.length };
}
Stage 3: Semi Design Mapper
The mapper converts raw harvest data to standardized Semi Design tokens:
- Color System: Primary, Secondary, Tertiary, Neutrals (50-900)
- Background Scale: bg-0 → bg-4
- Fill States: fill-0 → fill-2
- Text Hierarchy: text-0 → text-3
- Spacing System: none → super-loose (10 steps)
- Border Radius: xs → full
- Shadow System: sm → elevated → lg
Stage 4: Component Generator
Generates production-ready components from blueprints:
Supported Frameworks
- React + Tailwind
- Vue 3 + Tailwind
- Semi Design (DouyinFE)
- shadcn/ui
Generated Components
- Button (primary, secondary, outline, ghost, danger)
- Card (default, bordered, elevated)
- Input (text, password, textarea, select)
- Badge/Tag (default, success, warning, danger, info)
- Avatar (circle, square, sizes)
- Alert (info, success, warning, error)
🔬 Tìm hiểu thêm
Khám phá API reference và bắt đầu sử dụng Harvester v4.