| name | ui |
| description | UI component architecture. Design systems, Storybook, CSS architecture, design tokens, component patterns.
|
UI -- UI Component Architecture
Activate When
/godmode:ui, "component architecture"
- "design system", "UI review", "Storybook setup"
- Building reusable components or shared UI packages
Workflow
Step 1: Analyze Current Architecture
grep -r "react\|vue\|svelte\|@angular/core" \
package.json 2>/dev/null
grep -r "tailwindcss\|styled-components\|@emotion\|sass" \
package.json 2>/dev/null
find src/ -name "*.tsx" -o -name "*.vue" \
-o -name "*.svelte" 2>/dev/null | wc -l
UI AUDIT:
Framework: <React | Vue | Svelte | Angular>
Styling: <CSS Modules | Tailwind | CSS-in-JS>
Component library: <custom | MUI | shadcn | none>
Storybook: <yes (version) | no>
Design tokens: <yes | no>
Component count: <N>
Step 2: Component Hierarchy
| Level | Count | Examples |
|----------|-------|----------------------|
| Atoms | <N> | Button, Input, Label |
| Molecules| <N> | FormField, SearchBar |
| Organisms| <N> | Header, DataTable |
| Templates| <N> | DashboardLayout |
| Pages | <N> | HomePage, Settings |
Step 3: CSS Architecture Decision
IF existing design system with tokens:
CSS Modules + CSS custom properties
IF rapid prototyping or small team:
Tailwind CSS
IF complex theming (dark, multi-brand):
CSS-in-JS (Emotion/styled-components)
IF SSR is critical:
avoid runtime CSS-in-JS
IF legacy SCSS: keep, migrate incrementally
| Criterion | CSS Modules | Tailwind | CSS-in-JS |
|------------|------------|---------|----------|
| Scoping | Automatic | Utility | Automatic|
| Bundle | Small | Small | Variable |
| Runtime | None | None | Yes |
| Type safety| Plugin | Plugin | Native |
Step 4: Design Token Audit
grep -rn "#[0-9a-fA-F]\{3,6\}" src/ \
--include="*.css" --include="*.tsx" \
--include="*.scss" 2>/dev/null | head -20
grep -rn "margin:\|padding:\|gap:" src/ \
--include="*.css" --include="*.scss" \
| grep -v "var(--" | head -20
| Token Category | Defined | Hardcoded | Violations |
|---------------|---------|-----------|-----------|
| Colors | 24 | 7 | 7 |
| Typography | 8 | 3 | 3 |
| Spacing | 12 | 5 | 5 |
| Border radius | 4 | 1 | 1 |
| Shadows | 3 | 2 | 2 |
Step 5: Component Library Structure
src/components/Button/
Button.tsx Component
Button.module.css Styles
Button.test.tsx Tests
Button.stories.tsx Storybook
Button.types.ts TypeScript interfaces
index.ts Public exports
Step 6: Storybook Setup
npx storybook@latest init
npm install --save-dev @storybook/addon-a11y \
@storybook/addon-viewport @storybook/addon-docs
Step 7: Pattern Consistency
NAMING RULES:
Components: PascalCase (Button, DataTable)
Files: PascalCase matching component
Styles: ComponentName.module.css
Tests: ComponentName.test.tsx
Hooks: use<Purpose> (useMediaQuery)
API CONVENTIONS:
variant for visual styles (not "type")
size: "small" | "medium" | "large"
children for content (not "text")
on<Event> for handlers (onClick)
Boolean props positive (isOpen, not isClosed)
forwardRef on all native-wrapping components
Step 8: Report
UI REPORT:
Components: {N} total
Well-structured: {N}, Needs work: {N}
Token violations: {N} hardcoded values
Stories coverage: {N}/{N} components
Verdict: PASS | NEEDS REVISION
Key Behaviors
- Components are the unit of UI.
- Design tokens are mandatory. No hardcoding.
- Every component needs stories.
- Consistency over cleverness.
- Never ask to continue. Loop autonomously.
Quality Targets
- Lighthouse score: >90 performance
- Interaction-to-paint: <100ms latency
- Cumulative Layout Shift: <1 score threshold
HARD RULES
- NEVER mix CSS approaches in one project.
- NEVER create God components (>30 props, >500 lines).
- NEVER hardcode colors or spacing. Use tokens.
- NEVER couple UI to business logic.
- ALWAYS type every component prop.
- ALWAYS write Storybook stories for every component.
- ALWAYS design mobile-first.
- NEVER use inline styles for component internals.
Auto-Detection
grep -r "storybook" package.json 2>/dev/null
ls .storybook/ 2>/dev/null
find src/ -name "*.stories.*" 2>/dev/null | wc -l
TSV Logging
Log to .godmode/ui-results.tsv:
timestamp\tcomponent\taction\ttests\ta11y\tbundle_kb\tstatus
Output Format
UI: Components {N}. Stories: {N}. Tokens: {N}.
Violations: {N}. a11y: {N}. Status: {DONE|PARTIAL}.
Keep/Discard Discipline
KEEP if: visual regression passes AND a11y clean
AND responsive at all breakpoints
DISCARD if: visual regression OR a11y violation
OR layout breaks. Revert on discard.
Stop Conditions
STOP when:
- All components render in Storybook
- Design token coverage >= 95%
- Zero a11y violations (axe-core)
- User requests stop