Sketch2Spec is an AI-powered design-to-code assistant that helps developers and designers transform hand-drawn wireframes and UI sketches into production-ready React components. It handles everything from real-time image analysis using vision AI, generating clean JSX code with Tailwind CSS, providing live component previews, and offering instant code regeneration for iterative refinement.
The design-to-development handoff is slow and inefficient. As developers, we've all been through the cycle of manually translating mockups into code, guessing at spacing and colors, writing repetitive component structures, and hoping the result matches the design. Most of the time, there's back-and-forth with designers, no clear starting point, and hours spent on boilerplate. Sketch2Spec was built to fix that - by helping you convert any wireframe or UI screenshot into working React code instantly, preview it across devices, and iterate quickly until it's perfect.
- Node.js 20.x or higher
- npm or yarn
- API keys for:
-
Clone the repository
git clone https://github.com/yourusername/Sketch2Spec.git cd Sketch2Spec -
Install dependencies
npm install
-
Configure environment variables
Create a
.envfile in the root directory:# Clerk Authentication NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_... CLERK_SECRET_KEY=sk_test_... NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard # Google Gemini AI GEMINI_API_KEY=AIza... GEMINI_MODEL=gemini-1.5-flash # Cloudinary NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME=your_cloud_name CLOUDINARY_API_KEY=your_api_key CLOUDINARY_API_SECRET=your_api_secret
-
Start the development server
npm run dev
-
Open your browser
Navigate to http://localhost:3000
| Tech | Purpose |
|---|---|
| Next.js 15 & Tailwind CSS | Frontend framework and styling |
| React 18 | UI library |
| TypeScript | Type safety and developer experience |
| Clerk | User authentication and management |
| Google Gemini | Vision AI for wireframe-to-code generation |
| Cloudinary | Image upload and storage |
| Babel Standalone | Browser-based JSX transformation |
| Lucide React | Icon library |
Sketch2Spec uses Google Gemini's vision models to analyze your wireframes and UI screenshots in real-time. Simply upload an image, and it generates complete React components with Tailwind CSS styling. You can choose between two models:
- Gemini Flash (Optimized): Faster generation, ideal for simple to medium complexity UIs
- Gemini Pro (Precision): Higher detail analysis, perfect for complex layouts and intricate designs
The AI extracts layout hierarchies, identifies UI elements, matches colors and typography, and produces clean, semantic JSX code ready to use in your projects.
Sketch2Spec analyzes the generated code to:
- Remove TypeScript syntax for browser compatibility
- Convert ES6 imports to UMD globals for iframe rendering
- Auto-detect and import Lucide React icons used in the JSX
- Validate code completeness and syntax correctness
- Apply retry logic with exponential backoff for robust generation
- Ensure balanced braces, proper exports, and complete component structures
You can preview your generated components instantly in a sandboxed iframe environment. The preview system supports:
- Responsive Device Switching: Test across desktop (100%), tablet (768px), and mobile (375px) viewports
- Real-time Rendering: See changes immediately with hot-reloading
- Error Handling: Detailed error messages with stack traces for debugging
- Code Inspection: Side-by-side view of source code and live preview
- One-Click Copy: Copy the entire JSX code to your clipboard instantly
Sketch2Spec lets you regenerate code directly from the preview page without re-uploading your image. This enables rapid iteration:
- Refine the generated output with a single click
- Get variations of the same design
- Experiment with different AI interpretations
- Save time during the design-to-code workflow
All generated code is stored in session storage, so you can navigate between pages without losing your work.
Upload your wireframes securely through Cloudinary integration:
- Signed upload URLs prevent unauthorized access
- Support for PNG, JPG, JPEG, and WebP formats
- Automatic image optimization and CDN delivery
- Persistent storage with unique public IDs
- Direct integration with AI generation pipeline
Sketch2Spec/
├── app/
│ ├── api/
│ │ ├── ai/
│ │ │ └── generate/
│ │ │ └── route.ts # AI code generation endpoint
│ │ └── cloudinary/
│ │ └── sign/
│ │ └── route.ts # Cloudinary signature endpoint
│ ├── dashboard/
│ │ ├── _components/
│ │ │ └── ImageUpload.tsx # Upload & generation UI
│ │ └── page.tsx # Dashboard page
│ ├── preview/
│ │ └── page.tsx # Preview & code viewer
│ ├── sign-in/
│ │ └── [[...sign-in]]/
│ │ └── page.tsx # Clerk sign-in
│ ├── sign-up/
│ │ └── [[...sign-up]]/
│ │ └── page.tsx # Clerk sign-up
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout
│ └── page.tsx # Landing page
├── components/
│ └── ui/ # Shadcn UI components
├── lib/
│ ├── aiProviders.ts # Gemini AI integration
│ ├── aiLogger.ts # Request logging
│ ├── buildPreviewSrcDoc.ts # Preview iframe builder
│ └── utils.ts # Utility functions
├── middleware.ts # Clerk auth middleware
├── tailwind.config.ts # Tailwind config
├── next.config.ts # Next.js config
└── package.json
- Sign up or log in using Clerk authentication
- Navigate to the Dashboard after authentication
- Upload your wireframe by clicking "Browse Files" or drag-and-drop
- Select an AI model (Optimized for speed, Precision for detail)
- Click "Generate Component" and wait 5-15 seconds
- View the live preview with responsive device switching
- Copy the code to your clipboard with one click
- Regenerate if needed for variations or improvements
- Use high-contrast, well-lit photos of your sketches
- Start with simpler layouts for better accuracy
- Add labels or annotations to wireframes for context
- Use the Precision model for complex, multi-section layouts
- Iterate with regeneration to explore different interpretations
Generate React code from a wireframe image URL.
Request:
{
"imageUrl": "https://res.cloudinary.com/...",
"model": "gemini-flash-latest",
"allowFallback": false
}Response:
{
"code": "import React from 'react'...",
"provider": "Gemini",
"fallbackUsed": false
}Generate a signed upload URL for Cloudinary.
Request:
{
"public_id": "sketch_1234567890"
}Response:
{
"signature": "...",
"timestamp": 1234567890,
"api_key": "...",
"cloud_name": "..."
}Adjust generation parameters in lib/aiProviders.ts:
generationConfig: {
temperature: 0.2, // Lower = more deterministic
maxOutputTokens: 16000, // Maximum code length
topP: 0.95,
topK: 40,
}Modify the preview environment in lib/buildPreviewSrcDoc.ts:
- React version:
react@18 - Tailwind CDN:
cdn.tailwindcss.com - Lucide icons:
lucide-react@0.474.0 - Babel:
@babel/standalone@7.23.5
# Start development server
npm run dev
# Build for production
npm run build
# Start production server
npm run start
# Lint code
npm run lint- Push your code to GitHub
- Import the repository in Vercel
- Add all environment variables from your
.envfile - Deploy with one click
- Update Clerk URLs to match your production domain
Preview not rendering
- Check browser console for errors
- Verify
window.__PREVIEW_COMPONENT__is defined - Ensure Babel transformation completed successfully
API rate limits
- Gemini has rate limits; add delays between requests
- Check your quota in Google Cloud Console
Image upload fails
- Verify Cloudinary credentials are correct
- Check image size (max 10MB recommended)
- Ensure CORS settings are properly configured
Module not found errors
- Ensure Lucide icons are properly auto-detected
- Check that UMD libraries are loading correctly
- Verify import resolution in
lib/aiProviders.ts
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.
- Support for Claude and GPT-4 Vision models
- Export to CodeSandbox and StackBlitz
- Component library integration (Material-UI, Chakra UI)
- Version history for generated code
- Collaborative editing and sharing
- Dark mode support
- Figma plugin integration
- Mobile app (React Native)
- Batch processing for multiple wireframes
- Google Gemini for powerful vision AI capabilities
- Clerk for seamless authentication
- Cloudinary for reliable image hosting
- Vercel for excellent deployment platform
- Shadcn for beautiful UI components
Built with ❤️ by the Sketch2Spec Team
Transform your sketches into reality, one component at a time.
