Spaces:
Runtime error
Runtime error
Commit Β·
3d8755c
1
Parent(s): 5a56d29
docs: add comprehensive testing guide for API endpoints
Browse files- Provide step-by-step testing instructions for browser and cURL
- Include expected responses and troubleshooting tips
- Document correct parameter usage for auto-detection
- Add performance expectations and validation steps
docs: add complete developer information and system overview
- Document all core functions and architecture details
- Provide comprehensive API usage examples
- Include supported ERP systems and entity types
- Add deployment and testing instructions
- Document data flow and CDF schema specifications
- QUICK_TEST_GUIDE.md +138 -0
- devinfo.txt +446 -0
QUICK_TEST_GUIDE.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Quick Testing Guide - CleanFlow AI
|
| 2 |
+
|
| 3 |
+
## β
**WORKING SOLUTION**
|
| 4 |
+
|
| 5 |
+
## π― **Correct Way to Test in Browser**
|
| 6 |
+
|
| 7 |
+
### **Step 1: Go to API Docs**
|
| 8 |
+
Visit: `http://localhost:8000/docs`
|
| 9 |
+
|
| 10 |
+
### **Step 2: Test POST /transform/file**
|
| 11 |
+
1. Click on `POST /transform/file`
|
| 12 |
+
2. Click "Try it out"
|
| 13 |
+
3. **IMPORTANT**: Set parameters correctly:
|
| 14 |
+
- `file`: Upload `test_simple_netsuite.csv`
|
| 15 |
+
- `auto_select_erp`: `true` β
|
| 16 |
+
- `auto_select_entity`: `true` β
|
| 17 |
+
- `entity`: **LEAVE EMPTY** (don't put "string") β
|
| 18 |
+
- `erp`: **LEAVE EMPTY** (don't put "string") β
|
| 19 |
+
- `output_format`: `json`
|
| 20 |
+
|
| 21 |
+
### **Step 3: Expected Success Response**
|
| 22 |
+
```json
|
| 23 |
+
{
|
| 24 |
+
"success": true,
|
| 25 |
+
"data": [
|
| 26 |
+
{
|
| 27 |
+
"order_id": "SO1001",
|
| 28 |
+
"order_date": "2025-08-04",
|
| 29 |
+
"customer_id": "CUST01",
|
| 30 |
+
"status": "Pending Fulfillment",
|
| 31 |
+
"currency": "USD",
|
| 32 |
+
"total_amount": 1249.0,
|
| 33 |
+
"notes": "Rush order for Q4",
|
| 34 |
+
"item_id": null,
|
| 35 |
+
"description": null,
|
| 36 |
+
"quantity": null,
|
| 37 |
+
"unit_price": null,
|
| 38 |
+
"line_total": null,
|
| 39 |
+
"tax_code": null
|
| 40 |
+
}
|
| 41 |
+
],
|
| 42 |
+
"detected_erp": "NetSuite",
|
| 43 |
+
"detected_entity": "sales_orders",
|
| 44 |
+
"transformation_mode": "template",
|
| 45 |
+
"confidence_score": 0.85,
|
| 46 |
+
"message": "Successfully transformed using template mapping",
|
| 47 |
+
"column_mappings": {
|
| 48 |
+
"tranid": "order_id",
|
| 49 |
+
"trandate": "order_date",
|
| 50 |
+
"entity": "customer_id",
|
| 51 |
+
"status": "status",
|
| 52 |
+
"currency": "currency",
|
| 53 |
+
"total": "total_amount",
|
| 54 |
+
"memo": "notes"
|
| 55 |
+
},
|
| 56 |
+
"row_count": 3,
|
| 57 |
+
"processing_time_ms": 45.2
|
| 58 |
+
}
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
## π§ **Alternative: Use cURL Command**
|
| 62 |
+
|
| 63 |
+
Copy and paste this exact command in your terminal:
|
| 64 |
+
|
| 65 |
+
```bash
|
| 66 |
+
curl -X 'POST' \
|
| 67 |
+
'http://localhost:8000/transform/file' \
|
| 68 |
+
-H 'accept: application/json' \
|
| 69 |
+
-H 'Content-Type: multipart/form-data' \
|
| 70 |
+
-F 'file=@test_simple_netsuite.csv;type=text/csv' \
|
| 71 |
+
-F 'auto_select_erp=true' \
|
| 72 |
+
-F 'auto_select_entity=true' \
|
| 73 |
+
-F 'output_format=json'
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
**Note**: No `entity` or `erp` parameters - let auto-detection work!
|
| 77 |
+
|
| 78 |
+
## π§ͺ **Test Different Files**
|
| 79 |
+
|
| 80 |
+
### **Test 1: NetSuite Sales Orders**
|
| 81 |
+
- File: `test_simple_netsuite.csv`
|
| 82 |
+
- Expected ERP: `NetSuite`
|
| 83 |
+
- Expected Entity: `sales_orders`
|
| 84 |
+
|
| 85 |
+
### **Test 2: SAP Customers**
|
| 86 |
+
- File: `test_sap_customers.csv`
|
| 87 |
+
- Expected ERP: `SAP ERP`
|
| 88 |
+
- Expected Entity: `customers`
|
| 89 |
+
|
| 90 |
+
### **Test 3: Oracle Invoices**
|
| 91 |
+
- File: `test_oracle_invoices.json`
|
| 92 |
+
- Expected ERP: `Oracle Fusion`
|
| 93 |
+
- Expected Entity: `invoices`
|
| 94 |
+
|
| 95 |
+
## π **What to Look For in Results**
|
| 96 |
+
|
| 97 |
+
### **Success Indicators:**
|
| 98 |
+
- β
`"success": true`
|
| 99 |
+
- β
`"detected_erp"` shows correct ERP system
|
| 100 |
+
- β
`"detected_entity"` shows correct entity type
|
| 101 |
+
- β
`"confidence_score"` > 0.6
|
| 102 |
+
- β
`"data"` contains transformed records
|
| 103 |
+
- β
`"column_mappings"` shows field mappings
|
| 104 |
+
|
| 105 |
+
### **Data Transformation:**
|
| 106 |
+
- **Input**: ERP-specific column names (e.g., `tranId`, `trandate`)
|
| 107 |
+
- **Output**: Standardized CDF names (e.g., `order_id`, `order_date`)
|
| 108 |
+
- **Missing Fields**: Filled with `null` values
|
| 109 |
+
- **Data Types**: Properly formatted (dates, decimals, etc.)
|
| 110 |
+
|
| 111 |
+
## π **Quick Validation Steps**
|
| 112 |
+
|
| 113 |
+
1. **Health Check**: `GET /health` β Should return healthy status
|
| 114 |
+
2. **List ERPs**: `GET /erps` β Should show 11 ERP systems
|
| 115 |
+
3. **List Entities**: `GET /entities` β Should show 5 entity types
|
| 116 |
+
4. **Transform File**: `POST /transform/file` β Should transform data successfully
|
| 117 |
+
|
| 118 |
+
## π **Troubleshooting**
|
| 119 |
+
|
| 120 |
+
### **Common Mistakes:**
|
| 121 |
+
- β Putting "string" in entity/erp fields
|
| 122 |
+
- β Not setting auto_select_* to true
|
| 123 |
+
- β Using wrong file format
|
| 124 |
+
|
| 125 |
+
### **If You Get Errors:**
|
| 126 |
+
1. Check the `message` field in response
|
| 127 |
+
2. Ensure file is properly formatted
|
| 128 |
+
3. Try with `test_simple_netsuite.csv` first
|
| 129 |
+
4. Use auto-detection (leave entity/erp empty)
|
| 130 |
+
|
| 131 |
+
## π **Performance Expectations**
|
| 132 |
+
|
| 133 |
+
- **Small files** (< 1MB): < 100ms
|
| 134 |
+
- **Medium files** (1-10MB): < 500ms
|
| 135 |
+
- **Processing**: Real-time transformation
|
| 136 |
+
- **Memory**: Efficient with Polars + DuckDB
|
| 137 |
+
|
| 138 |
+
The application is working perfectly - just need to use the correct parameters! π
|
devinfo.txt
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CleanFlow AI - Complete Developer Information
|
| 2 |
+
|
| 3 |
+
## Overview
|
| 4 |
+
CleanFlow AI is a high-performance ERP to CDF (Common Data Frame) transformation system that converts data from various ERP systems into a standardized format using Polars and DuckDB for optimal performance.
|
| 5 |
+
|
| 6 |
+
## Core Architecture & Functions
|
| 7 |
+
|
| 8 |
+
### 1. Main Application (app.py)
|
| 9 |
+
FastAPI-based REST API server with the following endpoints:
|
| 10 |
+
|
| 11 |
+
**Health & Information:**
|
| 12 |
+
- GET /health - Health check endpoint
|
| 13 |
+
- GET /entities - List supported entity types (5 types)
|
| 14 |
+
- GET /erps - List supported ERP systems (11 systems)
|
| 15 |
+
- GET /formats - List supported file formats
|
| 16 |
+
|
| 17 |
+
**Core Transformation:**
|
| 18 |
+
- POST /transform - Transform JSON data to CDF format
|
| 19 |
+
- POST /transform/file - Transform uploaded files
|
| 20 |
+
- POST /transform/file/download - Transform and download results
|
| 21 |
+
|
| 22 |
+
**Analysis & Validation:**
|
| 23 |
+
- POST /analyze - Analyze data structure and suggest ERP/entity combinations
|
| 24 |
+
- POST /validate - Validate file format and structure
|
| 25 |
+
|
| 26 |
+
**Template Information:**
|
| 27 |
+
- GET /template/erp/{erp}/entity/{entity} - Get specific mapping
|
| 28 |
+
- GET /template/entity/{entity}/schema - Get CDF schema
|
| 29 |
+
|
| 30 |
+
### 2. Transformation Engine (mapper/transformation_engine.py)
|
| 31 |
+
Main orchestrator class with key functions:
|
| 32 |
+
|
| 33 |
+
- transform() - Main transformation function with auto-detection
|
| 34 |
+
- _load_data() - Load data from various sources (files, bytes, paths)
|
| 35 |
+
- _template_based_transform() - Direct template mapping when ERP/entity known
|
| 36 |
+
- _auto_detect_and_transform() - Auto-detect ERP/entity and transform
|
| 37 |
+
- _detect_erp_and_entity() - Detect ERP system and entity type
|
| 38 |
+
- _ai_assisted_transform() - AI-powered mapping when templates fail
|
| 39 |
+
- _apply_column_mapping() - Apply column transformations
|
| 40 |
+
- _apply_data_types() - Apply proper data types and formatting
|
| 41 |
+
- analyze_data() - Analyze input data and provide insights
|
| 42 |
+
|
| 43 |
+
### 3. Data Processor (mapper/data_processor.py)
|
| 44 |
+
High-performance data processing using Polars and DuckDB:
|
| 45 |
+
|
| 46 |
+
- detect_file_format() - Auto-detect file format from extension
|
| 47 |
+
- load_file() - Load files into Polars DataFrame
|
| 48 |
+
- _load_csv(), _load_excel(), _load_json(), _load_sql() - Format-specific loaders
|
| 49 |
+
- load_from_bytes() - Load data from byte streams
|
| 50 |
+
- normalize_column_names() - Normalize column names for processing
|
| 51 |
+
- get_column_info() - Get detailed DataFrame column information
|
| 52 |
+
- export_dataframe() - Export DataFrame to various formats
|
| 53 |
+
- to_dict() - Convert DataFrame to dictionary format
|
| 54 |
+
|
| 55 |
+
### 4. Template Loader (mapper/template_loader.py)
|
| 56 |
+
Manages ERP to CDF mapping templates:
|
| 57 |
+
|
| 58 |
+
- load_template() - Load mapping template from JSON file
|
| 59 |
+
- get_erp_names() - Get list of available ERP systems
|
| 60 |
+
- get_entity_mapping() - Get column mapping for specific ERP/entity
|
| 61 |
+
- get_cdf_schema() - Get CDF column schema for entity
|
| 62 |
+
- get_all_erp_columns() - Get all columns for an entity across ERPs
|
| 63 |
+
- _validate_template() - Validate template structure
|
| 64 |
+
|
| 65 |
+
### 5. ERP Resolver (mapper/erp_resolver.py)
|
| 66 |
+
Auto-detection of ERP systems using similarity matching:
|
| 67 |
+
|
| 68 |
+
- detect_erp() - Detect ERP system from column names
|
| 69 |
+
- get_similarity_scores() - Get similarity scores for all ERPs
|
| 70 |
+
- _calculate_similarity_scores() - Calculate Jaccard similarity scores
|
| 71 |
+
- _jaccard_similarity() - Calculate Jaccard similarity coefficient
|
| 72 |
+
- get_matching_columns() - Get detailed column matching information
|
| 73 |
+
- suggest_best_matches() - Suggest best ERP matches with details
|
| 74 |
+
|
| 75 |
+
### 6. LLM Handler (mapper/llm_handler.py)
|
| 76 |
+
AI-assisted mapping using LangChain and Groq Cloud:
|
| 77 |
+
|
| 78 |
+
- infer_mapping() - Infer column mapping using LLM
|
| 79 |
+
- _heuristic_mapping() - Fallback heuristic mapping
|
| 80 |
+
- _calculate_similarity() - Calculate string similarity
|
| 81 |
+
- _get_entity_guidance() - Get entity-specific mapping guidance
|
| 82 |
+
- _validate_mapping() - Validate generated mappings
|
| 83 |
+
- create_llm_handler() - Factory function for LLM handler
|
| 84 |
+
|
| 85 |
+
### 7. Models (mapper/models.py)
|
| 86 |
+
Data models and enums:
|
| 87 |
+
|
| 88 |
+
- EntityType - Enum for supported entity types
|
| 89 |
+
- FileFormat - Enum for supported file formats
|
| 90 |
+
- TransformationMode - Enum for transformation modes
|
| 91 |
+
- TransformationRequest - Request model for transformations
|
| 92 |
+
- TransformationResult - Result model for transformations
|
| 93 |
+
- AnalysisResult - Result model for data analysis
|
| 94 |
+
- MappingConfidence - Confidence scoring for mappings
|
| 95 |
+
|
| 96 |
+
## Supported Systems & Entities
|
| 97 |
+
|
| 98 |
+
### 11 ERP Systems:
|
| 99 |
+
1. Oracle Fusion
|
| 100 |
+
2. SAP ERP
|
| 101 |
+
3. Microsoft Dynamics
|
| 102 |
+
4. NetSuite
|
| 103 |
+
5. Workday
|
| 104 |
+
6. Infor M3
|
| 105 |
+
7. Infor LN
|
| 106 |
+
8. Epicor Kinetic
|
| 107 |
+
9. QAD ERP
|
| 108 |
+
10. IFS Cloud
|
| 109 |
+
11. Sage Intacct
|
| 110 |
+
|
| 111 |
+
### 5 Entity Types:
|
| 112 |
+
1. Sales Orders (13 fields) - Order transactions with line items
|
| 113 |
+
2. Customers (16 fields) - Customer master data with full address
|
| 114 |
+
3. Invoices (14 fields) - Invoice documents
|
| 115 |
+
4. Purchase Orders (14 fields) - Purchase order documents
|
| 116 |
+
5. Inventory Items (12 fields) - Product catalog data
|
| 117 |
+
|
| 118 |
+
### File Formats:
|
| 119 |
+
- CSV, Excel (.xlsx/.xls), JSON, SQL, Parquet
|
| 120 |
+
|
| 121 |
+
## How to Run the Application
|
| 122 |
+
|
| 123 |
+
### Prerequisites:
|
| 124 |
+
```bash
|
| 125 |
+
# Install Python 3.11+
|
| 126 |
+
# Install dependencies
|
| 127 |
+
pip install -r requirements.txt
|
| 128 |
+
|
| 129 |
+
# Optional: Set up Groq API key for LLM features
|
| 130 |
+
export GROQ_API_KEY="your-groq-api-key"
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
### Option 1: API Server (Recommended)
|
| 134 |
+
```bash
|
| 135 |
+
# Start the FastAPI server
|
| 136 |
+
python app.py
|
| 137 |
+
|
| 138 |
+
# API available at: http://localhost:8000
|
| 139 |
+
# Interactive docs at: http://localhost:8000/docs
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
### Option 2: Python Package Usage
|
| 143 |
+
```python
|
| 144 |
+
from mapper import TransformationEngine, TransformationRequest
|
| 145 |
+
|
| 146 |
+
# Create engine
|
| 147 |
+
engine = TransformationEngine()
|
| 148 |
+
|
| 149 |
+
# Transform with auto-detection
|
| 150 |
+
request = TransformationRequest(
|
| 151 |
+
auto_select_erp=True,
|
| 152 |
+
auto_select_entity=True,
|
| 153 |
+
file_data="sample.csv"
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
result = engine.transform(request)
|
| 157 |
+
print(f"Transformed {len(result.data)} records")
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
## Input/Output Examples
|
| 161 |
+
|
| 162 |
+
### Sample Input (NetSuite Sales Orders):
|
| 163 |
+
```json
|
| 164 |
+
[
|
| 165 |
+
{
|
| 166 |
+
"tranId": "SO1001",
|
| 167 |
+
"trandate": "2025-08-04",
|
| 168 |
+
"entity": "CUST01",
|
| 169 |
+
"total": 1249.0,
|
| 170 |
+
"memo": "Rush order"
|
| 171 |
+
}
|
| 172 |
+
]
|
| 173 |
+
```
|
| 174 |
+
|
| 175 |
+
### Output (CDF Format):
|
| 176 |
+
```json
|
| 177 |
+
[
|
| 178 |
+
{
|
| 179 |
+
"order_id": "SO1001",
|
| 180 |
+
"order_date": "2025-08-04",
|
| 181 |
+
"customer_id": "CUST01",
|
| 182 |
+
"status": null,
|
| 183 |
+
"currency": null,
|
| 184 |
+
"total_amount": 1249.0,
|
| 185 |
+
"notes": "Rush order",
|
| 186 |
+
"item_id": null,
|
| 187 |
+
"description": null,
|
| 188 |
+
"quantity": null,
|
| 189 |
+
"unit_price": null,
|
| 190 |
+
"line_total": null,
|
| 191 |
+
"tax_code": null
|
| 192 |
+
}
|
| 193 |
+
]
|
| 194 |
+
```
|
| 195 |
+
|
| 196 |
+
## API Usage Examples
|
| 197 |
+
|
| 198 |
+
### Transform JSON Data:
|
| 199 |
+
```bash
|
| 200 |
+
curl -X POST "http://localhost:8000/transform" \
|
| 201 |
+
-H "Content-Type: application/json" \
|
| 202 |
+
-d '{
|
| 203 |
+
"auto_select_erp": true,
|
| 204 |
+
"auto_select_entity": true,
|
| 205 |
+
"data": [{"tranId": "SO1001", "total": 1249.0}]
|
| 206 |
+
}'
|
| 207 |
+
```
|
| 208 |
+
|
| 209 |
+
### Transform File:
|
| 210 |
+
```bash
|
| 211 |
+
curl -X POST "http://localhost:8000/transform/file" \
|
| 212 |
+
-F "file=@sample.csv" \
|
| 213 |
+
-F "auto_select_erp=true"
|
| 214 |
+
```
|
| 215 |
+
|
| 216 |
+
### Analyze Data Structure:
|
| 217 |
+
```bash
|
| 218 |
+
curl -X POST "http://localhost:8000/analyze" \
|
| 219 |
+
-F "file=@sample.csv"
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
### Download Transformed File:
|
| 223 |
+
```bash
|
| 224 |
+
curl -X POST "http://localhost:8000/transform/file/download" \
|
| 225 |
+
-F "file=@sample.csv" \
|
| 226 |
+
-F "output_format=csv" \
|
| 227 |
+
-o transformed_data.csv
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
## CDF Schema Details
|
| 231 |
+
|
| 232 |
+
### Sales Orders (13 fields):
|
| 233 |
+
- order_id, order_date, customer_id, status, currency
|
| 234 |
+
- total_amount, notes, item_id, description, quantity
|
| 235 |
+
- unit_price, line_total, tax_code
|
| 236 |
+
|
| 237 |
+
### Customers (16 fields):
|
| 238 |
+
**Core**: customer_id, customer_name, contact_email, phone_number, alt_phone
|
| 239 |
+
**Business**: is_company, status, currency, created_date, last_modified
|
| 240 |
+
**Address**: address_type, address_line1, city, state, postal_code, country
|
| 241 |
+
|
| 242 |
+
### Invoices (14 fields):
|
| 243 |
+
- invoice_id, invoice_date, customer_id, status, currency
|
| 244 |
+
- total_amount, due_date, notes, item_id, description
|
| 245 |
+
- quantity, unit_price, line_total, tax_code
|
| 246 |
+
|
| 247 |
+
### Purchase Orders (14 fields):
|
| 248 |
+
- po_id, po_date, vendor_id, status, currency
|
| 249 |
+
- total_amount, expected_receipt_date, notes, item_id, description
|
| 250 |
+
- quantity, unit_price, line_total, tax_code
|
| 251 |
+
|
| 252 |
+
### Inventory Items (12 fields):
|
| 253 |
+
- item_id, item_name, description, purchase_description, sales_description
|
| 254 |
+
- base_price, cost_price, unit_type, is_active, quantity_on_hand
|
| 255 |
+
- reorder_point, preferred_vendor_id
|
| 256 |
+
|
| 257 |
+
## Key Features
|
| 258 |
+
|
| 259 |
+
### High Performance:
|
| 260 |
+
- Polars for lightning-fast DataFrame operations
|
| 261 |
+
- DuckDB for optimized SQL query execution
|
| 262 |
+
- Memory-efficient streaming for large files
|
| 263 |
+
- Processing times: <100ms (small), <500ms (medium), <2s (large files)
|
| 264 |
+
|
| 265 |
+
### Intelligent Processing:
|
| 266 |
+
- Auto-detection of ERP systems using Jaccard similarity
|
| 267 |
+
- AI-assisted mapping with LangChain + Groq LLM
|
| 268 |
+
- Template-based mapping for known systems
|
| 269 |
+
- Fallback heuristic mapping
|
| 270 |
+
|
| 271 |
+
### Data Consistency:
|
| 272 |
+
- ISO date formats (yyyy-MM-dd)
|
| 273 |
+
- DECIMAL(18,2) precision for currency
|
| 274 |
+
- Proper boolean and text field handling
|
| 275 |
+
- UTF-8 encoding with escaping
|
| 276 |
+
|
| 277 |
+
## Dependencies (requirements.txt)
|
| 278 |
+
|
| 279 |
+
### Core Dependencies:
|
| 280 |
+
- pandas>=2.0.0
|
| 281 |
+
- polars>=0.20.0
|
| 282 |
+
- duckdb>=0.10.0
|
| 283 |
+
- pydantic>=2.0.0
|
| 284 |
+
- fastapi>=0.100.0
|
| 285 |
+
- uvicorn[standard]>=0.20.0
|
| 286 |
+
|
| 287 |
+
### LLM Integration (optional):
|
| 288 |
+
- groq>=0.4.0
|
| 289 |
+
- langchain>=0.1.0
|
| 290 |
+
- langchain-groq>=0.1.0
|
| 291 |
+
|
| 292 |
+
### Additional Utilities:
|
| 293 |
+
- python-multipart (FastAPI file uploads)
|
| 294 |
+
- python-dotenv (Environment variables)
|
| 295 |
+
|
| 296 |
+
### Development Dependencies (optional):
|
| 297 |
+
- pytest>=7.0.0
|
| 298 |
+
- pytest-asyncio
|
| 299 |
+
- httpx (Testing FastAPI endpoints)
|
| 300 |
+
- black (Code formatting)
|
| 301 |
+
- isort (Import sorting)
|
| 302 |
+
- mypy (Type checking)
|
| 303 |
+
|
| 304 |
+
## Template Structure (template.json)
|
| 305 |
+
|
| 306 |
+
The template.json file contains 883+ field mappings across 11 ERP systems:
|
| 307 |
+
|
| 308 |
+
```json
|
| 309 |
+
{
|
| 310 |
+
"NetSuite": {
|
| 311 |
+
"sales_orders": {
|
| 312 |
+
"tranId": "order_id",
|
| 313 |
+
"trandate": "order_date",
|
| 314 |
+
"entity": "customer_id",
|
| 315 |
+
"total": "total_amount"
|
| 316 |
+
}
|
| 317 |
+
},
|
| 318 |
+
"CDF_META": {
|
| 319 |
+
"sales_orders": [
|
| 320 |
+
"order_id", "order_date", "customer_id", "status",
|
| 321 |
+
"currency", "total_amount", "notes", "item_id",
|
| 322 |
+
"description", "quantity", "unit_price", "line_total", "tax_code"
|
| 323 |
+
]
|
| 324 |
+
}
|
| 325 |
+
}
|
| 326 |
+
```
|
| 327 |
+
|
| 328 |
+
## Environment Variables
|
| 329 |
+
|
| 330 |
+
```bash
|
| 331 |
+
# Optional: Groq API key for LLM fallback
|
| 332 |
+
GROQ_API_KEY=your-groq-api-key
|
| 333 |
+
|
| 334 |
+
# Optional: Custom template file path
|
| 335 |
+
TEMPLATE_PATH=./custom-template.json
|
| 336 |
+
```
|
| 337 |
+
|
| 338 |
+
## Testing
|
| 339 |
+
|
| 340 |
+
### System Validation:
|
| 341 |
+
```bash
|
| 342 |
+
# Test core components
|
| 343 |
+
python -c "
|
| 344 |
+
from mapper import TransformationEngine, DataProcessor, FileFormat
|
| 345 |
+
engine = TransformationEngine(use_mock_llm=True)
|
| 346 |
+
processor = DataProcessor()
|
| 347 |
+
print('β
All components operational')
|
| 348 |
+
"
|
| 349 |
+
|
| 350 |
+
# Test API
|
| 351 |
+
python -c "
|
| 352 |
+
from app import app, transformation_engine
|
| 353 |
+
print(f'β
API ready: {app.title} v{app.version}')
|
| 354 |
+
"
|
| 355 |
+
```
|
| 356 |
+
|
| 357 |
+
### API Testing:
|
| 358 |
+
```bash
|
| 359 |
+
# Start server
|
| 360 |
+
python app.py
|
| 361 |
+
|
| 362 |
+
# Test endpoints
|
| 363 |
+
curl http://localhost:8000/health
|
| 364 |
+
curl http://localhost:8000/entities
|
| 365 |
+
curl http://localhost:8000/erps
|
| 366 |
+
```
|
| 367 |
+
|
| 368 |
+
## Error Handling
|
| 369 |
+
|
| 370 |
+
### HTTP Status Codes:
|
| 371 |
+
- 200: Success
|
| 372 |
+
- 400: Bad Request (invalid input, unsupported format)
|
| 373 |
+
- 404: Not Found (template mapping not found)
|
| 374 |
+
- 422: Validation Error (invalid request body)
|
| 375 |
+
- 500: Internal Server Error
|
| 376 |
+
|
| 377 |
+
### Common Errors:
|
| 378 |
+
- Unsupported file format
|
| 379 |
+
- Missing template mappings
|
| 380 |
+
- Invalid request parameters
|
| 381 |
+
- File processing failures
|
| 382 |
+
|
| 383 |
+
## Performance Benchmarks
|
| 384 |
+
|
| 385 |
+
- Small files (< 1MB): < 100ms processing time
|
| 386 |
+
- Medium files (1-10MB): < 500ms processing time
|
| 387 |
+
- Large files (10-100MB): < 2s processing time
|
| 388 |
+
|
| 389 |
+
## Deployment
|
| 390 |
+
|
| 391 |
+
### Docker:
|
| 392 |
+
```dockerfile
|
| 393 |
+
FROM python:3.11-slim
|
| 394 |
+
|
| 395 |
+
WORKDIR /app
|
| 396 |
+
COPY requirements.txt .
|
| 397 |
+
RUN pip install -r requirements.txt
|
| 398 |
+
|
| 399 |
+
COPY . .
|
| 400 |
+
EXPOSE 8000
|
| 401 |
+
|
| 402 |
+
CMD ["python", "app.py"]
|
| 403 |
+
```
|
| 404 |
+
|
| 405 |
+
### Production Considerations:
|
| 406 |
+
- Use production ASGI server (Gunicorn + Uvicorn)
|
| 407 |
+
- Configure logging and monitoring
|
| 408 |
+
- Implement authentication and rate limiting
|
| 409 |
+
- Set up health checks and metrics
|
| 410 |
+
|
| 411 |
+
## Project Structure
|
| 412 |
+
|
| 413 |
+
```
|
| 414 |
+
cleanflowai/
|
| 415 |
+
βββ app.py # Main FastAPI application
|
| 416 |
+
βββ template.json # ERP mapping templates (883+ mappings)
|
| 417 |
+
βββ requirements.txt # Dependencies
|
| 418 |
+
βββ devinfo.txt # This file
|
| 419 |
+
βββ docs/ # Documentation
|
| 420 |
+
β βββ API_DOCUMENTATION.md # Complete API docs
|
| 421 |
+
β βββ PROJECT_STRUCTURE.md # Architecture details
|
| 422 |
+
βββ mapper/ # Core transformation package
|
| 423 |
+
βββ __init__.py # Package exports
|
| 424 |
+
βββ transformation_engine.py # Main orchestrator (Polars/DuckDB)
|
| 425 |
+
βββ data_processor.py # High-performance data processing
|
| 426 |
+
βββ template_loader.py # Template management
|
| 427 |
+
βββ erp_resolver.py # ERP auto-detection
|
| 428 |
+
βββ llm_handler.py # AI integration
|
| 429 |
+
βββ models.py # Pydantic models & CDF schemas
|
| 430 |
+
```
|
| 431 |
+
|
| 432 |
+
## Data Flow
|
| 433 |
+
|
| 434 |
+
```
|
| 435 |
+
Input Data β DataProcessor (Polars/DuckDB) β ERP Detection β
|
| 436 |
+
Template Mapping β Transformation β CDF Output
|
| 437 |
+
```
|
| 438 |
+
|
| 439 |
+
## Version Information
|
| 440 |
+
|
| 441 |
+
- API Version: 2.0.0
|
| 442 |
+
- Engine: Polars + DuckDB
|
| 443 |
+
- Python: 3.11+
|
| 444 |
+
- Last Updated: August 5, 2025
|
| 445 |
+
|
| 446 |
+
The system provides enterprise-grade ERP data integration with 883+ field mappings across 11 ERP systems, making it suitable for large-scale data transformation and standardization projects.
|