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.jsonwithmain,uiandapifieldsfigma.showUI(__html__)andfigma.ui.onmessage@figma/plugin-typingsindevDependencies
Where things usually live
- manifest.json
- Plugin ID, entry files, editor types, network access.
- src/code.ts
- Main thread: document access and the
figmaAPI. - 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
manifest.jsoncode.ts, especiallyfigma.ui.onmessage- Where the UI posts messages
How a request moves through the code
- The user runs the plugin; Figma loads
code.ts. - The code calls
figma.showUIto open the iframe. - The UI sends
parent.postMessage({ pluginMessage })on user actions. figma.ui.onmessagereceives it and changes the document.- The code replies with
figma.ui.postMessageto 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,windowand browser-only libraries belong in the UI iframe. - Forgetting
figma.closePlugin()leaves the plugin running.