Design to Code
Purpose
Turn an approved visual source into maintainable code without relying on prose precision. Prefer structured inputs, small implementation passes, and screenshot-backed parity evidence.
Ownership Boundary
design-to-code owns work after design approval/handoff:
- implementation mapping and code changes
- extracting implementation details from approved visual sources
data-section anchors and section-level parity evidence
- visual repair, mismatch/debt notes, accepted deviations
Return to idea-to-design only when the approved source is missing/stale, scope changed, the handoff predates approval, or the user asks for a design change.
Input Priority
implementation-blueprint.json + page-matrix.json + component-blueprint.json + debt-ledger.json
- Visual IR / section contract (
visual-ir/<page-id>.json, visual-contracts/*, section crops)
- Approved design images / Figma context / persisted mockups
- Page briefs and prose notes
Prose briefs are supporting context, not the source of truth.
Fidelity Path
D2C has one default path: highest-fidelity-regeneration.
Use D2C only when converting or repairing against an approved visual source and the expected result is the highest practical design-source fidelity. Do not downgrade to quick, standard, or "structure-first" modes unless the user explicitly waives fidelity for that specific task.
For every visual D2C page/section:
- approved visual source is the source of truth; prose only supports it
- load the highest-fidelity references before coding, not after a mismatch appears
- extract executable section-level IR before implementation
- inventory visible text, icons, shapes, tokens, assets, and controls before coding; for mobile pages include icon anatomy, icon size tokens, and Iconify visual compensation
- implement from the inventory/IR, then generate left-design/right-live evidence
- any shortcut, placeholder, missing icon, or simplified asset is debt and must be named before showing the result
Required references for visual D2C work:
references/design-extraction-analysis-gate.md
references/full-page-regeneration-guard.md
references/high-fidelity-rules.md
references/section-driven-high-fidelity.md
references/executable-visual-ir.md
references/asset-atlas-generation.md when multiple related bitmap assets are needed
references/functional-component-handoff-guard.md when controls/forms/tabs/pickers affect behavior
Non-visual or minor project-convention edits should not use D2C and must not claim design parity.
Fidelity Kernel
These rules are always active for GPT Image 2/mockup work:
- approved visual source is the source of truth; prose only supports it
- preserve page type, section order, first-screen density, card/list/form anatomy, and action hierarchy
- preserve icon anatomy and icon size tokens: box size, glyph size, container/radius/color/alignment, and Iconify visual compensation must be explicit before L4/L5 claims
- for mobile H5 / phone-width work, preserve readability floors as part of fidelity; do not copy or generate tiny 10-12px-equivalent text for meaningful content just to match density
- do not convert list/detail/form/product pages into generic dashboards
- do not replace populated designs with empty states unless the source says so
- do not claim parity from DOM/text smoke alone; use screenshot or section evidence
- maintain or create lightweight Visual IR for the active page/section
- before strict visual repair, perform design extraction and analysis from the approved source; load
references/design-extraction-analysis-gate.md when fidelity depends on a screenshot/mockup
- for high-fidelity page rewrites, enrich Visual IR to executable section-level layout/asset/anatomy/token contracts before coding
- if visual repair keeps producing "similar but not restored", treat under-specified IR as the blocker and load
references/executable-visual-ir.md before more CSS
- generated media must match its final display role and aspect ratio; do not hide asset mismatch with
object-fit or background-position tricks
- atlas generation is for creation efficiency only; crop atlas outputs into independent files before implementation
- fix the largest 1-3 visual gaps per pass and record remaining debt
Default Workflow
- Intake: identify source of truth, target routes/files, framework constraints, current maturity target.
- Foundation: map tokens/shell/base components before page-specific polish.
- Coverage: make every in-scope route/page visibly present before deep fidelity work.
- Section Anchors: add stable
data-section markers for key sections.
- Fidelity Loop: compare source vs implementation by section; fix the largest 1-3 gaps per pass.
- Handoff: report page maturity, evidence, debt, and deviations.
Highest-Fidelity Gate
Before coding any visual D2C page/section, the required references above must be loaded and applied. Section-level executable IR is mandatory: each major section needs bbox/height or density, component anatomy, text/icon/shape inventory, token targets including mobile typography floors, media/asset role, crop strategy, text safe areas, screenshot target, pass criteria, and must-not-substitute rules.
If any required field is missing, stop and enrich the IR/brief before changing code.
Asset Strategy Kernel
Use generated media by role:
| role |
strategy |
| hero main visual |
generate as an independent asset |
| CTA/banner background |
generate as an independent asset |
| repeated card thumbnails |
atlas generation allowed, then crop to independent files |
| application/factory scene groups |
atlas generation allowed, then crop to independent files |
| certificates, logos, nav, buttons, labels |
render with HTML/CSS/SVG/Iconify; do not bake into images |
Hard rule: an atlas is never a production UI asset. Final code must reference the cropped output files, not use CSS background-position against the atlas to fake separate images.
Visual IR Minimum
Use or create a lightweight Visual IR for PNG/GPT Image 2/mockup sources when fidelity matters:
{
"page_id": "application-list",
"route": "/pages/applications/index",
"viewport": [390, 844],
"page_type": "list",
"source_refs": ["design-to-code-inputs/mockup.png"],
"sections": [
{"name": "topbar", "order": 1, "bbox": [0,0,390,72]},
{"name": "card-list", "order": 4, "density": "2.5 cards visible"}
],
"section_anchors": ["topbar", "card-list"],
"must_not_do": ["do not replace list with dashboard"]
}
Do not over-model every pixel. Capture page type, section order, bbox, first-screen density, card/list anatomy, action hierarchy, must-not-do, and asset strategy.
Required Output Evidence
For each meaningful checkpoint, report:
- route/page coverage
- maturity level: L0 route-ready, L1 skeleton, L2 content, L3 system-styled, L4 core-fidelity, L5 functional
- section parity: PASS/WARN/FAIL for major sections when fidelity is claimed
- largest remaining visual gaps and whether they are debt or accepted deviation
- verification actually run; do not claim checks that were skipped
Hard Rules
- Do not claim design parity from DOM/text smoke alone.
- Do not replace populated designs with empty states unless the design/source says so.
- Do not convert list/detail/form pages into generic dashboards.
- Do not run broad lint/type/build repeatedly during active visual editing unless a failure signal or gate requires it.
- Do not handwave “close enough”; record section-level debt.
- Do not invent visual effects or decorative assets beyond the approved source; when strict detail is needed, load
references/high-fidelity-rules.md.
- Functional controls must follow existing project/UI-library patterns first; load
IdeaToTech only when API/state/permission/cross-platform/verification risk is non-trivial.
Mandatory Reference Loading
For visual D2C work, load these before coding; they are not optional or deferred:
references/high-fidelity-rules.md — exactness, text/icon/shape inventory, asset/layer rules, functional-control escalation
references/design-extraction-analysis-gate.md — design extraction from screenshots/mockups into section IR, component anatomy, asset roles, token targets, must-not-substitute rules, and pass criteria
references/full-page-regeneration-guard.md — complete-page token table, text inventory, icon anatomy, asset grouping map, and section-level asset plan
references/section-driven-high-fidelity.md — section-by-section restoration and strict visual repair
references/executable-visual-ir.md — executable section-level layout/asset/anatomy/token contracts
references/asset-atlas-generation.md — when multiple related bitmap assets are present or may be needed
references/functional-component-handoff-guard.md — when controls/forms/tabs/pickers affect behavior
references/blueprint-driven-implementation.md — when project blueprint files exist
references/visual-measurements.md — extracting sizes, colors, density
references/width-normalization.md — canonical page width, responsive/H5 viewport metrics, and real mobile screenshot evidence
references/mobile-recomposition.md — when desktop/PC-only sources must become mobile
references/playwright-section-diff.md — screenshot comparison and Mobile H5 visual audit pack
references/main-skill-full-reference.md — if the compact guide is insufficient
Common Pitfalls
| Pitfall |
Fix |
| Implementing from prose only |
Build/read Visual IR and source crops |
| Broad route smoke treated as visual pass |
Require section screenshots for parity claims |
| Reusing a dashboard template everywhere |
Preserve page type and first-screen anatomy |
| Pixel-chasing before coverage |
Cover routes first, then L4/L5 selected pages |
| Coding starts before extracting design |
Stop; run design extraction and analysis, then write executable IR before implementation |
| IR only names sections |
Add executable IR: bbox/height, density, component anatomy, asset role, token targets, pass criteria, and must-not-substitute rules |
| Repeated CSS tuning still feels unlike source |
Stop coding; classify mismatch as asset/structure/anatomy/token/verification and enrich references/executable-visual-ir.md fields first |
| Using one generated atlas as many CSS backgrounds |
Crop atlas into independent files and reference cropped assets only |
| Hero/banner mixed into thumbnail atlas |
Generate hero/CTA as independent assets with final safe areas |
1---2name: design-to-code3description: Use when converting approved design sources, handoff packages, mockups, visual contracts, or UI blueprints into implementation code and visual parity evidence; also when visual implementation feels rough, stretched, under-specified, or needs section-level high-fidelity repair.4---56# Design to Code78## Purpose910Turn an approved visual source into maintainable code without relying on prose precision. Prefer structured inputs, small implementation passes, and screenshot-backed parity evidence.1112## Ownership Boundary1314`design-to-code` owns work after design approval/handoff:15- implementation mapping and code changes16- extracting implementation details from approved visual sources17- `data-section` anchors and section-level parity evidence18- visual repair, mismatch/debt notes, accepted deviations1920Return to `idea-to-design` only when the approved source is missing/stale, scope changed, the handoff predates approval, or the user asks for a design change.2122## Input Priority23241. `implementation-blueprint.json` + `page-matrix.json` + `component-blueprint.json` + `debt-ledger.json`252. Visual IR / section contract (`visual-ir/<page-id>.json`, `visual-contracts/*`, section crops)263. Approved design images / Figma context / persisted mockups274. Page briefs and prose notes2829Prose briefs are supporting context, not the source of truth.3031## Fidelity Path3233D2C has one default path: **highest-fidelity-regeneration**.3435Use D2C only when converting or repairing against an approved visual source and the expected result is the highest practical design-source fidelity. Do not downgrade to `quick`, `standard`, or "structure-first" modes unless the user explicitly waives fidelity for that specific task.3637For every visual D2C page/section:38- approved visual source is the source of truth; prose only supports it39- load the highest-fidelity references before coding, not after a mismatch appears40- extract executable section-level IR before implementation41- inventory visible text, icons, shapes, tokens, assets, and controls before coding; for mobile pages include icon anatomy, icon size tokens, and Iconify visual compensation42- implement from the inventory/IR, then generate left-design/right-live evidence43- any shortcut, placeholder, missing icon, or simplified asset is debt and must be named before showing the result4445Required references for visual D2C work:46- `references/design-extraction-analysis-gate.md`47- `references/full-page-regeneration-guard.md`48- `references/high-fidelity-rules.md`49- `references/section-driven-high-fidelity.md`50- `references/executable-visual-ir.md`51- `references/asset-atlas-generation.md` when multiple related bitmap assets are needed52- `references/functional-component-handoff-guard.md` when controls/forms/tabs/pickers affect behavior5354Non-visual or minor project-convention edits should not use D2C and must not claim design parity.5556## Fidelity Kernel5758These rules are always active for GPT Image 2/mockup work:59- approved visual source is the source of truth; prose only supports it60- preserve page type, section order, first-screen density, card/list/form anatomy, and action hierarchy61- preserve icon anatomy and icon size tokens: box size, glyph size, container/radius/color/alignment, and Iconify visual compensation must be explicit before L4/L5 claims62- for mobile H5 / phone-width work, preserve readability floors as part of fidelity; do not copy or generate tiny 10-12px-equivalent text for meaningful content just to match density63- do not convert list/detail/form/product pages into generic dashboards64- do not replace populated designs with empty states unless the source says so65- do not claim parity from DOM/text smoke alone; use screenshot or section evidence66- maintain or create lightweight Visual IR for the active page/section67- before strict visual repair, perform design extraction and analysis from the approved source; load `references/design-extraction-analysis-gate.md` when fidelity depends on a screenshot/mockup68- for high-fidelity page rewrites, enrich Visual IR to executable section-level layout/asset/anatomy/token contracts before coding69- if visual repair keeps producing "similar but not restored", treat under-specified IR as the blocker and load `references/executable-visual-ir.md` before more CSS70- generated media must match its final display role and aspect ratio; do not hide asset mismatch with `object-fit` or background-position tricks71- atlas generation is for creation efficiency only; crop atlas outputs into independent files before implementation72- fix the largest 1-3 visual gaps per pass and record remaining debt7374## Default Workflow75761. **Intake**: identify source of truth, target routes/files, framework constraints, current maturity target.772. **Foundation**: map tokens/shell/base components before page-specific polish.783. **Coverage**: make every in-scope route/page visibly present before deep fidelity work.794. **Section Anchors**: add stable `data-section` markers for key sections.805. **Fidelity Loop**: compare source vs implementation by section; fix the largest 1-3 gaps per pass.816. **Handoff**: report page maturity, evidence, debt, and deviations.8283## Highest-Fidelity Gate8485Before coding any visual D2C page/section, the required references above must be loaded and applied. Section-level executable IR is mandatory: each major section needs bbox/height or density, component anatomy, text/icon/shape inventory, token targets including mobile typography floors, media/asset role, crop strategy, text safe areas, screenshot target, pass criteria, and must-not-substitute rules.8687If any required field is missing, stop and enrich the IR/brief before changing code.8889## Asset Strategy Kernel9091Use generated media by role:9293| role | strategy |94|---|---|95| hero main visual | generate as an independent asset |96| CTA/banner background | generate as an independent asset |97| repeated card thumbnails | atlas generation allowed, then crop to independent files |98| application/factory scene groups | atlas generation allowed, then crop to independent files |99| certificates, logos, nav, buttons, labels | render with HTML/CSS/SVG/Iconify; do not bake into images |100101Hard rule: an atlas is never a production UI asset. Final code must reference the cropped output files, not use CSS `background-position` against the atlas to fake separate images.102103## Visual IR Minimum104105Use or create a lightweight Visual IR for PNG/GPT Image 2/mockup sources when fidelity matters:106107```json108{109 "page_id": "application-list",110 "route": "/pages/applications/index",111 "viewport": [390, 844],112 "page_type": "list",113 "source_refs": ["design-to-code-inputs/mockup.png"],114 "sections": [115 {"name": "topbar", "order": 1, "bbox": [0,0,390,72]},116 {"name": "card-list", "order": 4, "density": "2.5 cards visible"}117 ],118 "section_anchors": ["topbar", "card-list"],119 "must_not_do": ["do not replace list with dashboard"]120}121```122123Do not over-model every pixel. Capture page type, section order, bbox, first-screen density, card/list anatomy, action hierarchy, must-not-do, and asset strategy.124125## Required Output Evidence126127For each meaningful checkpoint, report:128- route/page coverage129- maturity level: L0 route-ready, L1 skeleton, L2 content, L3 system-styled, L4 core-fidelity, L5 functional130- section parity: PASS/WARN/FAIL for major sections when fidelity is claimed131- largest remaining visual gaps and whether they are debt or accepted deviation132- verification actually run; do not claim checks that were skipped133134## Hard Rules135136- Do not claim design parity from DOM/text smoke alone.137- Do not replace populated designs with empty states unless the design/source says so.138- Do not convert list/detail/form pages into generic dashboards.139- Do not run broad lint/type/build repeatedly during active visual editing unless a failure signal or gate requires it.140- Do not handwave “close enough”; record section-level debt.141- Do not invent visual effects or decorative assets beyond the approved source; when strict detail is needed, load `references/high-fidelity-rules.md`.142- Functional controls must follow existing project/UI-library patterns first; load `IdeaToTech` only when API/state/permission/cross-platform/verification risk is non-trivial.143144## Mandatory Reference Loading145146For visual D2C work, load these before coding; they are not optional or deferred:147- `references/high-fidelity-rules.md` — exactness, text/icon/shape inventory, asset/layer rules, functional-control escalation148- `references/design-extraction-analysis-gate.md` — design extraction from screenshots/mockups into section IR, component anatomy, asset roles, token targets, must-not-substitute rules, and pass criteria149- `references/full-page-regeneration-guard.md` — complete-page token table, text inventory, icon anatomy, asset grouping map, and section-level asset plan150- `references/section-driven-high-fidelity.md` — section-by-section restoration and strict visual repair151- `references/executable-visual-ir.md` — executable section-level layout/asset/anatomy/token contracts152- `references/asset-atlas-generation.md` — when multiple related bitmap assets are present or may be needed153- `references/functional-component-handoff-guard.md` — when controls/forms/tabs/pickers affect behavior154- `references/blueprint-driven-implementation.md` — when project blueprint files exist155- `references/visual-measurements.md` — extracting sizes, colors, density156- `references/width-normalization.md` — canonical page width, responsive/H5 viewport metrics, and real mobile screenshot evidence157- `references/mobile-recomposition.md` — when desktop/PC-only sources must become mobile158- `references/playwright-section-diff.md` — screenshot comparison and Mobile H5 visual audit pack159- `references/main-skill-full-reference.md` — if the compact guide is insufficient160161## Common Pitfalls162163| Pitfall | Fix |164|---|---|165| Implementing from prose only | Build/read Visual IR and source crops |166| Broad route smoke treated as visual pass | Require section screenshots for parity claims |167| Reusing a dashboard template everywhere | Preserve page type and first-screen anatomy |168| Pixel-chasing before coverage | Cover routes first, then L4/L5 selected pages |169| Coding starts before extracting design | Stop; run design extraction and analysis, then write executable IR before implementation |170| IR only names sections | Add executable IR: bbox/height, density, component anatomy, asset role, token targets, pass criteria, and must-not-substitute rules |171| Repeated CSS tuning still feels unlike source | Stop coding; classify mismatch as asset/structure/anatomy/token/verification and enrich `references/executable-visual-ir.md` fields first |172| Using one generated atlas as many CSS backgrounds | Crop atlas into independent files and reference cropped assets only |173| Hero/banner mixed into thumbnail atlas | Generate hero/CTA as independent assets with final safe areas |