# yinm/figma-text-style-guide architecture

> Architecture diagram of the GitHub repository yinm/figma-text-style-guide, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yinm/figma-text-style-guide
- Repository: https://github.com/yinm/figma-text-style-guide

## Overview

##### Project Type and Purpose
- This project is a Figma plugin with an accompanying user interface (UI). Its goal is to help manage and apply text style guides and design tokens within Figma. The design tokens (managed in the design-tokens directory) provide consistent styling, and the “plugin” code adds functionality (like creating frames and text style objects) directly within Figma.
- The README commands (e.g., “pnpm sync-design-tokens”, “pnpm dev:ui”) confirm that there is active synchronization between design tokens and the plugin/UI elements.

##### File Structure
- The top-level directories and configuration files indicate robust development tooling:
- Configuration files (.prettierrc.json, eslint.config.js, etc.) ensure code quality.
- GitHub workflows (.github/workflows/ci.yml) and renovate.json illustrate CI/CD and dependency management.
- The source code is split primarily into two main areas:
- The plugin itself (in src/plugin) which handles core functionality and operations within Figma. This includes various “nodes” (such as createBodyFrame, createHeadingFrame, etc.) each with its own implementation and testing.
- The UI (in src/ui) which includes an index.html, main.tsx, and several React (or similar) components (like Button, Switch, LabelAndSwitch). This indicates a separation of concerns between the plugin logic and the interactive user interface.
- Additionally, there is a standalone “design-tokens” directory that contains token configuration files and JSON definitions (primitive.tokens.json and semantic.tokens.json), which are likely integrated into both the plugin and UI parts.

##### Architectural Patterns and Design Principles
- The project follows a modular design by separating functionality into distinct directories:
- Plugin modules (various “nodes”) help maintain a clear separation of responsibilities (each node for a particular frame or text style operation).
- The UI is self-contained and uses component-based architecture.
- There is evidence of a message-passing mechanism between the UI and plugin parts (see files like src/ui/utils/postMessageFromUi.ts and the shared types under src/shared/types), which suggests a loosely-coupled design where the UI sends messages (commands, updates) to the plugin runtime.

##### Relevant Technologies/Frameworks/Libraries
- Build and dependency management: pnpm with a pnpm-lock.yaml file.
- Modern JavaScript/TypeScript: Use of TS configuration files (tsconfig.*.json) throughout the project.
- Vite: Two Vite configuration files (vite.config.plugin.ts and vite.config.ui.ts) drive the separate builds for the plugin and the UI.
- Testing: Unit tests (.spec.ts) are present for both plugin nodes and UI components.
- Scaffdog: Template/scaffolding configuration (files under .scaffdog) to speed up file/component generation.
- Design tokens: Maintained under design-tokens and synced via pnpm commands.

## Diagram (Mermaid)

