# imnotashrimp/copythat-airtable-figma architecture

> Architecture diagram of the GitHub repository imnotashrimp/copythat-airtable-figma, 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/imnotashrimp/copythat-airtable-figma
- Repository: https://github.com/imnotashrimp/copythat-airtable-figma

## Overview

##### Main components
- Figma Environment & Plugin Integration:
- manifest.json: This file defines the plugin’s metadata and is how Figma integrates and registers the plugin.
- UI files: src/ui.html and src/ui.ts are responsible for rendering and handling interactions in the plugin’s user interface.

- Core Plugin Logic:
- Entry point and main logic: src/code.ts – orchestrates how the plugin operates once it’s invoked in Figma.
- Utility modules: Files like src/date-time.ts, src/fonts.ts, src/format-text.ts, src/replace-text.ts, and src/var-test.ts provide helper functions and variable processing.

- External Service Integration (Airtable):
- Airtable Service Layer: Modules under src/airtable (get-airtable-records.ts and get-set-airtable-config.ts) are dedicated to fetching records from Airtable, configuring the connection, and potentially managing the data flow from Airtable.

- Build and Deployment Tools:
- Bundler & Transpilers: webpack.config.js (for bundling) and babel.config.js are used to prepare the code for execution, ensuring it complies with the required specifications for Figma.
- TypeScript configuration: tsconfig.json ensures the TypeScript code is compiled correctly.
- Package Management: package.json, package-lock.json, and the related npm dependencies.

- Testing Environment:
- Test cases: Files in the __tests__ directory (e.g., dateTime.spec.js, varTest.spec.js) using Jest to validate the functionality.

##### Relationships and data flow
- The developer builds the plugin using the provided build tools (Webpack, Babel, TypeScript) and manages dependencies via npm.
- The plugin is loaded into Figma via manifest.json.
- Within Figma:
- When triggered (via the Figma menu), the plugin’s UI (src/ui.html & src/ui.ts) is rendered, offering configuration options for Airtable (like specifying field names, etc.).
- The core logic (src/code.ts) listens for user actions, such as syncing text.
- The core logic calls the Airtable modules to fetch the required records.
- Once records are fetched and processed (using utility modules to format/replace text), the plugin updates the Figma document text nodes that match the placeholders.
- Testing components ensure that functions, particularly those that process variables and dates, behave as expected. Jest tests in __tests__ lend confidence to module interactions.

##### Architectural patterns and design principles
- Modularization: The project is split into distinct modules for Airtable integration, UI management, and general utility functions. This aligns with modular development best practices.
- Separation of Concerns: The clear separation between UI, core processing, and external service (Airtable) calls.
- Plugin architecture standard for Figma: Leveraging manifest.json for registration and appropriate signaling to Figma’s runtime environment.
- Build and deployment pipeline: Maintaining configuration files (tsconfig.json, webpack.config.js, babel.config.js) and CI workflows (in .github/workflows) that run tests.

- Frontend (Figma plugin UI)
- Backend / core logic
- External API integration
- Build environment and testing infrastructure.

## Diagram (Mermaid)

```mermaid
graph TD
    Figma["Figma Environment"]:::figma
    Manifest["Plugin Registration: manifest.json"]:::plugin
    Figma -->|"loads"| Manifest

    subgraph "UI Layer"
        UIHTML["UI: src/ui.html"]:::frontend
        UITS["UI: src/ui.ts"]:::frontend
    end
    Manifest -->|"registersUI"| UIHTML
    Manifest -->|"registersUI"| UITS
    UIHTML -->|"triggers"| Code
    UITS -->|"triggers"| Code

    subgraph "Core Logic"
        Code["Core Entry: src/code.ts"]:::backend
        DateTime["Utility: src/date-time.ts"]:::backend
        Fonts["Utility: src/fonts.ts"]:::backend
        FormatText["Utility: src/format-text.ts"]:::backend
        ReplaceText["Utility: src/replace-text.ts"]:::backend
        VarTest["Utility: src/var-test.ts"]:::backend
    end
    Manifest -->|"registersCore"| Code
    Code -->|"uses"| DateTime
    Code -->|"uses"| Fonts
    Code -->|"uses"| FormatText
    Code -->|"uses"| ReplaceText
    Code -->|"uses"| VarTest

    subgraph "Airtable Integration"
        AirtableRec["Airtable Records: src/airtable/get-airtable-records.ts"]:::external
        AirtableConfig["Airtable Config: src/airtable/get-set-airtable-config.ts"]:::external
    end
    Code -->|"calls"| AirtableRec
    Code -->|"calls"| AirtableConfig
    AirtableRec -->|"returnsData"| Code
    AirtableConfig -->|"returnsConfig"| Code

    Code -->|"updates"| Figma

    subgraph "Build & Deployment"
        Webpack["webpack.config.js"]:::build
        Babel["babel.config.js"]:::build
        TSConfig["tsconfig.json"]:::build
        Package["package.json"]:::build
        PackageLock["package-lock.json"]:::build
    end
    Webpack -->|"buildsTo"| Manifest
    Babel -->|"buildsTo"| Manifest
    TSConfig -->|"compiles"| Code
    Package -->|"managesDeps"| Code
    PackageLock -->|"locksDeps"| Code

    subgraph "Testing Environment"
        TestDateTime["__tests__/dateTime.spec.js"]:::test
        TestVarTest["__tests__/varTest.spec.js"]:::test
    end
    TestDateTime -->|"tests"| DateTime
    TestVarTest -->|"tests"| VarTest
    TestDateTime -->|"tests"| Code
    TestVarTest -->|"tests"| Code

classDef figma fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
classDef plugin fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
classDef frontend fill:#fff9c4,stroke:#fbc02d,stroke-width:2px;
classDef backend fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px;
classDef external fill:#ffcdd2,stroke:#c62828,stroke-width:2px;
classDef build fill:#d1c4e9,stroke:#5e35b1,stroke-width:2px;
classDef test fill:#f8bbd0,stroke:#ad1457,stroke-width:2px;

click Manifest "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/manifest.json"
click UIHTML "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/src/ui.html"
click UITS "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/src/ui.ts"
click Code "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/src/code.ts"
click DateTime "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/src/date-time.ts"
click Fonts "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/src/fonts.ts"
click FormatText "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/src/format-text.ts"
click ReplaceText "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/src/replace-text.ts"
click VarTest "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/src/var-test.ts"
click AirtableRec "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/src/airtable/get-airtable-records.ts"
click AirtableConfig "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/src/airtable/get-set-airtable-config.ts"
click Webpack "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/webpack.config.js"
click Babel "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/babel.config.js"
click TSConfig "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/tsconfig.json"
click Package "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/package.json"
click PackageLock "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/package-lock.json"
click TestDateTime "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/__tests__/dateTime.spec.js"
click TestVarTest "https://github.com/imnotashrimp/copythat-airtable-figma/blob/develop/__tests__/varTest.spec.js"
```
