cmp-design-to-code
Skill0 starsChanged 3 days agoMITView on GitHub
Use when building or adjusting UI from a provided design in this Compose Multiplatform app — the exported design boards under design/ (dc.html files and canvas.json), the fonts and icons Compass prepared, a mockup or a screenshot — or when a screen must match its design more closely. Measure first, map every value to a theme token, build exactly what is shown, then check each value against the design.
In this repository20 other files it gives its agents.
- compass-kit/CLAUDE.mdCLAUDE.md
- unity-kit/CLAUDE.mdCLAUDE.md
- backend-new-projectSkill
- cmp-backendSkill
- cmp-code-rulesSkill
- cmp-commitSkill
- cmp-design-rulesSkill
- cmp-detektSkill
- cmp-featureSkill
- cmp-gatesSkill
- cmp-maestroSkill
- cmp-new-projectSkill
- cmp-testingSkill
- cmp-verifySkill
- game-balanceSkill
- game-briefSkill
- game-lookSkill
- game-new-projectSkill
- game-releaseSkill
- game-smokeSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 3 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
Search design/ recursively.
- Distinctive: line 29
Read every board of the screen you are building, all states included, before writing code.
- Very specific: line 32
Write a value table in your working notes, not in a file: element → value → source (read or estimated) → token or component.
- Very specific: line 100
Put the design's type scale into Typography(...): size, line height, weight and letter spacing per role.
- Very specific: line 114
Do not hard-code the board frame.
- Distinctive: line 134
Every size, colour and font in the diff traces to a table row, read or marked estimated.
- Distinctive: line 142
No pixel measurement with scripts.
- Very specific: line 144
Do not open the design URL.
- Very specific: line 148
Do not ask questions. Choose the closest reading of the design and list it under Assumptions.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Design to code
The design is the specification. Read values from it; never eyeball them. Code rules are in
cmp-code-rules, screen structure in cmp-feature.
1. What is in design/
Search design/ recursively; the boards may sit in a subfolder such as design/project/.
| File | What it is |
*.dc.html | One board per screen and state. Inline style attributes hold exact values: px sizes, hex colours, font family, weight, line height, letter spacing, radius, gaps. |
canvas.json | The board list: file name, title (usually Screen · state) and frame size. Use it to pair screens with their states. A board that shows the flow between screens tells you the navigation. |
| a style-guide board | Colour tokens and the type scale, when the design has one. Read it first. |
fonts/<family>_<weight>.ttf | The design's fonts, already downloaded (for example figtree_600.ttf). |
icons/<id>.xml | Android vector drawables, drawn black; tint them. License in icons/LICENSE-icons.txt. |
sounds/ | Sound effects, when the app has them. |
artifact-url.txt | Where the design was published. Do not open it: it needs a login. |
The <link> to Google Fonts and support.js in the HTML are for the browser; ignore them.
2. Extract
- Read every board of the screen you are building, all states included, before writing code.
- Machine-readable values (HTML, CSS, SVG, token files) are exact. Values taken from an image (a screenshot, a mockup) are estimates.
- Write a value table in your working notes, not in a file:
element → value → source (read or estimated) → token or component. The code must follow the table; the table is what you check against at the end.
CSS to Compose. The board frame (for example 390 × 844) is a phone in dp, so 1 CSS px = 1 dp and font px = sp.
| CSS | Compose |
width: 390px; height: 844px on the board root | the frame, never code it: fillMaxSize() |
padding: 52px 20px 14px (top, right/left, bottom) | padding(start = 20.dp, top = 52.dp, end = 20.dp, bottom = 14.dp) |
display: flex; flex-direction: column; gap: 8px | Column(verticalArrangement = Arrangement.spacedBy(8.dp)) |
display: flex (row), gap: 12px | Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) |
justify-content: space-between | Arrangement.SpaceBetween |
align-items: center | verticalAlignment = Alignment.CenterVertically (Row), horizontalAlignment = Alignment.CenterHorizontally (Column) |
flex: 1 | Modifier.weight(1f) |
width: 100% | fillMaxWidth() |
font-size: 15px; line-height: 22px; letter-spacing: 0.4px | fontSize = 15.sp, lineHeight = 22.sp, letterSpacing = 0.4.sp |
font-weight: 400 / 500 / 600 / 700 | FontWeight.Normal / Medium / SemiBold / Bold |
color: #9E2F45 | Color(0xFF9E2F45), defined in the theme |
rgba(255,255,255,0.16) | Color.White.copy(alpha = 0.16f) |
border-radius: 20px / 999px | RoundedCornerShape(20.dp) / CircleShape |
border: 1px solid #E8DCD3 | Modifier.border(1.dp, color, shape) |
box-shadow: ... | Modifier.shadow(elevation, shape); an estimate, mark it |
opacity: 0.6 | Modifier.alpha(0.6f) |
aria-hidden="true" | decorative: contentDescription = null |
3. Clarify
- The board titles name the states (content, empty, loading, error, dialog). Each board becomes a
UI state;
cmp-code-rulesrequires loading, empty and error even when the design leaves one out. - Interactive session: ask about what the design does not show (a missing state, overflow of long text, what a tap does).
- A choice the design leaves open and you must make (a derived state's colours): if
cmp-design-rulesis installed, follow it; the design's own values always win. - Headless run: derive a missing state from the boards that exist (same header, spacing and
colours) and list it under
Assumptions. Never fill a gap with your own "improvement". - The design's sample data (names, counts, prices) is sample data. Show real or fake data from the data layer, not the design's numbers hard-coded in the UI.
4. Ground in the theme
- Find the project's theme first.
shared/.../AppTheme.ktexists: the project was generated from the release that added it or later.MainScreenalready wraps the app inAppTheme { … }; never add a secondMaterialThemeor theme composable around theScaffold.- With Theming: the palette (
CustomColorsPalette,OnLightColorsPalette,OnDarkColorsPalette) andKtThemeare incore/designsystem/.../theme/.KtThemeprovidesLocalColorsPaletteand maps the palette toMaterialTheme.colorScheme(background/surface,onBackground/onSurface,onSurfaceVariant,primary,onPrimary,outline) incolorSchemeFor;AppTheme.ktapplies the user's Light/Dark/System choice through it. Add the design's colours to the palette class and both palettes, map them incolorSchemeForwhen a Material role fits, and put typography and shapes intoKtTheme'sMaterialTheme(...)call. - Without Theming:
AppTheme.ktis a plainMaterialThemethat follows the system with Material's baseline light and dark schemes. Put the colour scheme, typography and shapes there (lightColorScheme(primary = …)); a dark scheme only when the design shows one ("One colour mode shown" below). A design with one colour mode: use its scheme in both branches ofAppTheme(or drop theisSystemInDarkTheme()branch), and setwindow_backgroundin boththemes.xmlfiles (next bullet) to that scheme's background, or deletevalues-night/themes.xml. Otherwise a dark-mode device shows Material's dark scheme, or a dark launch window before a light app. - With or without Theming:
window_backgroundinandroidApp/src/main/res/values/themes.xml(light) andvalues-night/themes.xml(dark) is the Android window shown before the first frame. When you change the theme's background colour, update it in both files.
- With Theming: the palette (
- Projects without
AppTheme.kt: usecore/designsystem's palette (packagedarkmode) when the project was generated with it, or athemepackage that already exists. Otherwise create one incore/presentationunder athemepackage: colours, typography and a theme composable that wrapsMaterialTheme, applied once inshared/.../MainScreen.ktaround theScaffold(addimplementation(projects.core.presentation)toshared/build.gradle.ktsif it is missing). Name each file after the one type it declares. - Colours: every measured colour becomes a named token in the theme. Map it to a
MaterialTheme.colorSchemerole when one fits (primary, background, surface, onSurface, error, outline). Colours with no role go into a small@Immutabledata class provided through aCompositionLocal. Composables read tokens; no bareColor(0x...)underui/. detekt'sMagicNumberexempts thethemepackage, notui/(hex colours in awhenunderui/were reported in a measured run). - One colour mode shown in the design: use it and list that under
Assumptions. Do not invent a dark palette. - Fonts: copy the needed files from
design/fonts/intosrc/commonMain/composeResources/font/of the theme module (core/designsystemwithKtTheme,sharedwith a plainAppTheme.kt, else the module above). That module needsandroidResources.enable = true(cmp-feature,references/screen.md, "Resources"), or the Android app falls back to the system font while every gate stays green. Build the family in a@Composablefunction, becauseorg.jetbrains.compose.resources.Fontis composable:
@Composable
fun figtreeFamily(): FontFamily = FontFamily(
Font(Res.font.figtree_400, FontWeight.Normal),
Font(Res.font.figtree_600, FontWeight.SemiBold)
)Put the design's type scale into Typography(...): size, line height, weight and letter
spacing per role. Components use MaterialTheme.typography.x, not ad-hoc TextStyles.
- Icons: copy the ones the screen uses from
design/icons/intocomposeResources/drawable/of the module that shows them, and draw them withIcon(painterResource(Res.drawable.<id>), contentDescription = ..., tint = ...). Material icons are not on the classpath. - Texts shown in the design become string resources in every UI language (
cmp-code-rules, section 11). - Reuse components the project already has before writing new ones.
5. Build one to one
- Apply the table's values exactly. Add nothing the design does not show: no extra animation, shadow, gradient, divider or "nicer" spacing.
- Do not hard-code the board frame. Express proportions with
weight,fillMaxWidth(fraction)andArrangement.spacedBy; fixed sizes only for things that are fixed by nature (icons, avatars, button heights). The app runs on phones of many sizes on Android and iOS. - Boards usually draw no status bar, but their first element often has a large top padding
(around 44 to 60 px) that stands in for it. The generated
MainScreenpasses itsScaffoldpadding to theNavHost, so every screen already starts below the status bar. Do not add that space a second time: keep only the part that is real spacing and mark it as estimated. - Spacing written once inside a composable may stay inline (
20.dp); values repeated across screens become theme tokens.
6. Verify
- Headless run: go through the table and find each value in the code (
grepfor the hex value or the token). Every row is used, or its absence is listed. Then run the gates (cmp-gates). The visual comparison happens on the walkthrough video Compass records afterwards. - Interactive session: run the app, take a screenshot of each state and compare it with its board row by row. List what still differs.
Done when
- Every size, colour and font in the diff traces to a table row, read or marked estimated.
- Nothing appears that the design does not show; every state board has a matching UI state.
- The design's fonts and icons are used; no system font where the design names a family.
- Modules that received fonts or drawables enable Android resources.
- The final summary lists remaining differences, estimates and assumptions.
Headless runs
- No pixel measurement with scripts. Open images with the Read tool and mark every value taken from an image as estimated.
- Do not open the design URL; it needs a login this session does not have. Everything needed is
under
design/. - There is no internet: if a font family is not in
design/fonts/, use the theme's default and say so underAssumptions. - Do not ask questions. Choose the closest reading of the design and list it under
Assumptions.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

