--- name: integrate-magic-patterns-design description: Adapt code generated by Magic Patterns (magicpatterns.com) into an existing codebase. Use when the user shares a Magic Patterns design, prototype, exported zip, "Copy Code as Prompt" output, or a magicpatterns.com URL and wants it implemented, integrated, or productionized in their project. Treats the Magic Patterns code as a design spec, not as code to copy verbatim. --- # Integrate a Magic Patterns Design Magic Patterns generates **prototypes**. The code you receive is a high-fidelity design spec — it shows layout, hierarchy, spacing rhythm, interactions, and intent. It is NOT meant to be pasted into a codebase as-is. **The golden rule: when the Magic Patterns code and the target codebase disagree, the codebase wins.** Reproduce the *design*, not the exact code. Always prefer the codebase's existing components, design tokens, styling system, data layer, and conventions over the literal values in the prototype. ## What Magic Patterns code looks like Unless the design used a custom design system, expect: - React 18 + TypeScript, styled with **Tailwind CSS v3** utility classes - **lucide-react** icons, **framer-motion** animations, **react-router-dom** routing, **recharts** charts - Named exports (`export function PricingSection`), flat or shallow file structure (`components/`, `pages/`, `utils/`) - **Hardcoded mock data** — inline arrays/objects or a `utils/mockData.ts` - Placeholder images as full URLs (often Unsplash) - Stubbed interactivity: controlled inputs with local `useState`, `onSubmit` handlers that do nothing real, no API calls, no auth, no backend - Zip/GitHub exports are wrapped in a standalone Vite project (`vite.config.ts`, `index.html`, `src/`) Designs built on a design system preset (shadcn/ui, Chakra, Mantine, MUI) or a custom imported design system will use that library's components and theming instead of plain Tailwind. ## Workflow ### Step 1: Inventory the prototype Read all the Magic Patterns files first. Identify: - The actual design content: components, layout, screens, interactions, states (hover, empty, loading, error if present) - Mock data shapes — these hint at the real data model the UI expects - Which parts are scaffolding to discard (see checklist below) **Discard checklist** — never port these: - [ ] `index.tsx` / `index.html` / `vite.config.ts` / `tsconfig*.json` / `postcss.config.js` / `package.json` / `.eslintrc*` — Vite scaffolding; your project already has its own - [ ] `tailwind.config.js` and `index.css` — merge any genuinely new tokens into your existing config instead of replacing it - [ ] `canvas.manifest.js`, `useScreenInit.js` — Magic Patterns multi-screen plumbing; replace with your real router - [ ] `ComponentPreview.tsx`, `components.config.json`, `context.md` — editor preview files - [ ] `_designSystem/` folders and empty component stub files — precompiled design system bundles - [ ] `data-id` props on elements — editor instrumentation - [ ] `utils/mockData.ts` and inline mock data — replace with your real data layer ### Step 2: Survey the target codebase Before writing anything, learn how this codebase builds UI. Find: 1. **Framework and routing** — Next.js App Router? Pages Router? Remix? Plain Vite + react-router? Match its conventions for pages, layouts, links, and navigation. 2. **Component library** — Look for an existing `components/ui/`, design system package, or shared component folder. List the available primitives (Button, Input, Card, Dialog, Select, Badge, Table...). 3. **Styling system** — Tailwind (which version? v4 syntax differs from the v3 the prototype uses), CSS Modules, styled-components, vanilla-extract, a token system? Find the theme: colors, spacing, radii, typography, breakpoints. 4. **Icons** — Which icon library is already installed? Do not add lucide-react if the project uses something else. 5. **Data and state** — How does this codebase fetch data (React Query, SWR, server components, tRPC)? Where do types live? How are forms handled (react-hook-form, server actions)? 6. **Conventions** — Default vs named exports, file naming, folder placement, client/server component boundaries, i18n, accessibility patterns. An effective shortcut: find an existing page or feature in the codebase that is similar in shape to the new design, and use it as the structural template. ### Step 3: Map prototype pieces to codebase equivalents For every element in the prototype, prefer replacement over porting: | Prototype has | Do this | |---|---| | Hand-rolled `