Convert Stitch screen(s) to React components for: $ARGUMENTS
$ARGUMENTS should include:
- A Stitch project ID or screen ID, OR "list" to browse available projects
- The target page route (e.g., "homepage", "pathways", "content/books")
- Optionally: "tokens-only" to extract design tokens without building components
- Optionally: "all" to convert all screens in a project sequentially
- Empty — list projects and ask the user what to convert
Purpose
This skill takes a generated Stitch screen (HTML/CSS) and converts it into production React components that integrate with the project's six-layer type safety chain. It archives existing page implementations before replacing them, ensuring no work is lost.
Critical Rules
- NEVER overwrite existing components or pages. Always archive first (see Archive Protocol).
- NEVER hand-edit generated Layer 1-5 files. Use hooks from
src/hooks/simplified/ and src/hooks/custom/ as-is.
- Components consume hooks (Layer 5), never call APIs or services directly.
- Use semantic CSS classes only —
bg-primary, text-muted-foreground, etc. Never hardcode hex/rgb.
- Use shadcn/ui components —
Card, Button, Input, Badge, Tabs, etc. Never raw HTML with inline styles.
- Use
tenantConfig for any text that could vary per tenant. Never hardcode tenant strings.
- Push "use client" to leaf components only. Keep page.tsx as a Server Component.
- Follow the design chain: Tokens → Tailwind → Radix/shadcn → Domain components → Patterns → Pages.
Phase 0 — Pre-Flight Checks
Before any conversion work:
- Read the target page's current implementation (if it exists) to understand what hooks, data sources, and patterns are already in use.
- Read
src/app/globals.css to understand current design tokens.
- Read
src/lib/config/tenant.config.ts to understand tenant theming and feature flags.
- Read the Stitch screen via
mcp__stitch__get_screen to get the full HTML/CSS.
- Identify which database entities the page needs (e.g., homepage needs pathways, content items, courses). Map each to its Layer 5 hook file in
src/hooks/simplified/ or src/hooks/custom/.
Phase 1 — Archive Existing Page (Archive Protocol)
This phase is MANDATORY when a page already exists at the target route.
For a page file (page.tsx):
src/app/(public)/page.tsx → src/app/(public)/page-old.tsx (rename, remove default export)
The archived file should be renamed by appending -old before the extension. Remove or comment out the export default so Next.js doesn't conflict with the new page. Add a comment at the top:
// ARCHIVED: [date] — replaced by stitch-react conversion from Stitch screen [screen-id]
// This file is preserved for reference. Delete when the new implementation is verified.
For section components referenced by the page:
Do NOT archive individual section components (e.g., src/components/hero.tsx). The new page will import NEW components from a screen-specific directory. Old components remain untouched and available — they just won't be imported by the new page.
For pages with -old suffix already existing:
If page-old.tsx already exists, use page-old-2.tsx, page-old-3.tsx, etc. Never overwrite an archive.
What to record:
After archiving, note in your conversion report:
- What was archived and where
- Which hooks/data sources the old page used (carry forward to new implementation)
- Which section components the old page imported (for reference during conversion)
Phase 2 — Token Extraction
Extract design tokens from the Stitch HTML/CSS and map them to the project's existing token system.
What to extract:
| Stitch artifact |
Maps to |
Location |
| Color palette (backgrounds, text, accents) |
CSS custom properties |
src/app/globals.css (:root and .dark) |
| Font families |
Tailwind font config |
tailwind.config.ts |
| Font sizes / weights / line heights |
Tailwind type scale |
tailwind.config.ts or globals.css |
| Spacing rhythm (padding, gap, margin patterns) |
Tailwind spacing scale |
Note patterns, don't add custom tokens unless necessary |
| Border radius values |
--radius variable |
globals.css |
| Shadow patterns |
Tailwind shadow utilities |
Note patterns |
Rules for token updates:
- Only update tokens if the Stitch design meaningfully differs from current tokens. If the existing tokens are close enough, use them.
- Prefer mapping Stitch values to existing semantic tokens over adding new ones.
- If adding new CSS variables, follow the existing naming convention in globals.css (e.g.,
--card, --popover, --accent).
- Support both light and dark mode. If Stitch generated a dark-mode design, ensure light mode values also exist.
- Ask the user before changing existing token values — these affect the entire site.
Token-only mode:
If the user specified "tokens-only", stop after this phase and report the token mapping. This is useful for the first screen conversion to establish the design foundation before converting components.
Phase 3 — Component Decomposition Plan
Analyze the Stitch HTML and create a conversion plan BEFORE writing any code.
Step 1 — Identify sections
Break the Stitch screen into logical sections. For a homepage this might be:
- Hero
- Social proof / logos
- Pathways grid
- Content sampler
- AI Lab teaser
- Course CTA
- Newsletter signup
Step 2 — Map sections to components
For each section, determine:
| Section |
New component path |
shadcn/ui primitives used |
Data source (hook) |
Client or Server? |
| Hero |
src/components/home/hero.tsx |
Button |
tenantConfig (static) |
Server |
| Pathways |
src/components/home/pathways.tsx |
Card, Badge |
usePathwaysList |
Client |
| ... |
... |
... |
... |
... |
Step 3 — Identify data requirements
For each component that needs data:
- Check if a Layer 5 hook exists in
src/hooks/simplified/ or src/hooks/custom/
- If the hook exists, note the import path and the data shape it returns
- If NO hook exists, note what custom hook or data fetch is needed and flag it for the user
NEVER create new hooks, services, or API routes. If a hook doesn't exist, flag it and ask the user whether to:
- Use an existing hook with filtering
- Skip that section for now
- Run
/generate to create the missing layers first
Step 4 — Present the plan
Show the full conversion plan to the user and wait for approval before proceeding. The plan should include:
- Archive targets (what gets renamed)
- New component tree (file paths and hierarchy)
- Token changes (if any)
- Data source mapping (which hooks wire to which components)
- Anything that can't be converted (missing hooks, unsupported patterns)
Phase 4 — Build Components
After the user approves the plan, build components bottom-up (leaf components first, page composition last).
Component file structure:
src/components/[page-name]/
├── hero.tsx # Section component
├── pathways-grid.tsx # Section component
├── content-sampler.tsx # Section component
└── ...
For each component:
- Start from the Stitch HTML structure — preserve the semantic hierarchy (headings, sections, lists)
- Replace HTML elements with shadcn/ui equivalents:
<div class="card"> → <Card>, <CardHeader>, <CardContent>
<button> → <Button variant="...">
<input> → <Input>
- Tabs →
<Tabs>, <TabsList>, <TabsTrigger>, <TabsContent>
- Replace all colors with semantic tokens:
- Any background color →
bg-background, bg-card, bg-primary, bg-muted
- Any text color →
text-foreground, text-muted-foreground, text-primary
- Any border →
border-border, border-primary
- Replace hardcoded text with
tenantConfig where appropriate
- Wire data from hooks:
"use client";
import { useContentItemsList } from "@/hooks/simplified/content-items.hooks";
export function ContentSampler() {
const { data, isLoading, error } = useContentItemsList({
status: "published",
limit: 6
});
// Handle loading, error, and data states
}
- Handle all states — loading (skeleton/spinner), error (message + retry), empty (message + action)
- Preserve GSAP animations from the old components if they existed, or add subtle scroll reveals following the project's animation pattern
TypeScript requirements:
- Type all props explicitly
- Use types from Layer 2 schemas when referencing entity shapes:
import type { ContentItems } from "@/lib/schemas"
- Never use
any
Accessibility:
- Preserve heading hierarchy (h1 → h2 → h3, no skipping)
- All images need
alt text
- Interactive elements need visible focus states (shadcn handles this)
- Tap targets minimum 44x44px
Phase 5 — Compose the Page
Create the new page.tsx that imports and arranges all section components.
// src/app/(public)/page.tsx
import { Hero } from "@/components/home/hero";
import { PathwaysGrid } from "@/components/home/pathways-grid";
import { ContentSampler } from "@/components/home/content-sampler";
// ... etc
export default function HomePage() {
return (
<>
<Hero />
<PathwaysGrid />
<ContentSampler />
{/* ... */}
</>
);
}
Rules:
- Page file is a Server Component (no "use client")
- Section components that need data are Client Components (they have "use client")
- Static sections (hero with tenant config only) can be Server Components
- Check feature flags:
{tenantConfig.features.chat && <AILabTeaser />}
Phase 6 — Verification Checklist
After building, verify:
Report the checklist results to the user.
Phase 7 — Conversion Report
## Stitch → React Conversion Complete
### Screen
- **Stitch Project:** [project ID]
- **Stitch Screen:** [screen ID / name]
- **Target Route:** [e.g., / (homepage)]
### Archived
- `src/app/(public)/page.tsx` → `src/app/(public)/page-old.tsx`
### New Files Created
1. `src/app/(public)/page.tsx` — Page composition (Server Component)
2. `src/components/home/hero.tsx` — Hero section
3. `src/components/home/pathways-grid.tsx` — Pathways grid (Client)
4. ...
### Token Changes
- [List any globals.css or tailwind.config.ts changes, or "None"]
### Data Sources Wired
| Component | Hook | Entity |
|-----------|------|--------|
| PathwaysGrid | `usePathwaysList` | pathways |
| ContentSampler | `useContentItemsList` | content_items |
### Flagged Issues
- [Any missing hooks, unsupported patterns, or items needing manual attention]
### Next Steps
- Run `pnpm dev` and verify the page renders
- Compare visually with the Stitch screen
- Run `/design-audit` to check visual quality
- Run `/responsive-audit` to check breakpoints
- Delete `page-old.tsx` once verified
Multi-Screen Workflow
When converting multiple screens (e.g., "all"):
- Start with Homepage — establishes tokens and shared patterns
- Convert in the build order from the screen prompts doc (Homepage → Pathways Hub → Pathway Detail → Content Library → ...)
- Reuse shared components — if the homepage conversion created a
PathwaysGrid component, the Pathways Hub page should import and extend it, not duplicate it
- After each screen, verify before proceeding to the next
- Token extraction only happens once (first screen). Subsequent screens use the established tokens.
Anti-Patterns
- Never modify generated Layer 1-5 files (schema, Zod, services, routes, hooks). If something is missing, use
/generate or /validate first.
- Never create a new API route or service as part of a conversion. Flag the gap and let the user decide.
- Never copy Stitch CSS verbatim. Extract the design intent and express it through the project's token system.
- Never put all sections in one giant component. Decompose into focused section components.
- Never skip the archive step. Even if the current page "looks bad," it contains valuable context about data wiring and hooks.
- Never use arbitrary Tailwind values (
text-[#ff6b35], p-[37px]). Map to the token system.
- Never create component files in
src/components/ui/. That's reserved for shadcn primitives. Use src/components/[page-name]/ for page sections.
1---2name: stitch-react-23description: Convert Stitch screens to React components — extracts design tokens, decomposes HTML into shadcn/ui components, generates TypeScript types, wires Layer 5 hooks, and archives existing pages. Triggers on: Stitch React, component conversion, React conversion, HTML to React. NOT for: new React apps, API routes, services, or schema changes.4---56Convert Stitch screen(s) to React components for: $ARGUMENTS78$ARGUMENTS should include:9- A Stitch project ID or screen ID, OR "list" to browse available projects10- The target page route (e.g., "homepage", "pathways", "content/books")11- Optionally: "tokens-only" to extract design tokens without building components12- Optionally: "all" to convert all screens in a project sequentially13- Empty — list projects and ask the user what to convert1415---1617## Purpose1819This skill takes a generated Stitch screen (HTML/CSS) and converts it into production React components that integrate with the project's six-layer type safety chain. It archives existing page implementations before replacing them, ensuring no work is lost.2021## Critical Rules22231. **NEVER overwrite existing components or pages.** Always archive first (see Archive Protocol).242. **NEVER hand-edit generated Layer 1-5 files.** Use hooks from `src/hooks/simplified/` and `src/hooks/custom/` as-is.253. **Components consume hooks (Layer 5), never call APIs or services directly.**264. **Use semantic CSS classes only** — `bg-primary`, `text-muted-foreground`, etc. Never hardcode hex/rgb.275. **Use shadcn/ui components** — `Card`, `Button`, `Input`, `Badge`, `Tabs`, etc. Never raw HTML with inline styles.286. **Use `tenantConfig`** for any text that could vary per tenant. Never hardcode tenant strings.297. **Push "use client" to leaf components only.** Keep page.tsx as a Server Component.308. **Follow the design chain:** Tokens → Tailwind → Radix/shadcn → Domain components → Patterns → Pages.3132---3334## Phase 0 — Pre-Flight Checks3536Before any conversion work:37381. **Read the target page's current implementation** (if it exists) to understand what hooks, data sources, and patterns are already in use.392. **Read `src/app/globals.css`** to understand current design tokens.403. **Read `src/lib/config/tenant.config.ts`** to understand tenant theming and feature flags.414. **Read the Stitch screen** via `mcp__stitch__get_screen` to get the full HTML/CSS.425. **Identify which database entities the page needs** (e.g., homepage needs pathways, content items, courses). Map each to its Layer 5 hook file in `src/hooks/simplified/` or `src/hooks/custom/`.4344---4546## Phase 1 — Archive Existing Page (Archive Protocol)4748**This phase is MANDATORY when a page already exists at the target route.**4950### For a page file (`page.tsx`):51```52src/app/(public)/page.tsx → src/app/(public)/page-old.tsx (rename, remove default export)53```5455The archived file should be renamed by appending `-old` before the extension. Remove or comment out the `export default` so Next.js doesn't conflict with the new page. Add a comment at the top:5657```typescript58// ARCHIVED: [date] — replaced by stitch-react conversion from Stitch screen [screen-id]59// This file is preserved for reference. Delete when the new implementation is verified.60```6162### For section components referenced by the page:63Do NOT archive individual section components (e.g., `src/components/hero.tsx`). The new page will import NEW components from a screen-specific directory. Old components remain untouched and available — they just won't be imported by the new page.6465### For pages with `-old` suffix already existing:66If `page-old.tsx` already exists, use `page-old-2.tsx`, `page-old-3.tsx`, etc. Never overwrite an archive.6768### What to record:69After archiving, note in your conversion report:70- What was archived and where71- Which hooks/data sources the old page used (carry forward to new implementation)72- Which section components the old page imported (for reference during conversion)7374---7576## Phase 2 — Token Extraction7778Extract design tokens from the Stitch HTML/CSS and map them to the project's existing token system.7980### What to extract:81| Stitch artifact | Maps to | Location |82|-----------------|---------|----------|83| Color palette (backgrounds, text, accents) | CSS custom properties | `src/app/globals.css` (`:root` and `.dark`) |84| Font families | Tailwind font config | `tailwind.config.ts` |85| Font sizes / weights / line heights | Tailwind type scale | `tailwind.config.ts` or `globals.css` |86| Spacing rhythm (padding, gap, margin patterns) | Tailwind spacing scale | Note patterns, don't add custom tokens unless necessary |87| Border radius values | `--radius` variable | `globals.css` |88| Shadow patterns | Tailwind shadow utilities | Note patterns |8990### Rules for token updates:91- **Only update tokens if the Stitch design meaningfully differs from current tokens.** If the existing tokens are close enough, use them.92- **Prefer mapping Stitch values to existing semantic tokens** over adding new ones.93- **If adding new CSS variables, follow the existing naming convention** in globals.css (e.g., `--card`, `--popover`, `--accent`).94- **Support both light and dark mode.** If Stitch generated a dark-mode design, ensure light mode values also exist.95- **Ask the user before changing existing token values** — these affect the entire site.9697### Token-only mode:98If the user specified "tokens-only", stop after this phase and report the token mapping. This is useful for the first screen conversion to establish the design foundation before converting components.99100---101102## Phase 3 — Component Decomposition Plan103104Analyze the Stitch HTML and create a conversion plan BEFORE writing any code.105106### Step 1 — Identify sections107Break the Stitch screen into logical sections. For a homepage this might be:108- Hero109- Social proof / logos110- Pathways grid111- Content sampler112- AI Lab teaser113- Course CTA114- Newsletter signup115116### Step 2 — Map sections to components117For each section, determine:118119| Section | New component path | shadcn/ui primitives used | Data source (hook) | Client or Server? |120|---------|-------------------|---------------------------|--------------------|--------------------|121| Hero | `src/components/home/hero.tsx` | Button | tenantConfig (static) | Server |122| Pathways | `src/components/home/pathways.tsx` | Card, Badge | `usePathwaysList` | Client |123| ... | ... | ... | ... | ... |124125### Step 3 — Identify data requirements126For each component that needs data:1271. Check if a Layer 5 hook exists in `src/hooks/simplified/` or `src/hooks/custom/`1282. If the hook exists, note the import path and the data shape it returns1293. If NO hook exists, note what custom hook or data fetch is needed and flag it for the user130131**NEVER create new hooks, services, or API routes.** If a hook doesn't exist, flag it and ask the user whether to:132- Use an existing hook with filtering133- Skip that section for now134- Run `/generate` to create the missing layers first135136### Step 4 — Present the plan137Show the full conversion plan to the user and wait for approval before proceeding. The plan should include:138- Archive targets (what gets renamed)139- New component tree (file paths and hierarchy)140- Token changes (if any)141- Data source mapping (which hooks wire to which components)142- Anything that can't be converted (missing hooks, unsupported patterns)143144---145146## Phase 4 — Build Components147148After the user approves the plan, build components bottom-up (leaf components first, page composition last).149150### Component file structure:151```152src/components/[page-name]/153 ├── hero.tsx # Section component154 ├── pathways-grid.tsx # Section component155 ├── content-sampler.tsx # Section component156 └── ...157```158159### For each component:1601611. **Start from the Stitch HTML structure** — preserve the semantic hierarchy (headings, sections, lists)1622. **Replace HTML elements with shadcn/ui equivalents:**163 - `<div class="card">` → `<Card>`, `<CardHeader>`, `<CardContent>`164 - `<button>` → `<Button variant="...">`165 - `<input>` → `<Input>`166 - Tabs → `<Tabs>`, `<TabsList>`, `<TabsTrigger>`, `<TabsContent>`1673. **Replace all colors with semantic tokens:**168 - Any background color → `bg-background`, `bg-card`, `bg-primary`, `bg-muted`169 - Any text color → `text-foreground`, `text-muted-foreground`, `text-primary`170 - Any border → `border-border`, `border-primary`1714. **Replace hardcoded text with `tenantConfig`** where appropriate1725. **Wire data from hooks:**173 ```tsx174 "use client";175 import { useContentItemsList } from "@/hooks/simplified/content-items.hooks";176177 export function ContentSampler() {178 const { data, isLoading, error } = useContentItemsList({179 status: "published",180 limit: 6181 });182 // Handle loading, error, and data states183 }184 ```1856. **Handle all states** — loading (skeleton/spinner), error (message + retry), empty (message + action)1867. **Preserve GSAP animations** from the old components if they existed, or add subtle scroll reveals following the project's animation pattern187188### TypeScript requirements:189- Type all props explicitly190- Use types from Layer 2 schemas when referencing entity shapes: `import type { ContentItems } from "@/lib/schemas"`191- Never use `any`192193### Accessibility:194- Preserve heading hierarchy (h1 → h2 → h3, no skipping)195- All images need `alt` text196- Interactive elements need visible focus states (shadcn handles this)197- Tap targets minimum 44x44px198199---200201## Phase 5 — Compose the Page202203Create the new `page.tsx` that imports and arranges all section components.204205```tsx206// src/app/(public)/page.tsx207import { Hero } from "@/components/home/hero";208import { PathwaysGrid } from "@/components/home/pathways-grid";209import { ContentSampler } from "@/components/home/content-sampler";210// ... etc211212export default function HomePage() {213 return (214 <>215 <Hero />216 <PathwaysGrid />217 <ContentSampler />218 {/* ... */}219 </>220 );221}222```223224Rules:225- Page file is a **Server Component** (no "use client")226- Section components that need data are Client Components (they have "use client")227- Static sections (hero with tenant config only) can be Server Components228- Check feature flags: `{tenantConfig.features.chat && <AILabTeaser />}`229230---231232## Phase 6 — Verification Checklist233234After building, verify:235236- [ ] Old page archived as `page-old.tsx` with archive comment237- [ ] No old component files were overwritten or modified238- [ ] New page.tsx is a Server Component (no "use client")239- [ ] All data comes from Layer 5 hooks, never direct API calls240- [ ] No hardcoded colors — only semantic Tailwind classes241- [ ] No hardcoded tenant strings — uses `tenantConfig`242- [ ] All components use shadcn/ui primitives243- [ ] Loading, error, and empty states handled in every data-consuming component244- [ ] TypeScript types imported from Layer 2 schemas where needed245- [ ] Heading hierarchy is correct (one h1 per page, proper nesting)246- [ ] No new hooks, services, or API routes were created247248Report the checklist results to the user.249250---251252## Phase 7 — Conversion Report253254```markdown255## Stitch → React Conversion Complete256257### Screen258- **Stitch Project:** [project ID]259- **Stitch Screen:** [screen ID / name]260- **Target Route:** [e.g., / (homepage)]261262### Archived263- `src/app/(public)/page.tsx` → `src/app/(public)/page-old.tsx`264265### New Files Created2661. `src/app/(public)/page.tsx` — Page composition (Server Component)2672. `src/components/home/hero.tsx` — Hero section2683. `src/components/home/pathways-grid.tsx` — Pathways grid (Client)2694. ...270271### Token Changes272- [List any globals.css or tailwind.config.ts changes, or "None"]273274### Data Sources Wired275| Component | Hook | Entity |276|-----------|------|--------|277| PathwaysGrid | `usePathwaysList` | pathways |278| ContentSampler | `useContentItemsList` | content_items |279280### Flagged Issues281- [Any missing hooks, unsupported patterns, or items needing manual attention]282283### Next Steps284- Run `pnpm dev` and verify the page renders285- Compare visually with the Stitch screen286- Run `/design-audit` to check visual quality287- Run `/responsive-audit` to check breakpoints288- Delete `page-old.tsx` once verified289```290291---292293## Multi-Screen Workflow294295When converting multiple screens (e.g., "all"):2962971. **Start with Homepage** — establishes tokens and shared patterns2982. **Convert in the build order** from the screen prompts doc (Homepage → Pathways Hub → Pathway Detail → Content Library → ...)2993. **Reuse shared components** — if the homepage conversion created a `PathwaysGrid` component, the Pathways Hub page should import and extend it, not duplicate it3004. **After each screen**, verify before proceeding to the next3015. **Token extraction only happens once** (first screen). Subsequent screens use the established tokens.302303---304305## Anti-Patterns306307- **Never modify generated Layer 1-5 files** (schema, Zod, services, routes, hooks). If something is missing, use `/generate` or `/validate` first.308- **Never create a new API route or service** as part of a conversion. Flag the gap and let the user decide.309- **Never copy Stitch CSS verbatim.** Extract the design intent and express it through the project's token system.310- **Never put all sections in one giant component.** Decompose into focused section components.311- **Never skip the archive step.** Even if the current page "looks bad," it contains valuable context about data wiring and hooks.312- **Never use arbitrary Tailwind values** (`text-[#ff6b35]`, `p-[37px]`). Map to the token system.313- **Never create component files in `src/components/ui/`.** That's reserved for shadcn primitives. Use `src/components/[page-name]/` for page sections.