# dev-five-git/devup-ui architecture

> Architecture diagram of the GitHub repository dev-five-git/devup-ui, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dev-five-git/devup-ui
- Repository: https://github.com/dev-five-git/devup-ui

## Overview

##### Project Type and Purpose
- This is a polyglot monorepo hosting a CSS-in-JS preprocessing library (“Devup UI”) composed of:
- Core Rust crates for style extraction and CSS generation
- A WebAssembly (WASM) binding package to expose Rust logic in JavaScript
- Multiple bundler plugins (Next.js, Vite, Webpack) and a React component library
- Demo and benchmark applications illustrating usage and measuring performance
- The README confirms it is a zero-runtime CSS preprocessor that integrates at build time via plugins, producing atomic CSS classes and optional CSS variables for theming.

##### Key Directories and Their Roles
- libs/… (Rust crates):
- libs/extractor – the AST-based style extraction engine
- libs/css – core CSS utility routines
- libs/sheet – converts style descriptors into CSS strings
- bindings/devup-ui-wasm:
- Builds the above crates into a WASM module plus JavaScript glue code
- packages/… (TypeScript):
- next-plugin, vite-plugin, webpack-plugin – bundler loader plugins invoking the WASM extraction at compile time
- apps/…:
- landing, next, vite, vite-lib – demo applications (Next.js, Vite) showing documentation site and library mode
- benchmark/…:
- Comparative benchmark apps to measure build time/size across UI libraries
- Other:
- CI/CD (.github/workflows) for building, testing, and publishing to NPM
- Monorepo manifests (pnpm-workspace.yaml, Cargo.toml, Cargo.lock)

##### How the System Works (Build-Time Flow)
1. Developer writes JSX/TSX using Devup UI React components.
2. Bundler plugin (Next/Vite/Webpack) sees a TSX file → sends it to the WASM binding.
3. WASM module (built from Rust crates) parses the AST, extracts style props, and outputs:
- A set of generated CSS rules (atomic classes, theme variables)
- A class-name mapping and inline CSS variable declarations
4. Plugin emits CSS file or injects style tags per configuration, and transforms the TSX into standard JSX/TSX with className and style props.
5. React component library simply renders HTML elements with those classNames/styles.
6. Final bundle includes no runtime CSS-in-JS code—only static CSS and minimal inline variables.

