How vicentelyrio/penpot-color-tokens works
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)