Skip to main content

UFR Design System analyzer and generator (Emergence Engine–powered)

Project description

UFR Design System - Enhanced Technical Specification

CI PyPI npm (tokenizer)

Executive Summary

What We're Building

UFR-DS is a design grammar engine that analyzes existing React design systems (e.g., MUI, custom component libraries) to discover their underlying patterns, compress redundancies, and expose a shared grammar layer that designers and developers can work with together.

Unlike traditional code generation tools, UFR-DS is not about replacing developer ownership of code. Instead, it acts as a translator between design and implementation:

  • Designers work in tokens and patterns.
  • Developers work in React code.
  • UFR-DS ensures these two worlds stay in sync via a shared grammar.

Core Value Proposition

  • Migration readiness: Analyze a legacy system (like MUI usage) and output a migration map to a custom system.
  • Compression & deduplication: Reduce hundreds of slightly different components into clean, canonical pattern families.
  • Design-dev bridge: Provide a visual grammar explorer, Storybook integration, and Figma mapping so both sides share the same vocabulary.
  • Standards enforcement: Accessibility, performance, and testing are baked into the grammar.

Architecture Overview

Input: React Codebase (TypeScript components + Design Tokens + Figma refs)
↓
Analyzer & Tokenizer (AST + Tokens)
↓
UFR Grammar Core (canonical tokens, component families, usage invariants)
↓
Translator & Collaboration Tools (Figma ↔ React mapping, MUI ↔ custom migration, Storybook, docs)

Key Technical Components

1. Pattern Discovery Engine

  • AST Parser: Analyzes React component files using Babel parser
  • Tokenizer: Converts component structures to analyzable token sequences
  • Grammar Induction: Uses RePair algorithm and Minimum Description Length (MDL) optimization
  • Pattern Classification: Groups similar components into pattern families

2. Grammar Core

  • Canonical Tokens: Standardized representation of UI patterns
  • Component Families: Groups of related components (e.g., Button variants)
  • Usage Invariants: Rules that ensure consistency across implementations
  • Compression Engine: Achieves 5-10x reduction in component count

3. Translation Layer

  • Component Generator: Converts grammar patterns back to React components
  • Migration Mapper: Creates transition plans from legacy to optimized systems
  • Type Preservation: Maintains TypeScript definitions through transformation
  • Variant System: Handles component variations through props rather than duplication

Implementation Architecture

ufr-design-system/
├── packages/
│   ├── core/                    # Grammar engine and pattern discovery
│   │   ├── src/
│   │   │   ├── engine/          # RePair + MDL implementation
│   │   │   ├── grammar/         # Grammar structures and operations
│   │   │   └── emergence/       # Pattern emergence detection
│   │
│   ├── react-analyzer/          # React-specific analysis
│   │   ├── src/
│   │   │   ├── parser/          # AST parsing and tokenization
│   │   │   ├── patterns/        # Pattern recognition
│   │   │   └── analyzer.ts      # Main analysis engine
│   │
│   ├── compiler/                # Grammar to React compiler
│   │   ├── src/
│   │   │   ├── generator/       # Component generation
│   │   │   └── optimizer/       # Code optimization
│   │
│   ├── visual-editor/           # Designer interface
│   │   └── src/                # Grammar Explorer UI
│   │
│   └── cli/                     # Command-line interface
│       └── src/commands/        # analyze, generate, dedupe commands

Key Features

1. Pattern Discovery

Parse a React codebase into tokens and detect recurring structures using advanced grammar induction algorithms.

Example Analysis Output:

✓ Found 127 components
✓ Extracted 18 canonical patterns
✓ Identified 42 duplicates
✓ Compression ratio: 7.0x

Suggested Consolidations:
• Button, PrimaryButton, SecondaryButton → Button with variant
• IconButton, Fab → Button with size + icon

2. Deduplication Reports

CLI tool outputs duplicates, frequency, and suggested consolidations with actionable refactoring suggestions.

3. Migration Mapping

Analyze an existing system and output grammar + migration suggestions for transitioning from legacy systems to optimized implementations.

4. Design-Dev Bridge

  • Grammar Explorer UI: Visual interface for browsing discovered patterns
  • Figma Plugin: Token mapping between design and code
  • Storybook Integration: Auto-generated stories for pattern documentation

5. Standards Enforcement

  • Accessibility Checks: Ensure WCAG compliance in generated components
  • Performance Constraints: Optimize bundle size and runtime performance
  • Testing Hooks: Auto-generate test suites for pattern families

Example Workflow

Analyzing a Legacy System

ufr analyze ./node_modules/@mui/material --output analysis.json

Output:

✓ Found 127 components
✓ Extracted 18 canonical patterns
✓ Identified 42 duplicates
✓ Compression ratio: 7.0x

Suggested Consolidations:
• Button, PrimaryButton, SecondaryButton → Button with variant
• IconButton, Fab → Button with size + icon

Generating Optimized Components

ufr generate analysis.json --output ./optimized --typescript --storybook

Generated Component Example:

// Before: 3 separate components
import { Button, PrimaryButton, SecondaryButton } from './legacy';

// After: 1 pattern-based component
import { Button } from '@ufr/optimized';

// Usage with variants
<Button variant="primary" />
<Button variant="secondary" />
<Button variant="icon" icon={<CheckIcon />} />

Success Metrics

