Anima Hello World
Overview
Generate production-ready React, Vue, or HTML code from a Figma design using the @animaapp/anima-sdk. This example converts a Figma component into clean TypeScript React with Tailwind CSS.
Prerequisites
- Completed
anima-install-auth setup
- A Figma file with at least one frame/component
- Know your file key and node ID
Instructions
Step 1: Generate React + Tailwind Code
// src/hello-world.ts
import { Anima } from '@animaapp/anima-sdk';
import fs from 'fs';
import path from 'path';
const anima = new Anima({
auth: { token: process.env.ANIMA_TOKEN! },
});
async function generateReactComponent() {
const { files } = await anima.generateCode({
fileKey: process.env.FIGMA_FILE_KEY!, // From Figma URL
figmaToken: process.env.FIGMA_TOKEN!,
nodesId: [process.env.FIGMA_NODE_ID!], // e.g., '1:2'
settings: {
language: 'typescript',
framework: 'react',
styling: 'tailwind',
uiLibrary: 'none', // or 'mui', 'antd', 'shadcn'
},
});
// Write generated files to disk
const outputDir = './generated';
fs.mkdirSync(outputDir, { recursive: true });
for (const file of files) {
const filePath = path.join(outputDir, file.fileName);
fs.writeFileSync(filePath, file.content);
console.log(`Generated: ${filePath} (${file.content.length} chars)`);
}
return files;
}
generateReactComponent().catch(console.error);
Step 2: Try Different Framework Outputs
// Generate Vue + Tailwind
const vueFiles = await anima.generateCode({
fileKey: process.env.FIGMA_FILE_KEY!,
figmaToken: process.env.FIGMA_TOKEN!,
nodesId: ['1:2'],
settings: {
language: 'typescript',
framework: 'vue',
styling: 'tailwind',
},
});
// Generate HTML + CSS (no framework)
const htmlFiles = await anima.generateCode({
fileKey: process.env.FIGMA_FILE_KEY!,
figmaToken: process.env.FIGMA_TOKEN!,
nodesId: ['1:2'],
settings: {
language: 'javascript',
framework: 'html',
styling: 'css',
},
});
// Generate React + shadcn/ui
const shadcnFiles = await anima.generateCode({
fileKey: process.env.FIGMA_FILE_KEY!,
figmaToken: process.env.FIGMA_TOKEN!,
nodesId: ['1:2'],
settings: {
language: 'typescript',
framework: 'react',
styling: 'tailwind',
uiLibrary: 'shadcn',
},
});
Step 3: Inspect Generated Output
// The generated files array contains:
interface GeneratedFile {
fileName: string; // e.g., 'HeroSection.tsx', 'styles.css'
content: string; // Full file content
type: string; // 'component', 'style', 'asset'
}
// Example output structure for React + Tailwind:
// generated/
// ├── HeroSection.tsx # React component with Tailwind classes
// ├── Button.tsx # Child components
// └── types.ts # TypeScript interfaces (if applicable)
Step 4: Integrate into Existing Project
# Copy generated files into your project
cp -r generated/components/* src/components/design/
# Install any missing dependencies
npm install # Anima generates standard React/Vue code — no special deps
Settings Reference
| Setting |
Options |
Default |
language |
typescript, javascript |
typescript |
framework |
react, vue, html |
react |
styling |
tailwind, css, styled-components |
tailwind |
uiLibrary |
none, mui, antd, shadcn |
none |
Output
- Generated React/Vue/HTML files from Figma design
- Clean TypeScript with Tailwind CSS classes
- Files ready to drop into existing project
- Multiple framework outputs compared
Error Handling
| Error |
Cause |
Solution |
File not found |
Wrong Figma file key |
Extract key from URL after /file/ |
Node not found |
Wrong node ID |
Use Figma's "Copy link" on the frame |
Empty files array |
Node has no renderable content |
Select a frame/component, not a page |
| Malformed output |
Complex nested auto-layout |
Simplify Figma structure; use components |
Resources
Next Steps
Proceed to anima-local-dev-loop for iterative design-to-code development.
1---2name: anima-hello-world3description: |4 Generate React/Vue/HTML code from a Figma design using the Anima SDK.5 Use when testing design-to-code conversion, learning Anima's code output format,6 or building your first automated design-to-code pipeline.7 Trigger: "anima hello world", "anima example", "figma to react",8 "figma to code", "anima generate code".9allowed-tools: Read, Write, Edit, Bash(npm:*)10version: 1.0.011license: MIT12author: Jeremy Longshore <jeremy@intentsolutions.io>13tags: [saas, design, figma, anima, react, code-generation]14compatible-with: claude-code15---1617# Anima Hello World1819## Overview2021Generate production-ready React, Vue, or HTML code from a Figma design using the `@animaapp/anima-sdk`. This example converts a Figma component into clean TypeScript React with Tailwind CSS.2223## Prerequisites2425- Completed `anima-install-auth` setup26- A Figma file with at least one frame/component27- Know your file key and node ID2829## Instructions3031### Step 1: Generate React + Tailwind Code3233```typescript34// src/hello-world.ts35import { Anima } from '@animaapp/anima-sdk';36import fs from 'fs';37import path from 'path';3839const anima = new Anima({40 auth: { token: process.env.ANIMA_TOKEN! },41});4243async function generateReactComponent() {44 const { files } = await anima.generateCode({45 fileKey: process.env.FIGMA_FILE_KEY!, // From Figma URL46 figmaToken: process.env.FIGMA_TOKEN!,47 nodesId: [process.env.FIGMA_NODE_ID!], // e.g., '1:2'48 settings: {49 language: 'typescript',50 framework: 'react',51 styling: 'tailwind',52 uiLibrary: 'none', // or 'mui', 'antd', 'shadcn'53 },54 });5556 // Write generated files to disk57 const outputDir = './generated';58 fs.mkdirSync(outputDir, { recursive: true });5960 for (const file of files) {61 const filePath = path.join(outputDir, file.fileName);62 fs.writeFileSync(filePath, file.content);63 console.log(`Generated: ${filePath} (${file.content.length} chars)`);64 }6566 return files;67}6869generateReactComponent().catch(console.error);70```7172### Step 2: Try Different Framework Outputs7374```typescript75// Generate Vue + Tailwind76const vueFiles = await anima.generateCode({77 fileKey: process.env.FIGMA_FILE_KEY!,78 figmaToken: process.env.FIGMA_TOKEN!,79 nodesId: ['1:2'],80 settings: {81 language: 'typescript',82 framework: 'vue',83 styling: 'tailwind',84 },85});8687// Generate HTML + CSS (no framework)88const htmlFiles = await anima.generateCode({89 fileKey: process.env.FIGMA_FILE_KEY!,90 figmaToken: process.env.FIGMA_TOKEN!,91 nodesId: ['1:2'],92 settings: {93 language: 'javascript',94 framework: 'html',95 styling: 'css',96 },97});9899// Generate React + shadcn/ui100const shadcnFiles = await anima.generateCode({101 fileKey: process.env.FIGMA_FILE_KEY!,102 figmaToken: process.env.FIGMA_TOKEN!,103 nodesId: ['1:2'],104 settings: {105 language: 'typescript',106 framework: 'react',107 styling: 'tailwind',108 uiLibrary: 'shadcn',109 },110});111```112113### Step 3: Inspect Generated Output114115```typescript116// The generated files array contains:117interface GeneratedFile {118 fileName: string; // e.g., 'HeroSection.tsx', 'styles.css'119 content: string; // Full file content120 type: string; // 'component', 'style', 'asset'121}122123// Example output structure for React + Tailwind:124// generated/125// ├── HeroSection.tsx # React component with Tailwind classes126// ├── Button.tsx # Child components127// └── types.ts # TypeScript interfaces (if applicable)128```129130### Step 4: Integrate into Existing Project131132```bash133# Copy generated files into your project134cp -r generated/components/* src/components/design/135136# Install any missing dependencies137npm install # Anima generates standard React/Vue code — no special deps138```139140## Settings Reference141142| Setting | Options | Default |143|---------|---------|---------|144| `language` | `typescript`, `javascript` | `typescript` |145| `framework` | `react`, `vue`, `html` | `react` |146| `styling` | `tailwind`, `css`, `styled-components` | `tailwind` |147| `uiLibrary` | `none`, `mui`, `antd`, `shadcn` | `none` |148149## Output150151- Generated React/Vue/HTML files from Figma design152- Clean TypeScript with Tailwind CSS classes153- Files ready to drop into existing project154- Multiple framework outputs compared155156## Error Handling157158| Error | Cause | Solution |159|-------|-------|----------|160| `File not found` | Wrong Figma file key | Extract key from URL after `/file/` |161| `Node not found` | Wrong node ID | Use Figma's "Copy link" on the frame |162| Empty `files` array | Node has no renderable content | Select a frame/component, not a page |163| Malformed output | Complex nested auto-layout | Simplify Figma structure; use components |164165## Resources166167- [Anima API Docs](https://docs.animaapp.com/docs/anima-api)168- [Anima SDK GitHub](https://github.com/AnimaApp/anima-sdk)169- [Anima Blog: Figma to React](https://www.animaapp.com/blog/design-to-code/how-to-export-figma-to-react/)170171## Next Steps172173Proceed to `anima-local-dev-loop` for iterative design-to-code development.174