-
Notifications
You must be signed in to change notification settings - Fork 59
Styling DNA
lets # Styling DNA
Drift's Styling DNA feature analyzes how your codebase implements patterns for both frontend styling (variants, responsive design, theming, spacing, animations) and backend conventions (API responses, error handling, logging, configuration).
Styling DNA creates a "genetic profile" of your codebase's patterns. This helps AI agents generate code that matches your existing conventions exactly.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STYLING DNA PROFILE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β FRONTEND GENES β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Variants β β Responsive β β Theming β β
β β β β β β β β
β β How you β β Breakpoints β β Dark mode β β
β β handle β β and media β β CSS vars β β
β β size/color β β queries β β tokens β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Spacing β β Animation β β State β β
β β β β β β β β
β β Margin/pad β β Transitions β β Hover/focus β β
β β scale β β keyframes β β active β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β
β BACKEND GENES β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β API Response β β Error Format β β Logging β β
β β β β β β β β
β β Envelope vs β β Problem β β Structured β β
β β direct β β details β β JSON β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Styling DNA analyzes ten "genes" that define your codebase's patterns - six for frontend and four for backend:
How you implement component variants (size, color, state).
| Pattern | Description | Example |
|---|---|---|
| Props-based | Variants via props | <Button size="lg" variant="primary"> |
| Class-based | Utility classes | className="btn btn-lg btn-primary" |
| CVA | Class Variance Authority | const button = cva("btn", { variants: {...} }) |
| Styled-components | CSS-in-JS variants |
${props => props.size === 'lg' && css...}
|
How you handle different screen sizes.
| Pattern | Description | Example |
|---|---|---|
| Mobile-first | Start small, add breakpoints | @media (min-width: 768px) |
| Desktop-first | Start large, subtract | @media (max-width: 768px) |
| Container queries | Component-based | @container (min-width: 400px) |
| Tailwind responsive | Utility prefixes | md:flex lg:grid |
How you style interactive states.
| Pattern | Description | Example |
|---|---|---|
| Pseudo-classes | CSS selectors |
:hover, :focus, :active
|
| Data attributes | State via data-* | [data-state="active"] |
| ARIA attributes | Accessibility-first | [aria-selected="true"] |
| Class toggling | JavaScript-driven | classList.add('is-active') |
How you implement themes and dark mode.
| Pattern | Description | Example |
|---|---|---|
| CSS Variables | Custom properties | var(--color-primary) |
| Class-based | Theme class on root | .dark .bg-white { ... } |
| Media query | System preference | @media (prefers-color-scheme: dark) |
| Context/Provider | React context | <ThemeProvider theme={darkTheme}> |
How you handle margins, padding, and gaps.
| Pattern | Description | Example |
|---|---|---|
| Scale-based | Consistent scale | 4px, 8px, 16px, 24px, 32px |
| Tailwind spacing | Utility classes | p-4 m-2 gap-6 |
| Design tokens | Named tokens |
--spacing-sm, --spacing-md
|
| Arbitrary | Ad-hoc values | margin: 13px |
How you implement animations and transitions.
| Pattern | Description | Example |
|---|---|---|
| CSS Transitions | Property transitions | transition: all 0.2s ease |
| Keyframes | Complex animations | @keyframes fadeIn { ... } |
| Framer Motion | React animation lib | <motion.div animate={{...}}> |
| CSS-in-JS | Styled animations | animation: ${fadeIn} 0.3s |
How you structure API responses.
| Pattern | Description | Example |
|---|---|---|
| Envelope | Wrapped response | { data: {...}, meta: {...} } |
| Direct | Raw data | { id: 1, name: "..." } |
| JSON:API | JSON:API spec | { data: {...}, included: [...] } |
| HAL | Hypermedia links | { _links: {...}, _embedded: {...} } |
How you structure error responses.
| Pattern | Description | Example |
|---|---|---|
| Problem Details | RFC 7807 | { type, title, status, detail } |
| Custom envelope | App-specific | { error: { code, message } } |
| Simple | Basic error | { message: "..." } |
How you structure log output.
| Pattern | Description | Example |
|---|---|---|
| Structured JSON | JSON logs | { level, message, timestamp, context } |
| Text | Plain text | [INFO] 2024-01-01 Message |
| Pino/Winston | Library-specific | Library default format |
How you manage configuration.
| Pattern | Description | Example |
|---|---|---|
| Environment | Env vars | process.env.DATABASE_URL |
| Config object | Centralized | config.database.url |
| Dotenv | .env files | dotenv.config() |
drift dna scanAnalyzes your codebase for frontend and backend styling/code patterns.
Options:
-
-p, --paths <paths...>β Specific frontend component paths to scan -
-b, --backend-paths <paths...>β Specific backend paths to scan -
-m, --mode <mode>β Analysis mode:frontend,backend, orall(default:all) -
--forceβ Force rescan even if cache is valid -
--verboseβ Enable verbose output -
--playbookβ Generate playbook after scan -
-f, --format <format>β Output format:summary,json, orai-context(default:summary)
drift dna statusShows your complete styling DNA profile with confidence scores.
Options:
-
-d, --detailedβ Show detailed gene breakdown -
--jsonβ Output as JSON
Example Output:
𧬠Drift DNA - Status
Summary
ββββββββββββββββββββββββββββββββββββββββββββββββββ
Health Score: 85/100
Genetic Diversity: 0.25
Framework: React
Components: 47
Files: 156
Last Updated: 1/27/2026, 10:30:00 AM
Genes
ββββββββββββββββββββββββββββββββββββββββββββββββββ
β Variant Handling props-based 92%
β Responsive Approach mobile-first 88%
β State Styling pseudo-classes 95%
β Theming css-variables 90%
β Spacing Philosophy tailwind-scale 85%
β Animation Approach css-transitions 78%
Mutations: 3
High: 0 Medium: 2 Low: 1
drift dna gene <gene-id>Shows detailed analysis for a specific gene.
Options:
-
-e, --examplesβ Show code examples -
-f, --filesβ List files for each allele
Example:
drift dna gene variant-handling --examplesdrift dna mutationsFinds places where styling deviates from established patterns.
Options:
-
-g, --gene <gene>β Filter by gene -
-i, --impact <level>β Filter by impact:low,medium, orhigh -
-s, --suggestβ Show resolution suggestions -
--jsonβ Output as JSON
Example Output:
𧬠Mutations (3)
High Impact (1)
ββββββββββββββββββββββββββββββββββββββββββββββββββ
src/components/Card.tsx:45
Gene: variant-handling
Found: inline-styles β Expected: props-based
Code: style={{ padding: '13px' }}...
π‘ Use variant prop pattern like Button.tsx
Medium Impact (2)
ββββββββββββββββββββββββββββββββββββββββββββββββββ
src/pages/Dashboard.tsx:123
Gene: spacing-philosophy
Found: arbitrary-value β Expected: tailwind-scale
Code: margin: 13px...
drift dna playbookGenerates a comprehensive style guide based on detected patterns.
Options:
-
-o, --output <path>β Output path (default:STYLING-PLAYBOOK.md) -
-e, --examplesβ Include code examples -
--forceβ Overwrite existing file -
--stdoutβ Output to stdout instead of file
drift dna exportExports the DNA profile for AI context or integration.
Options:
-
-f, --format <format>β Export format:ai-context,json,playbook, orsummary(default:ai-context) -
-g, --genes <genes...>β Specific genes to export -
-m, --mutationsβ Include mutations -
-c, --compactβ Compact output -
-l, --level <level>β AI context level 1-4 (default:3)
Get the complete styling DNA profile via MCP.
drift_dna_profile({
gene?: "variant-handling" | "responsive-approach" | "state-styling" |
"theming" | "spacing-philosophy" | "animation-approach"
})Parameters:
-
geneβ (optional) Specific gene to query. If omitted, returns the complete profile.
Response:
{
"profile": {
"variantHandling": {
"pattern": "props-based",
"confidence": 0.92,
"examples": ["Button.tsx:12", "Card.tsx:8"],
"details": {
"commonProps": ["size", "variant", "color"],
"componentCount": 47
}
},
"responsiveApproach": {
"pattern": "mobile-first",
"confidence": 0.88,
"breakpoints": ["640px", "768px", "1024px", "1280px"]
}
// ... other genes
},
"overallConfidence": 0.88,
"recommendations": [
"Consider standardizing animation durations",
"3 components use inconsistent spacing"
]
}Drift includes styling-specific detectors that feed into the DNA analysis:
| Detector | Description |
|---|---|
class-naming |
BEM, utility-first, or custom naming |
design-tokens |
Color, spacing, typography tokens |
responsive |
Breakpoint and media query patterns |
spacing-scale |
Consistent spacing usage |
typography |
Font family, size, weight patterns |
color-usage |
Color palette consistency |
z-index-scale |
Layering and stacking context |
tailwind-patterns |
Tailwind CSS utility usage |
These detectors analyze your code and contribute to the overall DNA profile.
When AI agents request context for UI work, Drift includes styling DNA:
// AI requests context for creating a button
drift_context({
intent: "add_feature",
focus: "button component"
})
// Response includes styling DNA
{
"patterns": [...],
"stylingDNA": {
"variantHandling": "props-based",
"responsiveApproach": "mobile-first",
"theming": "css-variables",
"spacing": "tailwind-scale"
},
"examples": [
{
"file": "src/components/Button.tsx",
"code": "export const Button = ({ size = 'md', variant = 'primary' }) => ..."
}
]
}This ensures generated UI code matches your existing patterns.
{
"dna": {
"enabled": true,
"genes": {
"variant-handling": { "enabled": true },
"responsive-approach": { "enabled": true },
"state-styling": { "enabled": true },
"theming": { "enabled": true },
"spacing-philosophy": { "enabled": true },
"animation-approach": { "enabled": true }
},
"excludePaths": [
"**/node_modules/**",
"**/vendor/**"
]
}
}# Generate style guide for new team members
drift dna playbook --output STYLE_GUIDE.md# Check PR for style consistency
drift dna mutations --staged# Identify components not following new patterns
drift dna mutations --verboseThe DNA profile is automatically included in AI context, ensuring generated code matches your styling approach.
- Pattern Categories β All 15 pattern categories
- Detectors Deep Dive β 400+ detectors explained
- Configuration β Project configuration options
- Cortex V2 Overview
- Memory Setup Wizard
- Memory CLI
- Universal Memory Types
- Learning System
- Token Efficiency
- Causal Graphs
- Code Generation
- Predictive Retrieval
- Architecture
- Call Graph Analysis
- Impact Analysis
- Security Analysis
- Data Boundaries
- Test Topology
- Coupling Analysis
- Error Handling Analysis
- Wrappers Detection
- Environment Variables
- Constants Analysis
- Styling DNA
- Constraints
- Contracts
- Decision Mining
- Speculative Execution
- Watch Mode
- Trends Analysis
- Projects Management
- Package Context
- Monorepo Support
- Reports & Export
- Dashboard
- 10 Languages
- 21 Frameworks
- 16 ORMs
- 400+ Detectors
- 50+ MCP Tools
- 60+ CLI Commands
- 23 Memory Types