# figma/plugin-samples architecture

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

- Interactive diagram: https://gitdiagram.com/figma/plugin-samples
- Repository: https://github.com/figma/plugin-samples

## Overview

This repository is a collection of sample Figma and FigJam plugins built to demonstrate various capabilities of the Figma Plugin API, including both plugins with user interfaces (UI) and those that run purely in the background. Each sample plugin is a self-contained module with its own manifest, plugin code (using TypeScript or JavaScript), and sometimes separate HTML files for the UI. The overall project serves as both a learning resource and a starting point for building your own plugins.

##### Project Type and Purpose
- Project Type: Collection of sample plugins for Figma and FigJam.
- Purpose: To demonstrate different plugin functionalities using Figma’s API – for example, generating charts, annotating images, handling drag-and-drop, performing network requests, or enabling real-time communication between plugin UI and Figma’s canvas.
- Key info from the README:
- Instructions on using TypeScript and Node.js to compile and test each sample.
- A clear distinction between plugins that run in Figma versus those meant for FigJam.
- Examples that cover basic to advanced functionalities (e.g., postMessage communication, bundling with esbuild/webpack, Dev Mode integrations).

##### Analyzing the File Structure
- At the top level, you have key files like .gitignore, LICENSE, and README. The repository is organized into subdirectories where each directory (e.g., barchart, capital, circletext, etc.) represents a separate sample plugin.
- Most sample directories include:
- A manifest.json that configures the plugin settings for Figma/ FigJam.
- A main code file (code.ts or code.js) that implements the plugin’s logic.
- Optionally, a UI file (ui.html or similar) for plugins that require a visual interface.
- For TypeScript-based projects, a tsconfig.json to set the build configuration.
- Some directories include additional files like build configurations (vite.config.ts, webpack.config.js) or package.json for dependency management.

a. Main Components:
- Repository Core: The main project shell that holds all sample plugins.
- Individual Plugin Modules: Each sample plugin (barchart, capital, circletext, etc.) is a modular component.
- Plugin Manifest & Configuration: For every module, the manifest.json file represents the configuration that Figma uses.
- Plugin Code: The plugin’s business logic (written in TypeScript or JavaScript).
- Plugin UI (if applicable): Standalone HTML or bundled UI code that interacts with the plugin code.
- Tooling Components: TypeScript compiler, bundlers (esbuild, webpack, vite) and Node/NPM which are used during development.
- Figma/FigJam Environment: The Figma desktop or FigJam web application hosting these plugins.

b. Relationships and Interactions:
- For each sample plugin, show a clear separation between plugin code and any UI components.
– Communication between plugin UI and Figma’s canvas via postMessage or API calls.
– Dependencies between plugin code and external resources (for example, any included libraries or bundled resources).
– Connections from each plugin module to the Figma/FigJam environment where the plugins are ultimately executed.
- That the shared project-level configuration (like package.json or shared typings) supports multiple plugin modules.

c. Architectural Patterns and Design Principles:
- Modular architecture: Each plugin is an independent module with its own configuration and isolated functionality.
- Separation of Concerns: Clear distinction between UI and backend logic within each plugin.
- Event-driven communication: Emphasize how UI components communicate with the main plugin logic and Figma’s API.
- Use of build pipelines: Highlight the role of build tools (esbuild, webpack, tsc) that transform source code into deployable assets.

d. Relevant Technologies:
- TypeScript and JavaScript as the programming languages.
- Node.js and npm for dependency management and scripting.
- Build tools: tsc, webpack, vite, and esbuild for bundling.
- Figma Plugin API and FigJam specific API components (e.g., for managing stickers, connectors, etc.).
- Optionally, UI libraries for styling (e.g., Figma Plugin DS or Preact) as referenced in the README for certain examples.

##### Elements
- Clearly labeled blocks for each major component: “Repository Core”, individual plugin modules (e.g., Bar Chart, Vote Tally, etc.), “Build Tools”, “Figma/FigJam Host Environment”.
- Source code components (circle or rectangle for code files and configuration)
- External systems (e.g., Figma desktop, Node.js environment).

## Diagram (Mermaid)

