> **A sophisticated web application that converts HTML and CSS to JSON layout through an intelligent multi-step flow process with AI validation.**
npm install xobuilder-extractor> A sophisticated web application that converts HTML and CSS to JSON layout through an intelligent multi-step flow process with AI validation.
XOBuilder Extractor is an advanced web application designed to transform HTML and CSS code into structured JSON layouts through a visual, multi-step processing flow. The application leverages ReactFlow for interactive UI representation and integrates with OpenAI for intelligent content conversion and validation.
The project follows Clean Architecture principles with clear separation of concerns:
```
src/
āāā application/ # Business logic and use cases
ā āāā dto/ # Data Transfer Objects
ā āāā use-case/ # Application use cases
āāā domains/ # Core business entities and models
ā āāā entities/ # Domain entities
āāā utils/ # Utility functions and helpers
āāā constants/ # Application constants
āāā index.ts # Main entry point and exported functions
- Interactive Flow Visualization: Built with ReactFlow for intuitive process monitoring
- Real-time Status Updates: Visual feedback with animated borders and progress indicators
- Step-by-Step Execution: Clear progression through processing stages
- OpenAI Integration: Intelligent HTML/CSS to JSON conversion
- Validation Loop: Automatic comparison and re-generation for accuracy
- Smart Retry Logic: Up to 5 automatic retries with improvement iterations
- Processing State: Animated running border with real-time counter
- Success State: Green success border indicating completion
- Failure State: Red error border for failed operations
- Connection Types:
- Solid arrows for step-to-step flow
- Dashed arrows for AI agent connections
The application follows a sophisticated 4-step process:
Purpose: Extract and prepare source materials
- Input: JSON file containing array of objects
- Processing: Extract HTML, CSS, and screenshot data
- Output: Structured data ready for conversion
- Status: Foundation step - must complete successfully
Purpose: Transform HTML/CSS to raw JSON layout
- Input: HTML and CSS from Step 1
- AI Agent: OpenAI integration (dashed connection)
- Processing: Intelligent conversion using machine learning
- Output: Raw JSON layout structure
- Retry Logic: Supports up to 5 regeneration attempts
Purpose: Ensure conversion accuracy through visual comparison
- Input: Raw JSON from Step 2 + Screenshot from Step 1
- Processing:
- Render JSON layout as image
- Compare with original screenshot
- Calculate similarity score
- Decision Logic:
- ā
Similar: Proceed to Step 4
- ā Different: Return to Step 2 (max 5 times)
- Smart Retry: Iterative improvement with feedback
Purpose: Complete the conversion process
- Success Path: From Step 3 validation success
- Failure Path: When Step 3 reaches maximum retry limit
- Output: Final result status and processed data
- Step Flow: Step 1 āāā Step 2 āāā Step 3 āāā Step 4Step 2 āāāā OpenAI Agent
- AI Integration: Step 3 āāāāā Step 2
- Retry Loop: (conditional)
| State | Visual Indicator | Description |
| -------------- | -------------------------- | --------------------------- |
| Processing | š Animated border + timer | Step currently executing |
| Success | ā
Green border | Step completed successfully |
| Failure | ā Red border | Step failed to complete |
| Pending | āŖ Default border | Step waiting to execute |
- Build System: Vite + TypeScript
- DOM Processing: jsdom, parse5
- CSS Processing: css, csso
- Utilities: lodash
- Runtime: Node.js with TypeScript support
- Linting: ESLint with TypeScript support
- Type Checking: TypeScript 5.7+
- Package Manager: pnpm
- Build Tool: Rollup with TypeScript plugin
#### parseHtml(html: string, css: string)
Parses HTML and CSS into structured format for processing.
`typescript`
const result = parseHtml(htmlContent, cssContent);
#### getEntities({ html, raw }: GetEntitiesProps)
Fills element attributes using parsed HTML and raw JSON data.
`typescript`
const entities = getEntities({
html: htmlString,
raw: sectionRawData,
});
#### getStyles(input: GetStylesInput)
Extracts and processes CSS styles from input data.
`typescript`
const styles = getStyles(styleInput);
#### getStylesAEP(type: string, cssText: string)
Analyzes element properties from CSS text.
`typescript`
const analyzedStyles = getStylesAEP("div", cssText);
#### getEEP(data: RawDataEEPV2[])
Expands element properties from raw data.
`typescript`
const expandedProperties = getEEP(rawDataArray);
- Node.js 18+
- pnpm (recommended) or npm
`bashClone the repository
git clone
cd xobuilder-extractor
$3
`bash
Start development server
pnpm devBuild for production
pnpm buildRun production build
pnpm start
`š§ Configuration
$3
The project uses Vite for modern, fast builds with TypeScript support. Configuration can be found in:
-
vite.config.ts - Build configuration
- tsconfig.json - TypeScript settings
- eslint.config.js` - Code quality rulesEnsure your environment supports:
- ES2020+ features
- TypeScript 5.7+
- Modern DOM APIs through jsdom
- Tree Shaking: Eliminates unused code in production builds
- Code Splitting: Modular architecture supports lazy loading
- Type Safety: Full TypeScript coverage prevents runtime errors
- Efficient Parsing: Optimized HTML/CSS processing with specialized libraries
- Clean Architecture: Easy to extend with new processing steps
- Modular Design: Independent use cases and entities
- Retry Logic: Robust error handling and recovery
- AI Integration: Pluggable AI providers through abstraction layer
#### AI Conversion Failures
- Cause: Network issues or API limitations
- Solution: Check API keys and network connectivity
- Mitigation: Automatic retry logic handles temporary failures
#### Visual Comparison Mismatches
- Cause: Rendering differences or screenshot quality
- Solution: Adjust similarity threshold in validation logic
- Monitoring: Track retry patterns for optimization
#### Memory Usage
- Cause: Large HTML/CSS files or many concurrent processes
- Solution: Implement chunking for large files
- Prevention: Monitor and limit concurrent processing
1. Create feature branch from main
2. Implement changes following Clean Architecture
3. Add/update tests for new functionality
4. Ensure TypeScript compliance
5. Submit pull request with detailed description
- Follow existing architectural patterns
- Maintain type safety throughout
- Document complex business logic
- Use meaningful variable and function names
This project is licensed under the terms specified in the package.json file.
---
Built with ā¤ļø by HaiUTC
For questions or support, please refer to the project documentation or create an issue in the repository.