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.

