Drop a screenshot, get React code instantly. Built with Next.js, Tailwind CSS, and Monaco Editor.
- 📸 Image Upload — Drag & drop or select screenshots
- 🤖 AI-Powered — Converts UI screenshots to React + Tailwind code
- 💻 Live Editor — Monaco Editor for tweaking generated code
- 👁️ Instant Preview — See your component render in real-time
- 📋 One-Click Copy — Copy code to clipboard instantly
Try it live: screenshot-to-code-demo.vercel.app
- Framework: Next.js 16 (App Router)
- Styling: Tailwind CSS + shadcn/ui
- Editor: Monaco Editor (@monaco-editor/react)
- Icons: Lucide React
- AI: OpenAI GPT-4 Vision API (optional)
git clone https://github.com/yourusername/screenshot-to-code.git
cd screenshot-to-code/my-app
npm installnpm run devnpm run buildThe demo uses mock responses. To add real AI:
-
Get OpenAI API key: platform.openai.com
-
Create
.env.local:
OPENAI_API_KEY=sk-your-key-here- Update API Route (
app/api/generate/route.ts):
Uncomment the OpenAI integration code and remove the mock responses.
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
// In POST handler:
const response = await openai.chat.completions.create({
model: "gpt-4-vision-preview",
messages: [
{
role: "user",
content: [
{
type: "text",
text: "Generate React + Tailwind CSS code for this UI screenshot. Return only the component code, no explanations."
},
{
type: "image_url",
image_url: { url: image }
}
]
}
]
});
const generatedCode = response.choices[0]?.message?.content || '';- Upload — User drops a UI screenshot
- Analyze — Image sent to GPT-4 Vision API
- Generate — AI returns React + Tailwind code
- Edit — User tweaks code in Monaco Editor
- Preview — Code renders live in an iframe
- Export — Copy code or download component
my-app/
├── app/
│ ├── api/
│ │ └── generate/ # AI generation endpoint
│ │ └── route.ts
│ ├── globals.css
│ ├── layout.tsx
│ └── page.tsx # Main UI
├── components/
│ └── ui/ # shadcn components
├── lib/
│ └── utils.ts
├── public/
├── next.config.ts
├── package.json
└── README.md
Edit app/api/generate/route.ts and add to MOCK_COMPONENTS:
const MOCK_COMPONENTS: Record<string, string> = {
"your-component": `export default function YourComponent() {
return (
<div>Your code here</div>
);
}`,
// ...existing components
};In app/page.tsx, modify the Editor component:
<Editor
theme="vs-light" // or "vs-dark", "hc-black"
// ...
/>The app uses a dark theme by default. To change:
- Edit
app/globals.cssfor CSS variables - Modify the main div class in
app/page.tsx
npm i -g vercel
vercel --prod- Push to GitHub
- Connect Coolify to repo
- Set build command:
npm run build - Set output directory:
dist
npm run build
# Output in ./dist folderGenerates React code from a screenshot.
Request:
{
"image": "data:image/png;base64,iVBORw0KGgo..."
}Response:
{
"success": true,
"code": "export default function Component() { ... }",
"message": "Code generated successfully"
}- Multiple framework support (Vue, Svelte, Angular)
- Component library detection (shadcn, Chakra, Material)
- Figma plugin integration
- Batch processing (multiple screenshots)
- Export to CodeSandbox/StackBlitz
- Theme customization from screenshot
Built after seeing the "Screenshot to Code" trend and wanting a clean, fast, no-signup tool.
MIT — use it however you want!
Built with ⚡️ by [Your Name]