```mermaid
graph TD
    RepositoryCore["Repository Core"]:::repository
    RepositoryCore --> PluginModules["Plugin Modules"]:::config
    RepositoryCore --> BuildTools["Build & Development Tools"]:::external

    subgraph "Plugins with UI"
        BarchartManifest["Manifest (barchart/manifest.json)"]:::config
        BarchartCode["Code (barchart/code.ts)"]:::code
        BarchartUI["UI (barchart/ui.html)"]:::ui

        AnnotationsManifest["Manifest (annotations/manifest.json)"]:::config
        AnnotationsCode["Code (annotations/code.js)"]:::code
        AnnotationsUI["UI (annotations/ui.html)"]:::ui

        BarchartUI -->|"postMessage"| BarchartCode
        AnnotationsUI -->|"postMessage"| AnnotationsCode
    end

    subgraph "Plugins without UI"
        CapitalManifest["Manifest (capital/manifest.json)"]:::config
        CapitalCode["Code (capital/code.ts)"]:::code
    end

    PluginModules --> BarchartManifest
    PluginModules --> AnnotationsManifest
    PluginModules --> CapitalManifest

    FigmaEnv["Figma/FigJam Environment"]:::external
    BarchartCode -->|"APICommunication"| FigmaEnv
    AnnotationsCode -->|"APICommunication"| FigmaEnv
    CapitalCode -->|"APICommunication"| FigmaEnv

    subgraph "Build Tools & Configurations"
        TSCompiler["TS Compiler (tsc)"]:::external
        Bundlers["Bundlers (webpack,vite,esbuild)"]:::external
        NodeNpm["Node.js & npm"]:::external

        BarchartTS["Barchart tsconfig (barchart/tsconfig.json)"]:::config
        WebpackConfig["webpack-react config (webpack-react/webpack.config.js)"]:::config
        CodegenVite["codegen vite config (codegen/vite.config.ts)"]:::config
        EsbuildVite["esbuild-react vite config (esbuild-react/vite.config.ts)"]:::config

        Gitignore["Gitignore (.gitignore)"]:::external
        ESLint["ESLint (circletext/.eslintrc.js)"]:::external
        CreateRectsGitignore["Gitignore (create-rects-shapes/.gitignore)"]:::external

        NodeNpm --> TSCompiler
        NodeNpm --> Bundlers
        TSCompiler --> BarchartTS
        Bundlers --> WebpackConfig
        Bundlers --> CodegenVite
        Bundlers --> EsbuildVite
    end

    BuildTools --> TSCompiler
    BuildTools --> Bundlers
    BuildTools --> NodeNpm
    BuildTools --> Gitignore
    BuildTools --> ESLint
    BuildTools --> CreateRectsGitignore

    TSCompiler -->|"CompilationBuild"| BarchartCode
    TSCompiler -->|"CompilationBuild"| CapitalCode
    Bundlers -->|"CompilationBuild"| AnnotationsCode

    click RepositoryCore "https://github.com/figma/plugin-samples/blob/main/."
    click BarchartManifest "https://github.com/figma/plugin-samples/blob/main/barchart/manifest.json"
    click BarchartCode "https://github.com/figma/plugin-samples/blob/main/barchart/code.ts"
    click BarchartUI "https://github.com/figma/plugin-samples/blob/main/barchart/ui.html"
    click AnnotationsManifest "https://github.com/figma/plugin-samples/blob/main/annotations/manifest.json"
    click AnnotationsCode "https://github.com/figma/plugin-samples/blob/main/annotations/code.js"
    click AnnotationsUI "https://github.com/figma/plugin-samples/blob/main/annotations/ui.html"
    click CapitalManifest "https://github.com/figma/plugin-samples/blob/main/capital/manifest.json"
    click CapitalCode "https://github.com/figma/plugin-samples/blob/main/capital/code.ts"
    click BarchartTS "https://github.com/figma/plugin-samples/blob/main/barchart/tsconfig.json"
    click WebpackConfig "https://github.com/figma/plugin-samples/blob/main/webpack-react/webpack.config.js"
    click CodegenVite "https://github.com/figma/plugin-samples/blob/main/codegen/vite.config.ts"
    click EsbuildVite "https://github.com/figma/plugin-samples/blob/main/esbuild-react/vite.config.ts"
    click Gitignore "https://github.com/figma/plugin-samples/blob/main/.gitignore"
    click ESLint "https://github.com/figma/plugin-samples/blob/main/circletext/.eslintrc.js"
    click CreateRectsGitignore "https://github.com/figma/plugin-samples/blob/main/create-rects-shapes/.gitignore"

    classDef repository fill:#87CEFA,stroke:#333,stroke-width:2px;
    classDef config fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef code fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef ui fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px;
```
