Skip to content

Extract design systems from WordPress themes using deterministic parsing and AI synthesis.

Notifications You must be signed in to change notification settings

soderlind/ps-design-system

Repository files navigation

PS Design System

A PoC and still in early development β€” use at your own risk!

Extract design systems from WordPress themes using deterministic parsing and AI synthesis.

PHP 8.3+ WordPress 6.8+ License: GPL v2+

Description

PS Design System is a WordPress plugin that extracts design tokens and patterns from any WordPress theme, producing a structured design system document. It uses a two-step process:

  1. Deterministic Extraction β€” Parses CSS files, theme.json, and template files to extract raw design tokens (colors, typography, spacing, etc.)

    Example: samples/TT5/extraction.json

  2. AI Synthesis β€” Uses LLM providers (OpenAI, Anthropic Claude, Azure OpenAI) to analyze, deduplicate, and synthesize tokens into a coherent design system

    Example:

Features

  • 🎨 Design Token Extraction β€” Colors, typography, spacing, shadows, borders, and more
  • πŸ“„ theme.json Support β€” Full support for WordPress block theme configuration
  • πŸ€– Multi-Provider LLM β€” Choose between OpenAI, Anthropic Claude, or Azure OpenAI
  • πŸ” Secure API Keys β€” Sodium encryption for stored API credentials
  • ⚑ Background Processing β€” Action Scheduler for chunked extraction of large themes
  • πŸ“Š Progress Tracking β€” Real-time job status updates in the admin UI
  • πŸ“₯ Multiple Outputs β€” Export as JSON tokens, full design system, HTML styleguide, or Figma Tokens Studio file
  • 🎯 Figma Integration β€” Import tokens directly into Figma via Tokens Studio plugin

Requirements

  • PHP 8.3 or higher
  • WordPress 6.8 or higher
  • Sodium PHP extension (included in PHP 7.2+)
  • Composer (for development)

Installation

From Source

# Clone the repository
git clone https://github.com/soderlind/ps-design-system.git

# Install dependencies
cd ps-design-system
composer install --no-dev

# Copy to your WordPress plugins directory
cp -r ps-design-system /path/to/wp-content/plugins/

Composer

composer require soderlind/ps-design-system

Configuration

  1. Navigate to Design System β†’ Settings
  2. Enter your API key for at least one provider:
  3. Save settings

Usage

  1. Go to Design System β†’ Generate
  2. Select the theme to analyze
  3. Choose extraction scope:
    • Tokens Only β€” Just design tokens (fastest)
    • Tokens + Components β€” Tokens and UI component patterns
    • Full System β€” Complete design system with templates
  4. Select your LLM provider
  5. Click Generate Design System
  6. Download the results when complete

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      WordPress Admin                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Generate Page  β”‚  History Page  β”‚  Settings Page           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                      Job Manager                             β”‚
β”‚  (Action Scheduler for background processing)                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   Extractor  β”‚    Normalizer    β”‚      LLM Client           β”‚
β”‚  (CSS/JSON)  β”‚  (Dedupe/Score)  β”‚  (AI Synthesis)           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                 β”‚    Figma Generator        β”‚
β”‚                                 β”‚  (Tokens Studio format)   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                      Providers                               β”‚
β”‚    OpenAI    β”‚    Anthropic     β”‚    Azure OpenAI           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Development

Prerequisites

  • PHP 8.3+
  • Composer
  • Node.js 20+
  • npm

Setup

# Install PHP dependencies
composer install

# Install JavaScript dependencies
npm install

Testing

# Run PHP tests (Pest)
composer test

# Run JavaScript tests (Vitest)
npm test

# Run all tests
composer test && npm test

Code Style

# Check PHP code style
composer phpcs

# Fix PHP code style
composer phpcbf

# Lint JavaScript
npm run lint

Hooks

Filters

// Modify extracted tokens before normalization
add_filter( 'ps_ds_extracted_tokens', function( $tokens, $theme, $job_id ) {
    // Modify $tokens
    return $tokens;
}, 10, 3 );

// Modify the system prompt sent to LLM
add_filter( 'ps_ds_system_prompt', function( $prompt, $scope ) {
    return $prompt . "\n\nAdditional instructions...";
}, 10, 2 );

// Modify final design system output
add_filter( 'ps_ds_design_system', function( $design_system, $job_id ) {
    // Add custom properties
    return $design_system;
}, 10, 2 );

Actions

// Fired when extraction starts
add_action( 'ps_ds_extraction_started', function( $job_id, $theme ) {
    // Log or notify
}, 10, 2 );

// Fired when job completes
add_action( 'ps_ds_job_complete', function( $job_id, $outputs ) {
    // Post-processing
}, 10, 2 );

// Fired on job failure
add_action( 'ps_ds_job_failed', function( $job_id, $error ) {
    // Error handling
}, 10, 2 );

Output Format

The generated design system follows a structured JSON schema:

{
  "version": "1.0",
  "theme": "theme-name",
  "generated_at": "2026-02-04T12:00:00Z",
  "tokens": {
    "colors": {
      "primary": { "value": "#007bff", "usage": "primary-actions" },
      "secondary": { "value": "#6c757d", "usage": "secondary-elements" }
    },
    "typography": {
      "fontFamilies": [...],
      "fontSizes": [...],
      "lineHeights": [...]
    },
    "spacing": {
      "scale": [4, 8, 16, 24, 32, 48, 64],
      "unit": "px"
    }
  },
  "components": [...],
  "patterns": [...]
}

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the GPL v2 or later β€” see the LICENSE file for details.

Credits

Support

About

Extract design systems from WordPress themes using deterministic parsing and AI synthesis.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published