Technical Metrics

  • Compression ratio: 5-10× component reduction
  • Type safety: 95%+ generated code compiles without errors
  • Performance: 20%+ bundle size reduction through deduplication
  • Speed: CLI analyzes 1000+ components in <30 seconds

Adoption Metrics

  • Migration coverage: % of legacy components mapped to new grammar
  • Developer adoption: Number of teams using grammar explorer/CLI
  • Design-dev alignment: Reduction in translation errors between design and code

Roadmap

  • Phase 1: AST parsing + tokenization → compression reports
  • Phase 2: Grammar Explorer UI + Storybook integration
  • Phase 3: Figma plugin for token mapping
  • Phase 4: Migration mapping and CI integration

Technical Requirements

Dependencies

  • Core: TypeScript, React, Babel (parser/traverse/types)
  • CLI: Commander.js, Chalk, Ora
  • Analysis: RePair algorithm implementation, MDL optimization
  • Generation: TypeScript Compiler API, Prettier

Performance Targets

  • Parse 1000+ components in <30 seconds

Quick Start (Prototype CLI)

  • Analyze a React project directory using the vendored Emergence Engine:

    python -m ufr_ds.cli analyze ./examples/material-ui-subset --pretty

  • Include emergence analysis (entropy trajectory + events):

    python -m ufr_ds.cli analyze ./examples/material-ui-subset --emergence --pretty

  • Generate canonical components from discovered families (writes TSX stubs):

    python -m ufr_ds.cli generate ./examples/material-ui-subset --out ./generated --pretty

What this does:

  • Tokenizes JSX/TSX/JS files for tags, props, and imports (regex-based).
  • Runs RePair + MDL scoring to induce a grammar and compute compression.
  • Reports discovered rules and top tokens; optional emergence events.
  • Generates family-based component skeletons with a variant prop.
  • Generate optimized library in <10 seconds
  • Visual editor loads in <2 seconds
  • Support codebases up to 10,000 components

Integration Examples

With Existing Workflow

// Current: Multiple similar components
import { PrimaryButton, SecondaryButton, IconButton } from './components';

// After UFR Analysis: Single flexible component
import { Button } from '@ufr/optimized';

// Automatic migration suggestions
<Button variant="primary" />    // was PrimaryButton
<Button variant="secondary" />  // was SecondaryButton
<Button variant="icon" />       // was IconButton

With Design Systems

// Integration with design tokens
const Button = ({ variant, size, ...props }) => {
    return (
        <StyledButton
            className={buttonVariants({ variant, size })}
            {...props}
        />
    );
};

// Auto-generated from discovered patterns
const buttonVariants = cva("base-button-styles", {
    variants: {
        variant: {
            primary: "bg-primary text-white",
            secondary: "bg-secondary text-gray",
        },
        size: {
            small: "px-2 py-1 text-sm",
            large: "px-4 py-2 text-lg",
        },
    },
});

Philosophy

The best design system is not the biggest—it's the smallest set of reusable patterns that both designers and developers can own together. UFR-DS exists to discover, enforce, and evolve that shared grammar.

Core Principles:

  • Developer Ownership: Code remains in developer control, UFR-DS provides translation
  • Pattern-First: Focus on discovering existing patterns rather than imposing new ones
  • Compression Over Creation: Reduce complexity rather than add new abstractions
  • Shared Vocabulary: Bridge design and development through common grammar
  • Evidence-Based: All recommendations backed by actual usage analysis

Getting Started

Installation

npm install -g @ufr/cli
# or
npx @ufr/cli analyze ./src/components

Quick Analysis

# Analyze your components
ufr analyze ./src/components --output analysis.json

# Review suggestions
ufr report analysis.json

# Generate optimized components
ufr generate analysis.json --output ./optimized

Integration

# Add to existing project
npm install @ufr/core @ufr/react-analyzer

# Use programmatically
import { ReactPatternAnalyzer } from '@ufr/react-analyzer';
const analyzer = new ReactPatternAnalyzer();
const results = await analyzer.analyzeCodbase('./src');

Next Steps: Start with a pilot analysis of your existing component library to see compression opportunities, then gradually adopt the generated patterns while maintaining your existing development workflow.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ufr_ds-0.1.1.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ufr_ds-0.1.1-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file ufr_ds-0.1.1.tar.gz.

File metadata

  • Download URL: ufr_ds-0.1.1.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ufr_ds-0.1.1.tar.gz
Algorithm Hash digest
SHA256 be45a0c634d887b2169960aebfd4a1e8356a227075b15527c67e1f27b6e8eda2
MD5 b5c6f47809a6fd05f1d22fe9d5e51250
BLAKE2b-256 80d2379d1dfde72e5e61b306748f159339f0029d1395120eb461b69298850e86

See more details on using hashes here.

Provenance

The following attestation bundles were made for ufr_ds-0.1.1.tar.gz:

Publisher: workflow.yml on wespiper/ufr-ds

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ufr_ds-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ufr_ds-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 32.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ufr_ds-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a6b04c18f7cd6a102b2228a52e894ffadc1e5a04047eb7833542e9b84a93913e
MD5 f1ffd5bff6fc6201170be241f9047460
BLAKE2b-256 0e2cbdce82261c93238c46b6f3e89748e67e88d7e7aa45c70b662545714cba96

See more details on using hashes here.

Provenance

The following attestation bundles were made for ufr_ds-0.1.1-py3-none-any.whl:

Publisher: workflow.yml on wespiper/ufr-ds

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page