# vicentelyrio/penpot-color-tokens architecture

> Architecture diagram of the GitHub repository vicentelyrio/penpot-color-tokens, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vicentelyrio/penpot-color-tokens
- Repository: https://github.com/vicentelyrio/penpot-color-tokens

## Overview

##### Project Type and Purpose
- It combines a React‐based front end (running in the plugin iframe) with plugin logic that calls the Penpot Plugin API.

##### File Structure
Top‐level:
- public/ (static assets, manifest, headers)
- index.html (plugin host HTML)
- src/
– app.tsx, main.tsx (React entry point)
– plugin.ts (Penpot plugin entry point)
– components/ (UI building blocks)
– hooks/ (React state‐management hooks)
– plugin/ (business logic that interfaces with Penpot API)
– utils/ (pure helper functions)
– consts/, types/ (configuration, type definitions)
– tests/ (Vitest setup and mocks)
Config & tooling: package.json, pnpm-lock.yaml, vite.config.ts, tsconfig*.json, vitest.config.ts

##### Extract Insights from the README
- The plugin:
- Generates tints/shades via algorithm
- Exports W3C-compliant JSON
- Highlights the core features: palette generation, component creation, JSON output.

a. Main Components
1) Presentation Layer (React UI)
– src/app.tsx, src/components/*, src/styles.css
2) State & Business Hooks
– src/hooks/useGenerate, usePalette, useToaster, etc.
3) Service Layer (Plugin Logic)
– src/plugin/*.ts: generateColorLibrary, generateComponents, libraryService, colorCache
4) Utility Layer
– src/utils/* for pure functions (buildPalette, parseColors, downloadJson, clsx)
5) Penpot Plugin Host (External Service)
– The environment provided by Penpot
6) Outputs
– Penpot UI library updates (components & tokens)
– JSON export file
7) Build & Tooling
– Vite dev server/bundler, Vitest for tests

b. Relationships & Interaction Flow
1) User interacts with the React UI in the plugin iframe.
2) UI hooks invoke service functions via custom hooks.
3) Service functions in src/plugin process data, call Penpot Plugin API (via plugin.ts).
4) Penpot API creates components/tokens in the user’s Penpot document.
6) Output: library is updated live; JSON blob is sent back to UI for download.

c. Architectural Patterns & Principles
– Separation of concerns: UI vs. hooks vs. plugin logic vs. utilities
– Unidirectional data flow: UI → hooks → services → Penpot API → UI feedback
– Testable units: each layer has accompanying .test.ts files (Vitest)
– Module boundaries: clear src/components, src/hooks, src/utils, src/plugin

d. Key Technologies & Frameworks
– React + TypeScript
– Vite (build tool)
– Vitest (testing)
– pnpm (package manager)
– Penpot Plugin API (external host)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        UI["React UI\n(src/app.tsx)"]:::ui
    end

    %% State & Business Hooks
    subgraph "State & Business Hooks"
        direction TB
        Hooks["Custom Hooks\n(src/hooks)"]:::hooks
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        Services["Plugin Services\n(src/plugin)"]:::service
    end

    %% Utility Layer
    subgraph "Utility Layer"
        direction TB
        Utils["Utilities\n(src/utils)"]:::utils
    end

    %% External Host
    subgraph "Plugin Host"
        direction TB
        Manifest["manifest.json"]:::external
        HostEnv["Penpot Plugin API\n(index.html)"]:::external
    end

    %% Outputs
    subgraph "Outputs"
        direction TB
        Library["Penpot Library\n(updated components & tokens)"]:::output
        JSON["JSON Export\n(downloadable blob)"]:::output
    end

    %% Build & Tooling
    subgraph "Build & Tooling"
        direction TB
        Build["Vite & Config\n(build & test)"]:::build
    end

    %% Flows
    UI -->|"uses hooks"| Hooks
    Hooks -->|"calls services"| Services
    Services -->|"invokes API"| HostEnv
    HostEnv -->|"updates library"| Library
    Services -->|"returns JSON"| JSON
    Utils -.-> UI
    Utils -.-> Hooks
    Utils -.-> Services

    %% Plugin Discover
    Manifest --> HostEnv

    %% Build Flow
    Build --> UI
    Build --> Services
    Build --> Utils
    Build --> Hooks

    %% Click Events
    click UI "https://github.com/vicentelyrio/penpot-color-tokens/blob/main/src/app.tsx"
    click Hooks "https://github.com/vicentelyrio/penpot-color-tokens/blob/main/src/hooks/useGenerate.ts"
    click Services "https://github.com/vicentelyrio/penpot-color-tokens/blob/main/src/plugin.ts"
    click Utils "https://github.com/vicentelyrio/penpot-color-tokens/blob/main/src/utils/buildPalette.ts"
    click Manifest "https://github.com/vicentelyrio/penpot-color-tokens/blob/main/public/manifest.json"
    click HostEnv "https://github.com/vicentelyrio/penpot-color-tokens/blob/main/index.html"
    click Build "https://github.com/vicentelyrio/penpot-color-tokens/blob/main/vite.config.ts"

    %% Styles
    classDef ui fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1
    classDef hooks fill:#E8F5E9,stroke:#A5D6A7,color:#1B5E20
    classDef service fill:#C8E6C9,stroke:#66BB6A,color:#2E7D32
    classDef utils fill:#ECEFF1,stroke:#B0BEC5,color:#37474F
    classDef external fill:#FFF3E0,stroke:#FFCC80,color:#E65100
    classDef output fill:#FFFDE7,stroke:#FFF176,color:#F9A825
    classDef build fill:#F3E5F5,stroke:#CE93D8,color:#6A1B9A
```
