Spaces:
Runtime error
Runtime error
|
Download docs/PROJECT_STRUCTURE.md from CleanflowAI/cleanflowai: direct link, hf CLI and curl.
- Browser
- Download file 8.96 kB
-
https://huggingface.co/spaces/CleanflowAI/cleanflowai/resolve/main/docs/PROJECT_STRUCTURE.md
- Command line
-
hf download hf://spaces/CleanflowAI/cleanflowai/docs/PROJECT_STRUCTURE.md
-
curl -L -o PROJECT_STRUCTURE.md https://huggingface.co/spaces/CleanflowAI/cleanflowai/resolve/main/docs/PROJECT_STRUCTURE.md
8.96 kB
Project Structure
Overview
This document describes the clean, restructured architecture of the ERP to CDF Transformation system. The project has been optimized for maintainability, performance, and ease of use.
Directory Structure
cleanflowai/
βββ app.py # Main FastAPI application (renamed from api_v2.py)
βββ template.json # ERP mapping templates (11 systems, 883+ mappings)
βββ requirements.txt # Python dependencies
βββ README.md # Project overview and quick start
βββ CHANGELOG.md # Version history and changes
βββ ERP_SYSTEM_COVERAGE.md # Detailed ERP system coverage
βββ ERP-CDF-Mapping.md # Data format consistency guidelines
βββ .gitignore # Git ignore patterns
βββ docs/ # Documentation directory
β βββ API_DOCUMENTATION.md # Comprehensive API documentation
β βββ PROJECT_STRUCTURE.md # This file
βββ mapper/ # Core transformation package
βββ __init__.py # Package exports and convenience functions
βββ models.py # Pydantic models and CDF schemas
βββ data_processor.py # High-performance Polars/DuckDB processor
βββ transformation_engine.py # Main transformation orchestrator
βββ template_loader.py # Template loading and caching
βββ erp_resolver.py # ERP auto-detection logic
βββ llm_handler.py # LLM integration for unknown mappings
Removed Files (Cleanup)
The following obsolete files were removed during restructuring:
Legacy Files
gdf_to_cdf_mapper.py- Old reference implementationapi.py- Old API v1.0 (replaced byapp.py)main.py- Old CLI tool (functionality moved to API)mapper/converter.py- Old pandas-based converter (replaced bytransformation_engine.py)
Duplicate/Temporary Files
template (1).json- Duplicate template fileexplain.txt- Temporary explanation filegdf_to_cdf_algorithm.md- Old algorithm documentationtests/- Empty test directory
Core Components
1. FastAPI Application (app.py)
Purpose: Main API server with comprehensive REST endpoints
Key Features:
- High-performance transformation endpoints
- File upload/download capabilities
- Data analysis and validation
- Template inspection utilities
- Comprehensive error handling
- Interactive API documentation
Endpoints:
POST /transform- Transform JSON dataPOST /transform/file- Transform uploaded filesPOST /transform/file/download- Transform and downloadPOST /analyze- Analyze data structurePOST /validate- Validate file formatGET /health,/entities,/erps,/formats- Information endpoints
2. Transformation Engine (mapper/transformation_engine.py)
Purpose: Core transformation orchestrator using Polars/DuckDB
Key Features:
- High-performance data processing
- Intelligent ERP/entity auto-detection
- Template-based and AI-assisted mapping
- Multiple file format support
- Data format consistency enforcement
Classes:
TransformationEngine- Main orchestratorTransformationRequest- Request modelTransformationResult- Response modelTransformationMode- Processing mode enum
3. Data Processor (mapper/data_processor.py)
Purpose: High-performance data loading and processing
Key Features:
- Polars DataFrames for fast processing
- DuckDB for SQL query optimization
- Support for CSV, Excel, JSON, SQL, Parquet
- Memory-efficient large file handling
- Data type inference and conversion
Classes:
DataProcessor- Main processor classFileFormat- Supported format enum
4. Template System
Template Loader (mapper/template_loader.py)
- Loads and caches ERP mapping templates
- Provides schema validation
- Supports custom template paths
ERP Resolver (mapper/erp_resolver.py)
- Auto-detects ERP systems using Jaccard similarity
- Provides confidence scoring
- Suggests best matches for unknown data
5. AI Integration (mapper/llm_handler.py)
Purpose: LLM integration for unknown ERP mappings
Features:
- OpenAI GPT integration
- Mock handler for testing
- Fallback mapping generation
- Error handling and retries
6. Data Models (mapper/models.py)
Purpose: Pydantic models and CDF schemas
Key Models:
EntityType- Supported entity types enumSalesOrderCDF- Sales order schema (13 fields)CustomerCDF- Customer schema (16 fields with full address)InvoiceCDF- Invoice schema (14 fields)PurchaseOrderCDF- Purchase order schema (14 fields)InventoryItemCDF- Inventory item schema (12 fields)
Package Architecture
Import Structure
# Main imports
from mapper import (
TransformationEngine,
TransformationRequest,
DataProcessor,
FileFormat,
EntityType
)
# Convenience functions
from mapper import create_transformation_engine, quick_transform
Dependency Flow
app.py
βββ mapper.transformation_engine
β βββ mapper.data_processor (Polars/DuckDB)
β βββ mapper.template_loader
β βββ mapper.erp_resolver
β βββ mapper.llm_handler
β βββ mapper.models
βββ FastAPI + Uvicorn
Data Flow
1. Request Processing
HTTP Request β FastAPI β TransformationEngine β DataProcessor
2. ERP Detection
Input Data β Column Analysis β ERP Resolver β Template Matching
3. Transformation
Raw Data β Polars DataFrame β Column Mapping β CDF Schema β Output
4. Response
Transformed Data β JSON/File Response β HTTP Response
Configuration
Environment Variables
OPENAI_API_KEY- Optional: For LLM fallback functionalityTEMPLATE_PATH- Optional: Custom template file path
Template Configuration
- Location:
template.json - Format: Nested JSON with ERP β Entity β Field mappings
- Coverage: 11 ERP systems, 5 entity types, 883+ field mappings
Performance Characteristics
Processing Speed
- Small files (< 1MB): < 100ms
- Medium files (1-10MB): < 500ms
- Large files (10-100MB): < 2s
Memory Usage
- Polars: Memory-efficient columnar processing
- DuckDB: Optimized SQL query execution
- Streaming: Large file support without memory overflow
Scalability
- Concurrent requests: FastAPI async support
- File formats: Extensible format support
- ERP systems: Template-driven expansion
Testing Strategy
Unit Tests
- Component-level testing for each module
- Mock LLM handler for consistent testing
- Template validation tests
Integration Tests
- End-to-end API testing
- File format compatibility tests
- ERP detection accuracy tests
Performance Tests
- Load testing with various file sizes
- Memory usage profiling
- Concurrent request handling
Deployment Options
Local Development
python app.py
# API available at http://localhost:8000
Docker Deployment
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["python", "app.py"]
Production Considerations
- Use production ASGI server (Gunicorn + Uvicorn)
- Configure proper logging and monitoring
- Implement authentication and rate limiting
- Set up health checks and metrics
Extension Points
Adding New ERP Systems
- Update
template.jsonwith new mappings - Test with sample data
- Update documentation
Adding New Entity Types
- Define new CDF model in
models.py - Add entity type to
EntityTypeenum - Update template structure
- Add validation logic
Adding New File Formats
- Extend
FileFormatenum - Implement loader in
DataProcessor - Add format detection logic
- Update API documentation
Maintenance
Regular Tasks
- Update ERP system mappings as needed
- Monitor API performance and errors
- Update dependencies for security patches
- Review and update documentation
Monitoring Points
- API response times
- Error rates by endpoint
- File processing success rates
- ERP detection accuracy
- Memory and CPU usage
Security Considerations
Input Validation
- File size limits
- File type validation
- SQL injection prevention
- XSS protection in API responses
Data Privacy
- No persistent data storage
- Temporary file cleanup
- Secure file handling
- Optional data encryption
API Security
- Rate limiting (recommended for production)
- Authentication (implement as needed)
- CORS configuration
- Input sanitization
Last Updated: August 5, 2025
Version: 2.0.0
Architecture: Clean, High-Performance, Production-Ready