Convert your Figma designs to production-ready React components using AI. This application uses the Figma API to fetch design files and Claude AI to generate clean, responsive React code.
- 🎨 Direct Figma Integration - Fetch designs directly from Figma using the API
- 🤖 AI-Powered Code Generation - Generate React components using Claude AI
- 📱 Responsive Design - Output includes mobile-first responsive styles
- 🎯 Multiple Output Types - Generate single components, multiple components, or complete pages
- 🛠️ Flexible Styling - Support for Tailwind CSS, CSS Modules, or Styled Components
- 📝 TypeScript Support - Generate TypeScript code with proper type definitions
- 🔄 Component Reusability - Automatically detect and create reusable components
Before you begin, you'll need:
-
Figma Access Token
- Go to Figma Settings
- Navigate to "Account" → "Personal Access Tokens"
- Create a new token with file read permissions
-
AI API Keys (Choose one or more)
- Anthropic API Key: Sign up at Anthropic Console and create an API key with Claude access
- OpenAI API Key: Sign up at OpenAI Platform and create an API key with GPT-4 access
- Google Gemini API Key: Sign up at Google AI Studio and create an API key with Gemini access
-
Clone and setup the project:
npx create-next-app@latest figma-to-code --typescript --tailwind --app cd figma-to-code -
Install dependencies:
npm install @anthropic-ai/sdk openai lucide-react prismjs @types/prismjs
-
Environment Configuration:
cp .env.example .env.local
Then edit
.env.localand add your API keys:FIGMA_ACCESS_TOKEN=your_figma_token_here ANTHROPIC_API_KEY=your_anthropic_api_key_here OPENAI_API_KEY=your_openai_api_key_here GEMINI_API_KEY=your_gemini_api_key_here NEXT_PUBLIC_APP_URL=http://localhost:3013
Note: You can add one or more AI provider keys. Having multiple providers gives you fallback options when one service is unavailable.
-
Start the development server:
npm run dev
- Make sure your Figma file is organized with frames containing your designs
- Ensure your access token has permission to read the file
- Copy the Figma file URL
-
Enter Figma Details:
- Paste your Figma file URL
- Enter your Figma access token
- Click "Load Figma File"
-
Select Frames:
- Choose which frames/screens you want to convert
- Preview the frame contents and dimensions
-
Configure Generation:
- Choose AI provider (Claude AI, OpenAI GPT-4, or Gemini 2.5 Flash)
- Choose generation type (single component, multiple components, or full page)
- Select your preferred framework (React, Vue, Angular)
- Pick styling method (Tailwind CSS, CSS Modules, Styled Components)
- Configure TypeScript, props, and responsive options
-
Generate Code:
- Click "Generate Code"
- Review the generated components
- Copy or download the code
figma-to-code-generator/
├── app/
│ ├── api/
│ │ ├── figma/route.ts # Figma API integration
│ │ └── generate/route.ts # Code generation endpoint
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout
│ └── page.tsx # Main application page
├── components/
│ ├── CodeViewer.tsx # Code display with syntax highlighting
│ ├── FigmaInput.tsx # Figma URL and token input
│ ├── FrameSelector.tsx # Frame selection interface
│ └── GenerationOptions.tsx # Code generation configuration
├── lib/
│ ├── figma-api.ts # Figma API client
│ ├── claude-api.ts # Claude AI client
│ └── openai-api.ts # OpenAI API client
├── types/
│ └── figma.ts # TypeScript type definitions
├── utils/
│ └── figma.ts # Figma data processing utilities
└── README.md
Fetch and process a Figma file.
Request:
{
"figmaUrl": "https://www.figma.com/file/...",
"accessToken": "figd_..."
}Response:
{
"success": true,
"data": {
"fileName": "My Design File",
"fileKey": "abc123",
"frames": [...],
"processedDocument": {...}
}
}Generate code from processed Figma nodes.
Request:
{
"nodes": [...],
"generationType": "component|page|multiple",
"provider": "claude|openai",
"options": {
"framework": "react",
"styling": "tailwind",
"typescript": true,
"includeProps": true,
"responsive": true,
"pageName": "HomePage"
}
}- Single Component: Generate one component from the first selected frame
- Multiple Components: Extract and generate all reusable components
- Complete Page: Generate a full page layout with all components
- React (default) - Modern React with hooks
- Vue - Vue 3 composition API
- Angular - Angular with TypeScript
- Tailwind CSS (recommended) - Utility-first CSS framework
- CSS Modules - Scoped CSS with modules
- Styled Components - CSS-in-JS solution
- TypeScript - Generate TypeScript code with type definitions
- Props Interface - Include props interface for component reusability
- Responsive Design - Mobile-first responsive styles
-
Organize Your Figma File:
- Use clear, descriptive names for frames and layers
- Group related elements together
- Use consistent spacing and typography
-
Design System:
- Define consistent colors, typography, and spacing
- Use components and instances where possible
- Create variants for different states
-
Layout Structure:
- Use auto-layout frames for flexible designs
- Define clear component boundaries
- Consider responsive breakpoints
Invalid Figma URL
- Ensure the URL is from figma.com and includes the file ID
- Supported formats:
/file/,/design/,/proto/
Access Token Errors
- Verify your token has read access to the file
- Check if the file is shared publicly or with your account
- Regenerate your token if it's expired
Code Generation Fails
- Check your AI provider API keys (Anthropic/OpenAI) and account limits
- Try switching between Claude and OpenAI if one is experiencing issues
- Ensure selected frames contain valid design elements
- Try with simpler designs first
Empty or Malformed Code
- Verify the design has proper structure and content
- Check if frames contain actual design elements
- Try different generation options
If you encounter issues:
- Check the browser console for error messages
- Verify your API keys are correctly configured
- Test with simple Figma files first
- Review the generated API responses in Network tab
This is a starter template! Feel free to:
- Add support for more frameworks (Svelte, Solid, etc.)
- Implement additional styling systems
- Add component optimization features
- Improve the design detection algorithms
- Add more code generation options
MIT License - feel free to use this project as a starting point for your own Figma-to-code tools.
- Component variant detection
- Design token extraction
- Animation and interaction generation
- Component documentation generation
- Integration with design systems
- Real-time collaboration features
- Advanced responsive breakpoint detection
- Accessibility optimization
- Performance optimization suggestions