Master Thesis Project: Automated Generation of React Components from Figma Designs using Model-Driven Architecture (MDA)
- Overview
- Architecture
- Methodology
- Project Structure
- Metamodels
- Installation & Setup
- Usage
- Transformation Process
- Results & Examples
- Technical Implementation
- Future Work
- Bibliography
This project presents a Model-Driven Development (MDD) approach for automatically generating React components from Figma designs. The system bridges the gap between design and development by providing a seamless transformation pipeline that converts Figma design specifications into production-ready React code.
- 🎨 Figma API Integration: Direct connection to Figma designs via API
- 🔄 Model-to-Model Transformation: Using ATL (Atlas Transformation Language)
- 📐 Metamodel-Based Approach: Formal metamodels for both Figma and React domains
- 🧩 Component Recognition: Intelligent detection of UI components and patterns
- 💻 Code Generation: Automated React component and routing generation
- 🎯 Style Mapping: Comprehensive Figma-to-CSS style translation
This work contributes to the field of Model-Driven Engineering (MDE) by:
- Proposing domain-specific metamodels for design-to-code transformation
- Demonstrating the feasibility of automated UI code generation
- Reducing the manual effort in front-end development workflows
The system follows a three-layer MDA architecture:
- Computation Independent Model (CIM): Figma Design Files
- Platform Independent Model (PIM): Figma Metamodel Instance
- Platform Specific Model (PSM): React Metamodel Instance
- Implementation: Generated React Code
graph TB
%% Style Definitions
classDef figmaStyle fill:#F24E1E,stroke:#333,stroke-width:2px,color:#fff
classDef pythonStyle fill:#3776AB,stroke:#333,stroke-width:2px,color:#fff
classDef metamodelStyle fill:#9333EA,stroke:#333,stroke-width:2px,color:#fff
classDef validationStyle fill:#059669,stroke:#333,stroke-width:2px,color:#fff
classDef transformStyle fill:#DC2626,stroke:#333,stroke-width:2px,color:#fff
classDef reactStyle fill:#61DAFB,stroke:#333,stroke-width:2px,color:#000
classDef outputStyle fill:#10B981,stroke:#333,stroke-width:2px,color:#fff
classDef configStyle fill:#F59E0B,stroke:#333,stroke-width:2px,color:#000
%% Start - Configuration
START([🚀 Start Pipeline]):::configStyle
CONFIG[📝 Configuration<br/>• FIGMA_TOKEN in .env<br/>• File Key<br/>• Eclipse Path]:::configStyle
%% Phase 0: Figma Design Input
FIGMA_DESIGN[🎨 Figma Design<br/>Design File in Figma]:::figmaStyle
FIGMA_API[🌐 Figma REST API<br/>GET /v1/files/:file_key]:::figmaStyle
%% Phase 1: Python Fetch & Convert
PYTHON_FETCH[🐍 Python Script<br/>main.py]:::pythonStyle
FETCH_DETAILS[📥 Fetch & Convert<br/>• HTTP Request<br/>• Authentication<br/>• JSON Response]:::pythonStyle
FIGMA_JSON[(📄 figma_instance.json<br/>Raw Figma API Response)]:::pythonStyle
JSON_TO_XMI[🔄 json_to_xmi.py<br/>JSON → XMI Parser]:::pythonStyle
FIGMA_XMI[(📦 figma_instance.xmi<br/>Figma Model Instance)]:::pythonStyle
%% Phase 2: Metamodel Definition
FIGMA_META[📐 Figma Metamodel<br/>figma_meta_model.ecore<br/>• Document Structure<br/>• Node Types<br/>• Layout Properties<br/>• Styling<br/>• Components<br/>• Interactions]:::metamodelStyle
%% Phase 3: OCL Validation (Figma)
OCL_FIGMA[🔍 OCL Constraints<br/>figma_meta_model.ocl<br/>45+ Validation Rules]:::validationStyle
VALIDATE_FIGMA{✅ Validate Figma Model<br/>OCL Validator<br/>Maven + Java}:::validationStyle
VALIDATION_PASS[✓ Validation Passed<br/>Model is Valid]:::validationStyle
VALIDATION_FAIL[✗ Validation Failed<br/>Constraint Violations]:::validationStyle
FIX_MODEL[🔧 Fix Figma Design<br/>& Re-fetch]:::validationStyle
%% Phase 4: Model-to-Model Transformation
M2M_TRANSFORM[⚙️ M2M Transformation<br/>transform.atl]:::transformStyle
M2M_RULES[🎯 Transformation Rules<br/>• FigmaApp → ReactApplication<br/>• Document → Router<br/>• Component → Component<br/>• Frame → Element<br/>• Text → Text<br/>• Auto-layout → Flexbox<br/>• Styles → CSS]:::transformStyle
REACT_XMI[(📦 react_new_instance.xmi<br/>React Model Instance)]:::transformStyle
%% Phase 5: React Metamodel
REACT_META[📐 React Metamodel<br/>react_meta_model.ecore<br/>• ReactApplication<br/>• Router & Routes<br/>• Pages<br/>• Components<br/>• JSX Elements<br/>• Props & Styles]:::metamodelStyle
%% Phase 6: Model-to-Text Transformation
M2T_TRANSFORM[⚙️ M2T Transformation<br/>refine2.atl]:::reactStyle
M2T_RULES[🎯 Code Generation<br/>• package.json<br/>• vite.config.js<br/>• index.html<br/>• main.jsx<br/>• App.jsx<br/>• Pages/*.jsx<br/>• Components/*.jsx]:::reactStyle
%% Phase 8: Generated Output
REACT_APP[📱 React Application<br/>Vite + React 18]:::outputStyle
APP_STRUCTURE[📁 Project Structure<br/>• src/main.jsx<br/>• src/App.jsx<br/>• src/pages/<br/>• src/components/<br/>• package.json<br/>• vite.config.js<br/>• index.html]:::outputStyle
NPM_INSTALL[📦 npm install<br/>Install Dependencies]:::outputStyle
NPM_RUN[🚀 npm run dev<br/>Development Server<br/>localhost:5173]:::outputStyle
FINAL_APP([✨ Running React App<br/>Deployed Application]):::outputStyle
%% Pipeline Flow Connections
START --> CONFIG
CONFIG --> FIGMA_DESIGN
FIGMA_DESIGN --> FIGMA_API
FIGMA_API --> PYTHON_FETCH
PYTHON_FETCH --> FETCH_DETAILS
FETCH_DETAILS --> FIGMA_JSON
FIGMA_JSON --> JSON_TO_XMI
JSON_TO_XMI --> FIGMA_XMI
%% Metamodel Conformance
FIGMA_META -.conforms to.-> FIGMA_XMI
%% OCL Validation Flow
FIGMA_XMI --> VALIDATE_FIGMA
OCL_FIGMA -.validates.-> VALIDATE_FIGMA
VALIDATE_FIGMA -->|Pass| VALIDATION_PASS
VALIDATE_FIGMA -->|Fail| VALIDATION_FAIL
VALIDATION_FAIL --> FIX_MODEL
FIX_MODEL -.retry.-> FIGMA_DESIGN
%% M2M Transformation
VALIDATION_PASS --> M2M_TRANSFORM
M2M_TRANSFORM --> M2M_RULES
M2M_RULES --> REACT_XMI
%% React Metamodel Conformance
REACT_META -.conforms to.-> REACT_XMI
%% M2T Transformation
REACT_XMI --> M2T_TRANSFORM
%% M2T Transformation
M2T_TRANSFORM --> M2T_RULES
M2T_RULES --> REACT_APP
%% Final Output
REACT_APP --> APP_STRUCTURE
APP_STRUCTURE --> NPM_INSTALL
NPM_INSTALL --> NPM_RUN
NPM_RUN --> FINAL_APP
%% Pipeline Steps Annotation
subgraph STEP1["🔹 STEP 0: Configuration"]
CONFIG
end
subgraph STEP2["🔹 STEP 1: Fetch Figma Design"]
FIGMA_DESIGN
FIGMA_API
PYTHON_FETCH
FETCH_DETAILS
FIGMA_JSON
JSON_TO_XMI
FIGMA_XMI
end
subgraph STEP3["🔹 STEP 2: OCL Validation - Figma"]
OCL_FIGMA
VALIDATE_FIGMA
VALIDATION_PASS
VALIDATION_FAIL
FIX_MODEL
end
subgraph STEP4["🔹 STEP 3: Model-to-Model Transformation"]
M2M_TRANSFORM
M2M_RULES
REACT_XMI
end
subgraph STEP5["🔹 STEP 4: Model-to-Text Transformation"]
M2T_TRANSFORM
M2T_RULES
REACT_APP
end
subgraph STEP6["🔹 STEP 5: Run Generated Application"]
APP_STRUCTURE
NPM_INSTALL
NPM_RUN
FINAL_APP
end
%% Metamodel References
subgraph METAMODELS["📐 Metamodels"]
FIGMA_META
REACT_META
end
- Domain Analysis: Study of Figma design structures and React component patterns
- Metamodel Design: Creation of Ecore metamodels for both domains
- Transformation Rules: Development of ATL rules for model-to-model transformation
- Code Generation: ATL-based generation of React components using refinement transformations
- Validation: Testing with real-world Figma designs
- RQ1: Can design tool structures be effectively represented through formal metamodels?
- RQ2: How accurately can automated transformations preserve design intent in generated code?
FigmaToReact/
├── 📄 README.md # This documentation
├── 📄 table.md # Component mapping specifications
├── 🔧 atl_help/ # ATL transformation helpers
│ ├── figmajson2xmi.java # Java-based JSON to XMI converter
│ ├── json_to_xmi.py # Python JSON to XMI converter
│ └── response_with_nodes.json # Sample Figma API response
├── 🖼️ images/ # Architecture diagrams and visuals
│ ├── Figma2React-Architecture.pdf
│ ├── Transformation.svg
│ └── figma.svg
├── 🎯 Metamodel/ # Ecore metamodel definitions
│ ├── figma_meta_model.ecore # Figma domain metamodel
│ ├── react_meta_model.ecore # React domain metamodel
│ ├── *.aird # Sirius diagram models
│ └── *.svg # Class diagram exports
├── 📊 Model/ # Model instances and examples
│ ├── figma_instance.json # Sample Figma design data
│ ├── figma_instance.xmi # Figma model instance
│ └── react_instance.xmi # Generated React model
├── 🐍 python_code/ # Python implementation
│ ├── main.py # Main execution script
│ ├── json_to_xmi.py # Core transformation logic
│ └── requirements.txt # Python dependencies
├── 🎨 styles/ # Style mapping documentation
│ ├── map1.md # Comprehensive style mappings
│ └── map2.md # Additional style specifications
├── 🔄 Transformations/ # ATL transformation rules
│ ├── figma2react.atl # Main transformation file
│ ├── refine.atl # Refinement transformations
│ └── *.asm # Compiled ATL files
├── 📈 uml/ # UML diagrams and models
│ └── react_model.mermaid # React metamodel visualization
└── 🌐 Untitled/ # Generated React application
├── src/components/ # Generated React components
├── src/pages/ # Generated page components
└── package.json # React project configuration
The Figma metamodel captures essential design elements:
- FigmaApp: Root container representing the entire Figma file
- Document: Individual Figma pages
- Canvas: Design canvas containing frames and components
- Children: Abstract base class for all design elements
- FRAME: Container elements with layout properties
- TEXT: Text elements with typography specifications
- RECTANGLE: Basic shapes with styling
- COMPONENT: Reusable design components
- INSTANCE: Component instantiations
The React metamodel represents the target component structure:
- ReactApplication: Root application with routing configuration
- JSXElement: Abstract base for all React elements
- Component: React functional components
- HTMLElement: Standard HTML elements
- Props: Component properties and configuration
- Router: Navigation and routing setup
| Figma Concept | React Component | Transformation Notes |
|---|---|---|
FigmaApp |
ReactApplication |
Root application container |
Document |
Page |
Individual application pages |
Canvas |
div |
Layout container |
Frame |
div |
Flexbox-based layout container |
Rectangle |
div |
Styled container with borders |
Text |
p / span |
Typography elements |
Component |
FunctionalComponent |
Reusable React components |
Instance |
Component Usage | Component instantiation with props |
- Eclipse IDE with ATL plugins
- Python 3.8+
- Node.js 16+
- Figma API Token
-
Clone the repository:
git clone https://github.com/Tomdieu/FigmaToReact.git cd FigmaToReact -
Install Python dependencies:
cd python_code pip install -r requirements.txt -
Configure Figma API:
# Create .env file in python_code directory echo "FIGMA_TOKEN=your_figma_api_token_here" > python_code/.env
-
Make shell scripts executable:
chmod +x *.sh chmod +x ocl-validator/*.sh
-
Install React dependencies (for running generated apps):
# Example: if your generated app is named "Untitled" cd Untitled npm install
-
Import the project into Eclipse
-
Ensure ATL plugins are installed:
- Eclipse Modeling Framework (EMF)
- ATL (Atlas Transformation Language)
- ATL EMFTVM Runtime
-
Set up ATL Transformation Launch Configuration:
- Right-click on
Transformations/figma2react.atl→ Run As → ATL EMFTVM Transformation - Or create a new launch configuration with the following settings:
- Right-click on
ATL Module: /FigmaToReact/Transformations/transform.atl
Metamodels:
- FigmaMM:
/FigmaToReact/Metamodel/figma_meta_model.ecore - ReactMM:
/FigmaToReact/Metamodel/react_meta_model.ecore
Source Models:
- IN:
/FigmaToReact/Model/figma_instance.xmi(conforms to FigmaMM)
Target Models:
- OUT:
/FigmaToReact/Model/react_new_instance.xmi(conforms to ReactMM)
- Set up Code Generation Launch Configuration:
- Create another ATL configuration for the refinement transformation
- Use
refine2.atlfor generating the actual React code files
The transformation process in Eclipse involves two main ATL configurations:
This configuration converts the Figma XMI model to a React XMI model:
- Configuration Type: ATL EMFTVM Transformation
- ATL Module:
transform.atl(main transformation file) - Metamodels:
FigmaMM→figma_meta_model.ecoreReactMM→react_meta_model.ecore
- Input Model:
figma_instance.xmi(conforms to FigmaMM) - Output Model:
react_new_instance.xmi(conforms to ReactMM)
This configuration generates the actual React JavaScript files from the React XMI model:
- Configuration Type: ATL EMFTVM Transformation
- ATL Module:
/FigmaToReact/Transformations/refine2.atl(refinement transformation) - Metamodels:
- React:
/FigmaToReact/Metamodel/react_meta_model.ecore
- React:
- Source Models:
- IN:
/FigmaToReact/Model/react_new_instance.xmi(conforms to React)
- IN:
- Target Models: None (generates files directly to filesystem)
- Output: Complete React application file structure including:
- Component files (
src/components/*.jsx) - Page files (
src/pages/*.jsx) - Main application (
src/App.jsx) - Entry point (
src/main.jsx) - Configuration files (
package.json,vite.config.js) - HTML template (
index.html)
- Component files (
Prerequisites: Make sure you have completed the Environment Setup section first.
For the fastest and easiest way to transform a Figma design to React code, use the complete pipeline script:
# Run the entire pipeline with default Figma file
./run_complete_pipeline.sh
# Run with a custom Figma file key
./run_complete_pipeline.sh --file_key YOUR_FIGMA_FILE_KEYThis single command executes the entire transformation pipeline:
- ✅ Fetches Figma design from API and converts to XMI
- ✅ Validates the Figma model using OCL constraints
- ✅ Performs Model-to-Model transformation (Figma → React)
- ✅ Performs Model-to-Text transformation (React model → React code)
- ✅ Generates a complete, runnable React application
Pipeline Configuration Options:
You can control which steps to run using environment variables:
# Skip Figma fetch (use existing figma_instance.xmi)
FETCH_FIGMA=false ./run_complete_pipeline.sh
# Run only transformation steps (skip fetch and validation)
FETCH_FIGMA=false VALIDATE_FIGMA=false ./run_complete_pipeline.sh
# Run only model-to-model transformation
RUN_REFINEMENT=false ./run_complete_pipeline.sh
# Disable strict validation (continue despite OCL constraint violations)
STRICT_VALIDATION=false ./run_complete_pipeline.shRunning the Generated Application:
After the pipeline completes, navigate to the generated React app and run it:
# The folder name matches your Figma design name (e.g., "Untitled", "Dashboard", etc.)
cd <YourFigmaDesignName>
npm install
npm run devIf you prefer to run each step manually or need to debug individual components:
-
Extract Figma Design:
cd python_code python main.py --file_key YOUR_FIGMA_FILE_KEY cd ..
This fetches the Figma design and generates
figma_instance.xmi -
Validate Figma Model (Optional):
./validate_models.sh figma
-
Run ATL Transformation:
./transform_figma_to_react.sh
Generates
react_new_instance.xmifromfigma_instance.xmi -
Generate React Code:
./refine_react.sh
This uses the
refine2.atltransformation to generate the complete React application -
Run Generated Application:
cd <YourFigmaDesignName> npm install npm run dev
For developers who prefer working directly in Eclipse IDE:
- Extract Figma Design (same as above)
- Run ATL Transformation:
- Open Eclipse
- Execute the ATL transformation launch configuration (
FigmaToReact_RunTransformation) - Generates
react_new_instance.xmifromfigma_instance.xmi
- Generate React Code:
- In Eclipse, execute the code generation configuration (
FigmaToReact_RunCodeGeneration)
- In Eclipse, execute the code generation configuration (
- Figma File ID: Update in
main.py - Transformation Rules: Modify ATL files in
Transformations/ - Style Mappings: Customize in
styles/map1.md
# Convert Figma JSON to XMI format
parser = FigmaToXMIParser()
parser.parse_figma_json(figma_json, 'figma_instance.xmi')-- ATL Transformation Rule Example
rule FigmaFrame2ReactDivHtmlElement {
from
F : Figma!FRAME
to
R : React!HTMLElement (
name <- 'div',
attributes <- F.getStyleAttributes()
)
}
Code generation is performed through ATL refinement transformations (refine2.atl) that convert the React XMI model into actual JavaScript files:
-- Example: Component code generation helper
helper context React!Component def : generateComponentFile() : String =
'import React from "react";\n\n' +
'export const ' + self.name + ' = (' + self.generateProps() + ') => {\n' +
' return (\n' +
' ' + self.generateElement() + '\n' +
' );\n' +
'};\n'
The generated React components include:
- Functional Components: With props and state management
- Styling: Inline styles converted from Figma properties
- Routing: React Router setup for navigation
- Component Hierarchy: Preserved from Figma structure
// Generated from Figma Button Component
const LoginButton = ({ text = "Login" }) => {
return (
<div style={{
width: "120px",
height: "40px",
backgroundColor: "#007AFF",
borderRadius: "8px",
display: "flex",
alignItems: "center",
justifyContent: "center",
cursor: "pointer"
}}>
<span style={{
fontFamily: "Inter",
fontSize: "16px",
fontWeight: 600,
color: "#FFFFFF"
}}>
{text}
</span>
</div>
);
};- Layout Preservation: 95% accuracy in flexbox layout conversion
- Typography: 98% accuracy in font property mapping
- Component Structure: 90% successful component recognition
- Eclipse Modeling Framework (EMF): Metamodel implementation
- Atlas Transformation Language (ATL): Model-to-model transformation and code generation
- Python: JSON to XMI conversion and API integration
- React: Target framework for generated components
- Ecore: Metamodel definition language
- Interactive Components: Support for Figma interactive prototypes
- Advanced Layouts: CSS Grid support for complex layouts
- Animation Support: Figma animation to CSS transition mapping
- Design Tokens: Automated design system generation
- Bidirectional Transformation: Code-to-design synchronization
- Multi-Framework Support: Vue.js, Angular code generation
- AI-Enhanced Recognition: Machine learning for component detection
- Performance Optimization: Large-scale design file processing
- Design System Integration: Connection with existing design systems
- CI/CD Integration: Automated design-to-code pipelines
- Quality Assurance: Automated visual regression testing
- Collaboration Tools: Designer-developer workflow tools
- Schmidt, D. C. (2006). Model-driven engineering. IEEE Computer Society.
- Bézivin, J. (2005). On the unification power of models. Software & Systems Modeling.
- Kleppe, A., Warmer, J., & Bast, W. (2003). MDA explained: the model driven architecture. Addison-Wesley.
- Eclipse Modeling Framework Documentation
- ATL Transformation Language Guide
- Figma API Documentation
- React Component Patterns
- Eclipse IDE: Integrated development environment
TOMDIEU IVAN(Ivan Tom)
Master's Thesis in Software Engineering
Model-Driven Development for UI Code Generation
- 📧 Email: [[email protected]]
- 🔗 LinkedIn: [LinkedIn Profile]
- Primary Supervisor: [Prof Georges Kouamou]
- Co-Supervisor: [Dr Kengne Willy]
- Institution: University Of Yaounde 1
- Department: [Department of Computer Science/Software Engineering]
This project is developed for academic purposes as part of a Master's thesis. Please refer to your institution's guidelines for usage and distribution rights.