##### Main Components & Interactions
- Core Rust Crates (Extractor, CSS, Sheet)
→ compile to → WASM Module + JS Glue (bindings/devup-ui-wasm)
- Bundler Plugins (packages/next-plugin, vite-plugin, webpack-plugin)
↕ use ↕
WASM Module
- React Component Library (@devup-ui/react)
↕ consumed by ↕
Demo Apps (apps/*) & Benchmark Apps
- CI/CD Pipeline
→ builds & tests Rust crates, packages, demo apps, runs benchmarks, publishes to NPM

##### Architectural Patterns & Principles
- Monorepo with polyglot workspaces (pnpm and Cargo)
- Build-time plugin architecture (no runtime overhead)
- Separation of concerns:
- Extraction logic in Rust → WASM → Plugin → React components → Consumer apps
- Minimal coupling: React library does not itself parse or generate CSS—it delegates to plugins/WASM

##### Essential Elements to Capture
- Each major codebase (Rust crates, WASM binding, TS packages, demo/benchmark apps, CI)
- The flow from source code to final bundle (AST extraction → CSS emit → transformed JSX → browser)
- Plugin injection points in build pipelines (Next.js/Vite/Webpack loaders)
- Package publishing step (CI → NPM)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Rust components
    subgraph "Rust Crates"
        direction TB
        Extractor["Extractor Engine"]:::rust
        CSSUtils["CSS Utilities"]:::rust
        Sheet["Style Sheet Generator"]:::rust
    end

    WASMBinding["WASM Binding Package"]:::wasm

    %% Plugin components
    subgraph "Bundler Plugins"
        direction TB
        NextPlugin["Next.js Plugin"]:::plugin
        VitePlugin["Vite Plugin"]:::plugin
        WebpackPlugin["Webpack Plugin"]:::plugin
    end

    Transformed["Transformed Code + CSS"]:::process

    ReactLib["@devup-ui/react"]:::reactlib

    subgraph "Demo Applications"
        direction TB
        LandingApp["Landing Site (Next.js)"]:::app
        NextApp["Next.js Example"]:::app
        ViteLibApp["Vite Library Mode"]:::app
        ViteApp["Vite SPA Example"]:::app
    end

    subgraph "Benchmark Suites"
        direction TB
        BenchChakra["Next + Chakra UI"]:::bench
        BenchDevup["Next + Devup UI"]:::bench
        BenchKuma["Next + Kuma UI"]:::bench
    end

    CICD["CI/CD Workflows"]:::cicd
    Manifests["Monorepo Manifests"]:::manifest

    %% Connections
    Extractor -->|compile to WASM| WASMBinding
    CSSUtils -->|compile to WASM| WASMBinding
    Sheet -->|compile to WASM| WASMBinding

    WASMBinding -->|"invoke at build time"| NextPlugin
    WASMBinding -->|"invoke at build time"| VitePlugin
    WASMBinding -->|"invoke at build time"| WebpackPlugin

    NextPlugin -->|"generate CSS and transform code"| Transformed
    VitePlugin -->|"generate CSS and transform code"| Transformed
    WebpackPlugin -->|"generate CSS and transform code"| Transformed

    Transformed -->|"render classNames/styles"| ReactLib
    ReactLib -->|"used by"| LandingApp
    ReactLib -->|"used by"| NextApp
    ReactLib -->|"used by"| ViteLibApp
    ReactLib -->|"used by"| ViteApp

    ReactLib -->|"used by"| BenchChakra
    ReactLib -->|"used by"| BenchDevup
    ReactLib -->|"used by"| BenchKuma

    CICD -->|"build & test"| Extractor
    CICD -->|"build & test"| CSSUtils
    CICD -->|"build & test"| Sheet
    CICD -->|"build & publish"| WASMBinding
    CICD -->|"build & publish"| NextPlugin
    CICD -->|"build & publish"| VitePlugin
    CICD -->|"build & publish"| WebpackPlugin
    CICD -->|"build & publish"| ReactLib
    CICD -->|"run demos & benchmarks"| LandingApp
    CICD -->|"run demos & benchmarks"| NextApp
    CICD -->|"run demos & benchmarks"| ViteLibApp
    CICD -->|"run demos & benchmarks"| ViteApp
    CICD -->|"run demos & benchmarks"| BenchChakra
    CICD -->|"run demos & benchmarks"| BenchDevup
    CICD -->|"run demos & benchmarks"| BenchKuma

    Manifests -->|"workspace config"| CICD

    %% Click Events
    click Extractor "https://github.com/dev-five-git/devup-ui/tree/main/libs/extractor"
    click CSSUtils "https://github.com/dev-five-git/devup-ui/tree/main/libs/css"
    click Sheet "https://github.com/dev-five-git/devup-ui/tree/main/libs/sheet"
    click WASMBinding "https://github.com/dev-five-git/devup-ui/tree/main/bindings/devup-ui-wasm"
    click NextPlugin "https://github.com/dev-five-git/devup-ui/tree/main/packages/next-plugin"
    click VitePlugin "https://github.com/dev-five-git/devup-ui/tree/main/packages/vite-plugin"
    click WebpackPlugin "https://github.com/dev-five-git/devup-ui/tree/main/packages/webpack-plugin"
    click ReactLib "https://github.com/dev-five-git/devup-ui/tree/main/packages/react"
    click LandingApp "https://github.com/dev-five-git/devup-ui/tree/main/apps/landing"
    click NextApp "https://github.com/dev-five-git/devup-ui/tree/main/apps/next"
    click ViteLibApp "https://github.com/dev-five-git/devup-ui/tree/main/apps/vite-lib"
    click ViteApp "https://github.com/dev-five-git/devup-ui/tree/main/apps/vite"
    click BenchChakra "https://github.com/dev-five-git/devup-ui/tree/main/benchmark/next-chakra-ui"
    click BenchDevup "https://github.com/dev-five-git/devup-ui/tree/main/benchmark/next-devup-ui"
    click BenchKuma "https://github.com/dev-five-git/devup-ui/tree/main/benchmark/next-kuma-ui"
    click CICD "https://github.com/dev-five-git/devup-ui/blob/main/.github/workflows/publish.yml"
    click Manifests "https://github.com/dev-five-git/devup-ui/blob/main/pnpm-workspace.yaml"
    click Manifests "https://github.com/dev-five-git/devup-ui/blob/main/Cargo.toml"
    click Manifests "https://github.com/dev-five-git/devup-ui/blob/main/Cargo.lock"

    %% Style Definitions
    classDef rust fill:#cccccc,stroke:#333,stroke-width:1px
    classDef wasm fill:#ffcc66,stroke:#333,stroke-width:1px
    classDef plugin fill:#99ccff,stroke:#333,stroke-width:1px
    classDef reactlib fill:#99ff99,stroke:#333,stroke-width:1px
    classDef app fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef bench fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef cicd fill:#ffdd99,stroke:#333,stroke-width:1px
    classDef manifest fill:#eeeeee,stroke:#333,stroke-width:1px
    classDef process fill:#ddddff,stroke:#333,stroke-width:1px
```