```mermaid
flowchart TD
    FigmaClient["Figma Client"]:::external
    FigmaClient -->|"integrates"| PModule

    subgraph "Plugin Module"
        PModule["Plugin Module - Core Functionality"]:::plugin
        PModule --> P1["createBodyFrame"]:::plugin_node
        PModule --> P2["createHeadingFrame"]:::plugin_node
        PModule --> P3["createPropertyFrame"]:::plugin_node
        PModule --> P4["createSampleText"]:::plugin_node
        PModule --> P5["createSpecFrame"]:::plugin_node
        PModule --> P6["createTextStyleFrame"]:::plugin_node
        PModule --> P7["createTextStyleGuideFrame"]:::plugin_node
    end

    subgraph "UI Module"
        UIModule["UI Module - Main Interface"]:::ui
        UIModule --> UIComp["UI Components"]:::ui
        UIComp --> U_Button["Button"]:::ui_comp
        UIComp --> U_Switch["Switch"]:::ui_comp
        UIComp --> U_LabelAndSwitch["LabelAndSwitch"]:::ui_comp
        UIModule --> UIMsg["UI Post Messaging Utility"]:::ui_tool
    end

    SharedMsg["Shared Messaging Interfaces"]:::shared

    DesignTokens["Design Tokens Service"]:::tokens

    subgraph "Toolchain"
        T1["Plugin Build Config"]:::toolchain
        T2["UI Build Config"]:::toolchain
        T3["CI/CD Workflows"]:::toolchain
        T4["Dependency & Lint Configs"]:::toolchain
    end

    %% Messaging between UI and Plugin
    UIModule -->|"postMessage"| PModule
    UIMsg -->|"sends"| SharedMsg
    SharedMsg -->|"triggers"| PModule

    %% Design Tokens integration
    DesignTokens ---|"stylingData"| PModule
    DesignTokens ---|"stylingData"| UIModule

    %% Toolchain connections
    T1 ---|"builds"| PModule
    T2 ---|"builds"| UIModule
    T3 ---|"deploys"| PModule
    T3 ---|"deploys"| UIModule
    T4 ---|"ensuresQuality"| PModule
    T4 ---|"ensuresQuality"| UIModule

    %% Click Events
    click PModule "https://github.com/yinm/figma-text-style-guide/tree/main/src/plugin"
    click P1 "https://github.com/yinm/figma-text-style-guide/blob/main/src/plugin/nodes/createBodyFrame/createBodyFrame.ts"
    click P2 "https://github.com/yinm/figma-text-style-guide/blob/main/src/plugin/nodes/createHeadingFrame/createHeadingFrame.ts"
    click P3 "https://github.com/yinm/figma-text-style-guide/blob/main/src/plugin/nodes/createPropertyFrame/createPropertyFrame.ts"
    click P4 "https://github.com/yinm/figma-text-style-guide/blob/main/src/plugin/nodes/createSampleText/createSampleText.ts"
    click P5 "https://github.com/yinm/figma-text-style-guide/blob/main/src/plugin/nodes/createSpecFrame/createSpecFrame.ts"
    click P6 "https://github.com/yinm/figma-text-style-guide/blob/main/src/plugin/nodes/createTextStyleFrame/createTextStyleFrame.ts"
    click P7 "https://github.com/yinm/figma-text-style-guide/blob/main/src/plugin/nodes/createTextStyleGuideFrame/createTextStyleGuideFrame.ts"
    click UIModule "https://github.com/yinm/figma-text-style-guide/tree/main/src/ui"
    click U_Button "https://github.com/yinm/figma-text-style-guide/blob/main/src/ui/components/Button/Button.tsx"
    click U_Switch "https://github.com/yinm/figma-text-style-guide/blob/main/src/ui/components/Switch/Switch.tsx"
    click U_LabelAndSwitch "https://github.com/yinm/figma-text-style-guide/blob/main/src/ui/components/LabelAndSwitch/LabelAndSwitch.tsx"
    click UIMsg "https://github.com/yinm/figma-text-style-guide/blob/main/src/ui/utils/postMessageFromUi.ts"
    click SharedMsg "https://github.com/yinm/figma-text-style-guide/tree/main/src/shared/types/pluginMessagesFromUi"
    click DesignTokens "https://github.com/yinm/figma-text-style-guide/tree/main/design-tokens"
    click T1 "https://github.com/yinm/figma-text-style-guide/blob/main/vite.config.plugin.ts"
    click T2 "https://github.com/yinm/figma-text-style-guide/blob/main/vite.config.ui.ts"
    click T3 "https://github.com/yinm/figma-text-style-guide/blob/main/.github/workflows/ci.yml"
    click T4 "https://github.com/yinm/figma-text-style-guide/blob/main/package.json"

    %% Styling
    classDef external fill:#ffd1dc,stroke:#333,stroke-width:2px;
    classDef plugin fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef plugin_node fill:#e0f7fa,stroke:#333,stroke-width:2px;
    classDef ui fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef ui_comp fill:#f1f8e9,stroke:#333,stroke-width:2px;
    classDef ui_tool fill:#f1f8e9,stroke:#333,stroke-width:2px;
    classDef shared fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef tokens fill:#d1c4e9,stroke:#333,stroke-width:2px;
    classDef toolchain fill:#f8d7da,stroke:#333,stroke-width:2px;
```
