Skip to content

How to understand a Figma plugin codebase

A Figma plugin runs in two places: main thread code that can read and change the document through the `figma` API but has no DOM, and an optional UI in an iframe that has a DOM but no document access. They talk through messages.

How to tell it's Figma plugin

  • manifest.json with main, ui and api fields
  • figma.showUI(__html__) and figma.ui.onmessage
  • @figma/plugin-typings in devDependencies

Where things usually live

manifest.json
Plugin ID, entry files, editor types, network access.
src/code.ts
Main thread: document access and the figma API.
src/ui.tsx or ui.html
The iframe UI.
build config
Bundles both parts; the UI is often inlined into one HTML file.

Conventions, not rules. Real projects rename and move things, so confirm against the repository.

Where to start reading

  1. manifest.json
  2. code.ts, especially figma.ui.onmessage
  3. Where the UI posts messages

How a request moves through the code

  1. 1The user runs the plugin; Figma loads code.ts.
  2. 2The code calls figma.showUI to open the iframe.
  3. 3The UI sends parent.postMessage({ pluginMessage }) on user actions.
  4. 4figma.ui.onmessage receives it and changes the document.
  5. 5The code replies with figma.ui.postMessage to update the UI.

Questions to ask about the repository

  • List each message type exchanged between UI and main thread.
  • Which document changes does the plugin make?
  • Does it need network access, and to which domains?

What trips people up

  • Main thread code has no DOM, so document, window and browser-only libraries belong in the UI iframe.
  • Forgetting figma.closePlugin() leaves the plugin running.