FigmaToCode AI is a Next.js application that converts a UI design image into clean, responsive React component code using Tailwind CSS and Gemini AI. Upload a mockup, screenshot, or wireframe, and the app sends it to the Gemini API to generate frontend code that matches the design structure and layout.
This project is built for rapid frontend prototyping, UI-to-code workflows, and design handoff automation.
- Upload UI screenshots or design images in PNG, JPG, or WEBP format
- Drag-and-drop support with file validation
- Image preview before generation
- AI-powered conversion into React + Tailwind CSS code
- Copy generated code to the clipboard
- Built with Next.js App Router and TypeScript
- Responsive UI for local development and testing
- Next.js 16
- React 19
- TypeScript
- Tailwind CSS
- Google GenAI SDK
- Lucide React icons
.
├── app/
│ ├── api/
│ │ └── generate/
│ │ └── route.ts # Gemini API endpoint for code generation
│ ├── globals.css # Global styling
│ ├── layout.tsx # App layout
│ └── page.tsx # Main UI for uploading images and generating code
├── public/ # Static assets
├── .env.local # Local environment configuration (not committed)
├── package.json # Project scripts and dependencies
├── next.config.ts # Next.js configuration
├── tsconfig.json # TypeScript configuration
├── eslint.config.mjs # ESLint config
├── README.md # Project documentation
└── ...Before running this project, make sure you have:
- Node.js 20+ (recommended: LTS)
- npm, pnpm, yarn, or bun
- A valid Google Gemini API key
- Clone the repository:
git clone <your-repository-url>
cd figma-to-code- Install dependencies:
npm install- Create a local environment file:
cp .env.example .env.localIf there is no .env.example, create .env.local manually and add:
GEMINI_API_KEY=your_google_gemini_api_key_hereStart the development server:
npm run devThen open:
http://localhost:3000
- Upload a UI design image using the upload area or drag-and-drop
- The app validates the file type and size
- The image is converted into a base64 string
- A POST request is sent to
/api/generate - Gemini analyzes the image and returns frontend code
- The generated code is displayed in the UI for review and copy
The server exposes a generation endpoint at:
POST /api/generateRequest body:
{
"imageBase64": "data:image/png;base64,...",
"mimeType": "image/png"
}Response example:
{
"code": "export default function Example() { return <div className=\"...\">...</div>; }"
}If the request fails, the API returns an error response:
{
"error": "Detailed error message"
}npm run dev # start the development server
npm run build # create a production build
npm run start # run the production server
npm run lint # run ESLint checksThe generator prompt instructs the model to behave like an expert frontend developer and return only code without markdown wrappers. The generated result is designed for React components using Tailwind CSS and semantic HTML.
- Uploaded files are limited to PNG, JPG, and WEBP formats
- Maximum file size is 5MB
- Generated code should still be reviewed and adjusted for production use
- The quality of the output depends on image clarity, layout complexity, and the prompt instructions used by the model
This project is ready to be deployed on platforms such as Vercel.
When deploying, make sure to configure the environment variable:
GEMINI_API_KEYThis project is currently unlicensed unless you add an explicit license file or update this section for your organization.
Contributions are welcome. If you want to improve the app, feel free to:
- open an issue
- submit a feature request
- create a pull request with improvements
If you run into problems:
- check the environment variable configuration
- verify the image format and size
- confirm that your Gemini API key is valid and has sufficient access
- review the terminal logs for API errors