Design2Code is a full-stack AI-powered web application that converts website design images and natural language prompts into clean, responsive HTML code. Built during a Hackathon, this project leverages Google's Gemini AI API to analyze visual designs and generate production-ready front-end code in seconds.
Whether you're a designer who wants quick prototypes, a developer looking to accelerate development, or a student learning web development, Design2Code eliminates repetitive coding and lets you focus on what matters.
- β³ Slow Prototyping: Converting design mockups to code manually takes hours
- π¨ Designer-Developer Gap: Designers struggle to communicate exact styling to developers
- π± Responsive Design: Building responsive layouts requires extensive media queries and testing
- π‘ Ideation Speed: Rapid iteration and prototyping becomes a bottleneck
- π¨ UI/UX Designers - Convert mockups to working prototypes instantly
- π¨βπ» Frontend Developers - Generate boilerplate code and focus on complex logic
- π’ Startups & Agencies - Speed up project delivery and reduce development time
- π Students & Learning - Understand HTML/CSS best practices through AI-generated code
- Upload website design screenshots (PNG/JPEG)
- AI analyzes layout, colors, typography, and spacing
- Generates semantic HTML5 with embedded CSS
- Creates responsive designs automatically
- Describe your website idea in natural language
- AI generates complete HTML structure with modern styling
- Supports complex design descriptions
- Produces pixel-perfect, responsive code
- Real-time HTML preview within the application
- Test generated code before downloading
- Visual validation of AI output
- Interactive component testing
- πΈ Upload Mode - Convert design images to code
- π¬ Prompt Mode - Generate code from descriptions
- π Whiteboard Mode - Sketch and convert
- π¨ Template Mode - Start from pre-built templates
- β Semantic HTML5 structure
- β Modern CSS with Flexbox/Grid
- β Fully responsive (desktop, tablet, mobile)
- β Smooth animations and transitions
- β Professional styling (gradients, shadows, effects)
- β Accessibility-ready
| Technology | Purpose |
|---|---|
| React 18 | UI framework |
| TypeScript | Type-safe development |
| Vite | Fast build tool |
| Tailwind CSS | Utility-first styling |
| Shadcn/ui | High-quality component library |
| Framer Motion | Smooth animations |
| GSAP | Advanced animations |
| React Three Fiber | 3D graphics |
| TanStack Query | Data fetching & caching |
| React Router | Client-side routing |
| Technology | Purpose |
|---|---|
| Node.js | JavaScript runtime |
| Express.js | Web framework |
| Google Gemini AI API | Code generation engine |
| Multer | File upload handling |
| CORS | Cross-origin support |
| Dotenv | Environment variables |
- TypeScript: 85% of codebase
- JavaScript: 9.9% (backend scripts)
- CSS: 4.6% (custom styling)
- HTML: 0.5% (markup)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER INTERFACE (React) β
β ββββββββββββββββ¬βββββββββββββββ¬βββββββββββββββββββββββββββ β
β β Landing Page β Create Page β Preview & Download β β
β ββββββββββββββββ΄βββββββββββββββ΄βββββββββββββββββββββββββββ β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β INPUT PROCESSING LAYER β
β ββββββββββββββββ¬βββββββββββββββ¬βββββββββββββββββββββββββββ β
β β Image Upload β Text Prompt β File Management β β
β β (Multer) β Processing β (Validation) β β
β ββββββββββββββββ΄βββββββββββββββ΄βββββββββββββββββββββββββββ β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β EXPRESS BACKEND SERVER β
β ββββββββββββββββ¬βββββββββββββββ¬βββββββββββββββββββββββββββ β
β β Image Route β Prompt Route β Middleware (Error) β β
β β /upload β /generate β Handler, CORS β β
β ββββββββββββββββ΄βββββββββββββββ΄βββββββββββββββββββββββββββ β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AI PROCESSING LAYER (Controllers) β
β ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ β
β β imageToCode.js β generationController.js β β
β β Process & Send to AI β Handle Generation Requests β β
β ββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββ β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SERVICES LAYER (External API Calls) β
β ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ β
β β imageService.js β generationService.js β β
β β - Buffer to Base64 β - Build API request β β
β β - Send to Gemini API β - Parse Gemini response β β
β ββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββ β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GOOGLE GEMINI AI (External Service) β
β π€ AI Code Generation Engine β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GENERATED HTML RESPONSE β
β ββ Semantic HTML5 Structure β
β ββ Embedded CSS with Flexbox/Grid β
β ββ Responsive Media Queries β
β ββ Modern Design Patterns β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- User Input β Frontend captures image/prompt
- Upload/Send β Data sent to Express backend via API
- Processing β Backend validates and processes input
- AI Call β Service layer sends to Google Gemini API
- Generation β Gemini AI analyzes and generates code
- Response β HTML code returned to frontend
- Preview β Live preview rendered in iframe
- Download β User downloads/uses generated code
http://localhost:5000/api
POST /upload/image-to-code
Content-Type: multipart/form-data
Body:
image: <File> (PNG or JPEG)Response (Success - 200)
{
"code": "<!DOCTYPE html>\n<html>...",
"timestamp": "2025-12-17T10:30:00Z"
}Response (Error - 400/500)
{
"error": "Error message describing what went wrong"
}cURL Example:
curl -X POST http://localhost:5000/api/upload/image-to-code \
-F "image=@design.png" \
-H "Accept: application/json"POST /generate/prompt-to-code
Content-Type: application/json
Body:
{
"prompt": "Create a modern landing page with a hero section, features grid, and CTA button"
}Response (Success - 200)
{
"code": "<!DOCTYPE html>\n<html>...",
"timestamp": "2025-12-17T10:30:00Z"
}cURL Example:
curl -X POST http://localhost:5000/api/generate/prompt-to-code \
-H "Content-Type: application/json" \
-d '{"prompt": "Create a modern dashboard"}'| Aspect | Details |
|---|---|
| Max File Size | 10 MB |
| Supported Formats | PNG, JPEG |
| Timeout | 30 seconds |
| Rate Limit | No limit (development) |
| Authentication | None (development) |
Before installing, ensure you have:
-
Node.js (v16.0.0 or higher)
- Download: nodejs.org
- Verify:
node --version
-
npm (v7.0.0 or higher) - Comes with Node.js
- Verify:
npm --version
- Verify:
-
Git - For cloning the repository
- Download: git-scm.com
-
Google Gemini API Key - Required for AI functionality
- Get it: Google AI Studio
git clone https://github.com/priymavani/Design2Code.git
cd Design2Code# Navigate to backend directory
cd backend
# Install dependencies
npm install
# Create .env file
echo "GEMINI_API_KEY=your_api_key_here" > .env
echo "PORT=5000" >> .env
# Verify .env
cat .envBackend Dependencies Installed:
express- Web server frameworkcors- Cross-origin resource sharingmulter- File upload handlingdotenv- Environment variablesnodemon- Auto-reload serveruuid- Unique ID generation
# Start with nodemon (auto-reload on changes)
npm run dev
# OR start normally
npm startExpected Output:
Server is running on port 5000
# From project root, navigate to frontend
cd frontend
# Install dependencies
npm install
# Start development server
npm run devExpected Output:
Local: http://localhost:5173
- Open browser:
http://localhost:5173 - Navigate to "Create" page
- Choose mode (Upload Image or Enter Prompt)
- Generate and preview your code!
| Issue | Solution |
|---|---|
| Port already in use | Change PORT in .env or kill process on that port |
| Module not found | Run npm install in the correct directory |
| GEMINI_API_KEY error | Ensure .env file exists in backend/ with valid key |
| CORS error | Verify frontend URL in server.js matches your dev URL |
| Build fails | Delete node_modules and .lock files, run npm install again |
Design2Code/
βββ README.md # Project documentation
β
βββ backend/ # Express.js server
β βββ package.json # Backend dependencies
β βββ server.js # Main server file with routes
β β
β βββ controllers/ # Request handlers
β β βββ imageToCode.js # Processes image uploads
β β βββ generationController.js # Handles prompt generation
β β βββ chatController.js # Chat functionality (future)
β β βββ promptToCode.js # Prompt processing
β β
β βββ routes/ # API endpoints
β β βββ imageRoute.js # POST /api/upload/image-to-code
β β βββ generationRoute.js # POST /api/generate/prompt-to-code
β β βββ chatRoute.js # Chat endpoints (future)
β β βββ promptRoute.js # Prompt-related routes
β β
β βββ services/ # Business logic & API calls
β β βββ imageService.js # Calls Gemini API for images
β β βββ generationService.js # Calls Gemini API for prompts
β β βββ geminiService.js # Shared Gemini utilities
β β βββ conversationService.js # Chat conversation logic
β β
β βββ middleware/ # Express middleware
β β βββ errorHandler.js # Global error handling
β β
β βββ .env # Environment variables (not in repo)
β
βββ frontend/ # React + TypeScript application
β βββ package.json # Frontend dependencies
β βββ vite.config.ts # Vite build configuration
β βββ tsconfig.json # TypeScript configuration
β βββ tailwind.config.ts # Tailwind CSS config
β βββ postcss.config.js # PostCSS configuration
β β
β βββ src/
β β βββ main.tsx # React entry point
β β βββ App.tsx # Root component with routing
β β βββ index.css # Global styles
β β β
β β βββ pages/ # Page components
β β β βββ Index.tsx # Landing page
β β β βββ CreatePage.tsx # Main code generation page
β β β βββ StickersPage.tsx # Stickers/decorations page
β β β βββ RealisticRobot.tsx # 3D robot component
β β β βββ NotFound.tsx # 404 page
β β β
β β βββ components/ # Reusable components
β β β βββ LandingPage.tsx # Hero section
β β β βββ CreatePage.tsx # Creation workflow
β β β βββ LivePreview.tsx # Code preview iframe
β β β βββ LoadingSpinner.tsx # Loading animation
β β β βββ LogoGenerator.tsx # Logo creation tool
β β β βββ OrbPreview.tsx # 3D orb animation
β β β βββ ParticleBackground.tsx # Animated particles
β β β βββ ColorPaletteDisplay.tsx # Color picker
β β β βββ ExampleLogos.tsx # Example templates
β β β βββ FeaturesTile.tsx # Features showcase
β β β βββ ThemeToggleTile.tsx # Dark mode toggle
β β β βββ ImpactTile.tsx # Impact statistics
β β β βββ PreviewTile.tsx # Code preview section
β β β βββ UploadTile.tsx # File upload component
β β β βββ StickersTile.tsx # Stickers showcase
β β β βββ FooterTile.tsx # Footer component
β β β βββ SmoothScrollProvider.tsx # Scroll animation provider
β β β β
β β β βββ ui/ # shadcn/ui components
β β β βββ button.tsx # Button component
β β β βββ card.tsx # Card component
β β β βββ dialog.tsx # Modal dialog
β β β βββ input.tsx # Input field
β β β βββ textarea.tsx # Text area
β β β βββ tabs.tsx # Tab component
β β β βββ accordion.tsx # Accordion
β β β βββ dropdown-menu.tsx # Dropdown menu
β β β βββ skeleton.tsx # Loading skeleton
β β β βββ [20+ more UI components]
β β β
β β βββ hooks/ # Custom React hooks
β β β βββ use-mobile.tsx # Mobile detection hook
β β β βββ use-toast.ts # Toast notification hook
β β β
β β βββ lib/ # Utility functions
β β β βββ utils.ts # Helper functions
β β β
β β βββ vite-env.d.ts # Vite type definitions
β β
β βββ public/ # Static assets
β β
β βββ index.html # HTML entry point
β
βββ .gitignore # Git ignore rules
| Directory | Purpose | Key Files |
|---|---|---|
backend/controllers |
Handle incoming requests | imageToCode.js |
backend/services |
Business logic & API calls | imageService.js |
backend/routes |
Define API endpoints | imageRoute.js |
frontend/pages |
Full page components | CreatePage.tsx |
frontend/components |
Reusable UI components | LivePreview.tsx |
frontend/components/ui |
Pre-built UI library | 30+ shadcn components |
Create a .env file in the backend/ directory:
# .env
GEMINI_API_KEY=your_actual_gemini_api_key_here
PORT=5000| Variable | Type | Required | Description |
|---|---|---|---|
GEMINI_API_KEY |
String | β Yes | Google Gemini API key for code generation |
PORT |
Number | β No | Server port (default: 5000) |
- Visit Google AI Studio
- Click "Create API Key"
- Copy the generated key
- Paste into
.envfile
.env to Git! It's already in .gitignore.
- View project features and benefits
- See example logos and stickers
- Understand the technology stack
- Browse theme options
1. Click "Upload Design Image" button
2. Select PNG or JPEG file from computer
3. Click "Generate Code"
4. AI analyzes image and generates HTML
5. Preview generated code in live preview
6. Download or copy code
1. Click "Describe Your Website" button
2. Type detailed description:
- "Create a modern e-commerce landing page with
hero section, product cards, and contact form"
3. Click "Generate Code"
4. AI generates responsive HTML
5. Preview and download
1. Browse pre-built templates
2. Select "Modern Dashboard" or others
3. View template preview
4. Use as starting point or modify
- Generated code displayed in live iframe
- See responsive design in real-time
- Test on different screen sizes
- Interactive component testing
- Copy code to clipboard
- Download as
.htmlfile - Share preview link
- Edit in your editor
- Browse decorative stickers
- Add to your designs
- Export as SVG/PNG