Figma to code
Skill tungnt1405/tungnt-ai-skills-marketplace/skills/figma-to-code
Translates exactly one selected Figma frame, component, or instance into production-ready frontend code with deterministic extraction, design-token mapping, component reuse, and visual validation. Use only when the user explicitly invokes figma-to-code, asks to implement UI code from Figma, or when ba-spec needs Figma implementation guidance for a Figma-related feature spec. Do not use for BA-only specs, Figma evidence logs, or editing the Figma canvas itself.From its SKILL.md
npx -y skills add tungnt1405/tungnt-ai-skills-marketplace --skill figma-to-codeAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
10.4 KB, as published. Nobody here has run it
Figma implement fidelity
Purpose
Implement frontend UI from Figma with repeatable 1:1 visual fidelity. The agent must not code directly from a raw MCP dump. It must first create a deterministic design snapshot and normalized IR, then generate code from that IR and validate the result against a Figma screenshot.
Manual Activation Only Or Invoked By BA-SPEC
Use this skill only when the user explicitly calls figma-to-code or (brainstorming or ba-spec) invokes it to assist in reading Figma.
Do not run at install time. Do not auto-process during session bootstrap.
Manual utility only or invoked by (brainstorming or ba-spec). Not a process skill. This is a domain skill for handling Figma snapshots or designs in specific Figma paths for system documentation.
When to use
Use this skill only when:
- The user explicitly invokes
figma-to-code. - The deliverable is application code, not edits inside Figma.
- The user asks to implement, generate, convert, or match a Figma design/component/screen/modal.
- (
brainstormingorba-spec) is already active, the input is Figma-related, and developer handoff needs UI implementation guidance from a Figma source. - Visual fidelity, exact spacing, typography, colors, and layout consistency matter.
Do not use this skill when:
- The request is BA-only spec generation, Figma evidence logging, or PO/QA handoff without UI code guidance.
- The user wants to create or modify nodes in Figma itself.
- The input is only a vague UI description with no Figma source.
- The user asks only for design critique or copy changes.
- Unable to read Figma images or unable to get information from Figma links.
- Missing MCP or tools to support reading from Figma.
When the skill encounters an issue making it unusable, immediately notify the user of what the problem is, for example: if missing MCP support, notify "Please install the figma-mcp-go MCP to use this skill effectively." or if figma-mcp-go MCP is installed but not connected, "Check your connection to figma-mcp-go, currently unable to connect to MCP." and any skills calling it MUST also be required to stop because the figma-to-code skill is experiencing issues due to missing supporting tools or inability to read information sent from the user, so it must wait for the user to check and confirm.
Hard rules
- Work from exactly one target node: a selected
FRAME,COMPONENT,COMPONENT_SET, orINSTANCE. - Never implement from full
get_documentoutput unless debugging. Full document dumps often include sibling frames, off-canvas variants, and hidden layers. - Always produce a snapshot directory before coding.
- Always run
scripts/extract_figma_ir.pybefore the agent reads the raw MCP output in detail. - Generate code from
figma-ir.json, not directly from raw MCP JSON. - Treat Figma screenshot as the visual source of truth for validation, not as the only implementation source.
- Ignore hidden nodes, opacity-zero nodes, off-canvas sibling frames, and nodes outside the selected target bounds unless explicitly needed as overlays/assets.
- Reuse project components and design tokens before creating raw HTML/CSS primitives.
- Use absolute positioning only for icons, decorative vectors, and intentional overlays. Use flex/grid for forms, lists, cards, headers, footers, and main layout.
- Validate rendered UI with screenshot comparison before declaring completion.
- On Windows, run Python commands with
python -X utf8. - Do not inspect raw Figma JSON with
json.load(open(path)). Usescripts/extract_figma_ir.py, or usePath(path).read_text(encoding="utf-8-sig")for any quick JSON inspection. - Take flat colors, text, fonts, sizes, radius, and coordinates from JSON (
styles.fills/styles.strokes/characters/fontFamily...). Do NOT eyeball them from the screenshot when JSON has them. - Use the screenshot to RECOVER what JSON cannot express: gradients (JSON gives one flat fill), empty
styles:{}on a visible node, andfills:"mixed"(multiple colors in one node, e.g. label + red*). Seereferences/color-and-icon-extraction.md. - Icons: JSON gives stroke/fill HEX but no usable path
d. Either export the icon node as SVG (save_screenshotsformat:"SVG") for exact paths, or recreate a matching line-icon and color it from the JSON hex. Record which. - Capture screenshots with
save_screenshotsto disk (PNG for visual checks + SVG for icon paths). Avoidget_screenshotfor full frames — its inline base64 often exceeds the tool-result token limit.
Required workflow
1. Resolve the target
If a Figma URL is provided, extract the exact node-id. If only desktop Figma is available, call the selection tool first.
Reject ambiguous targets:
- Multiple top-level selected nodes.
- A page/canvas/document root instead of a frame/component.
- A parent frame that contains many unrelated screens.
If there is ambiguity, choose the most specific selected frame or component. Do not crawl unrelated siblings.
2. Fetch focused design context
Preferred MCP sequence for figma-mcp-go style tools:
get_selectionget_design_contextfor the selected node, compact firstget_nodefor the selected node only when deeper details are requiredget_stylesget_variable_defsget_fontsexport_tokenssave_screenshotsfor the same node — write PNG (visual) + SVG (icon paths) to the snapshot dir. Prefer this overget_screenshot, whose inline base64 often exceeds the tool-result token limit for a full frame.
Avoid get_document for implementation. If a response is truncated, fetch smaller child nodes by ID rather than broadening scope.
3. Save a deterministic snapshot
Create:
.design-snapshots/<feature-name>/
raw-output.json
screenshot.png
tokens.json
styles.json
fonts.json
component-registry.json
figma-ir.json
4. Run the extractor before reading raw output
Run:
python -X utf8 skills/figma-to-code/scripts/extract_figma_ir.py \
--input .design-snapshots/<feature-name>/raw-output.json \
--out .design-snapshots/<feature-name>/figma-ir.json \
--target-node-id <nodeId>
If the target node ID is unknown, run the extractor without --target-node-id to get a candidate summary, then re-run with the chosen target.
On Windows, never inspect JSON with the default encoding:
# Do not use this:
python -c "import json; data=json.load(open('.design-snapshots/<feature-name>/raw-output.json')); print(data.keys())"
# Use this instead:
python -X utf8 -c "import json, pathlib; p=pathlib.Path(r'.design-snapshots/<feature-name>/raw-output.json'); data=json.loads(p.read_text(encoding='utf-8-sig')); c=(data.get('context') or [data])[0]; print(c.get('id'), c.get('type'), c.get('name'))"
5. Inspect the IR summary
Before coding, read only:
summarylayout.columnslayout.sectionstokenssemanticNodeswarnings
Only open raw output when IR has warnings that require source verification.
6. Map to project conventions
Check the repository before creating new primitives:
- Existing
Button,Input,Select,Dialog,Modal,Card,Table,Typography,Icon,FormFieldcomponents. - CSS variable names, Tailwind config, design token files, theme provider, and font imports.
- Routing, data fetching, validation, and state management conventions.
Use examples/component-registry.example.json as the registry format if the repo does not already have one.
7. Generate code
Implementation priorities:
- Semantic structure: modal/header/body/footer, form sections, form rows, fields, actions.
- Layout: columns, rows, gaps, padding, width/height from IR.
- Typography: font family, size, weight, line height.
- Colors, borders, radius, shadows, opacity — flat values from JSON; resolve gradients / empty
styles:{}/fills:"mixed"from the screenshot perreferences/color-and-icon-extraction.md. - Assets/icons: export the icon node as SVG for exact paths, or recreate a line-icon colored from the JSON hex (JSON has icon color but no usable path
d). - Responsive behavior from constraints/auto-layout patterns.
Do not copy hidden-node styles into global CSS.
8. Validate visually
Render the result and capture a screenshot (Playwright, the repo's visual test tool, or headless Chrome --headless --screenshot). When rendering a local file, pass a file:// URL — a bare index.html is parsed as a hostname and fails to load. Compare with the Figma reference:
- Layout: x/y/width/height/gap differences.
- Typography: font family, size, weight, line-height.
- Color: fill/stroke/text/background.
- Radius/shadow/opacity.
- Missing/extra nodes.
Iterate until the major mismatches are fixed. If exact parity is impossible, document why.
Common failure modes to prevent
- Raw MCP output includes unrelated sibling frames and the agent copies their styles.
- Parser generated by the agent changes every run.
- Hidden variants leak styles into visible elements.
- Vector rectangles are treated as semantic containers without grouping.
- The agent creates absolute-positioned layouts for forms that should be flex/grid.
- Figma MCP output is treated as final React/Tailwind instead of a design reference.
- Screenshot is used without metadata, causing guessed spacing and typography.
- A gradient or empty-
stylesnode is shipped as the wrong flat color because the screenshot was never consulted. - Icon shapes are invented from imagination instead of exported SVG or a matched line-icon colored from the JSON hex.
Example prompt
Implement the selected Figma node in this repo using the figma-to-code skill.
Requirements:
- Use the exact selected frame/component only.
- Run the extractor before reading raw MCP output in detail.
- Generate code from figma-ir.json, not raw output.
- Reuse existing Button/Input/Select/Modal/FormField components.
- Use project tokens where possible.
- Validate against the Figma screenshot with Playwright and fix visible mismatches.