How to create design systems from DESIGN.md

Upload a DESIGN.md file and create a design system from it programmatically with the SDK.

A DESIGN.md file defines your project’s visual identity in plain text — colors, typography, spacing, component patterns. The SDK lets you upload one and convert it into an actionable design system that Stitch applies to generated screens.

This is a two-step workflow: upload the file, then create the design system from it.

Upload a DESIGN.md

import { stitch } from "@google/stitch-sdk";
import { readFileSync } from "node:fs";

const project = stitch.project("your-project-id");
const markdown = readFileSync("DESIGN.md", "utf-8");
const instance = await project.uploadDesignMd(Buffer.from(markdown, "utf-8").toString("base64"));

The file content must be base64-encoded. Buffer.from(str, 'utf-8').toString('base64') handles this correctly for all UTF-8 strings, including non-ASCII characters. The response is a screen instance — you’ll pass it to the next step.

Create the design system

const ds = await project.createDesignSystemFromDesignMd(
  { id: instance.id, sourceScreen: instance.sourceScreen },
  "DESKTOP",
);
console.log(`Created design system: ${ds.id}`);

The selectedScreenInstance requires id and sourceScreen from the upload response. The deviceType is optional — use "DESKTOP", "MOBILE", "TABLET", or "AGNOSTIC".

Apply to screens

Once created, apply the design system to screens the same way as any other design system:

const projectData = await stitch.callTool("get_project", {
  name: `projects/${project.id}`,
});

const instances = projectData.screenInstances.map((si: any) => ({
  id: si.id,
  sourceScreen: si.sourceScreen,
}));

await ds.apply(instances);

Full workflow

import { stitch } from "@google/stitch-sdk";
import { readFileSync } from "node:fs";

const project = await stitch.createProject("Branded App");

// Generate screens first
const home = await project.generate("A landing page for a SaaS product");
const pricing = await project.generate("A pricing page with three tiers");

// Upload and create design system from DESIGN.md
const markdown = readFileSync("DESIGN.md", "utf-8");
const instance = await project.uploadDesignMd(Buffer.from(markdown, "utf-8").toString("base64"));
const ds = await project.createDesignSystemFromDesignMd(
  { id: instance.id, sourceScreen: instance.sourceScreen },
  "DESKTOP",
);

// Apply to all screens
const projectData = await stitch.callTool("get_project", {
  name: `projects/${project.id}`,
});
const screenInstances = projectData.screenInstances.map((si: any) => ({
  id: si.id,
  sourceScreen: si.sourceScreen,
}));
await ds.apply(screenInstances);
console.log("Design system from DESIGN.md applied to all screens");

Using callTool directly

If you prefer the low-level callTool API (useful for agent workflows):

const instance = await stitch.callTool("upload_design_md", {
  projectId: "your-project-id",
  designMdBase64: Buffer.from(markdown, "utf-8").toString("base64"),
});

const ds = await stitch.callTool("create_design_system_from_design_md", {
  projectId: "your-project-id",
  selectedScreenInstance: {
    id: instance.id,
    sourceScreen: instance.sourceScreen,
  },
  deviceType: "DESKTOP",
});

What’s next

Original: https://stitch.withgoogle.com/docs/sdk/design-md/

Translated from the official Google Stitch documentation. Original content © Google LLC. This is an independent, unofficial translation.