3TE/data_schemas.md
Nicolas Cantu 5c7137f3d2 Add administrative procedures to module components and centralized regulation characteristics configuration
**Motivations :**
* Allow associating administrative procedures to module components with status tracking
* Centralize regulation characteristics configuration for better data consistency
* Link regulation characteristics to wastes, regulators, ecosystems, and module components

**Root causes :**
* Need to track administrative procedures per module component
* Regulation characteristics were hardcoded in multiple places, causing inconsistency
* No centralized way to manage and reference regulation characteristics

**Correctifs :**
* Added ModuleComponentProcedureAssociation interface with procedureId, status, and notes
* Created RegulationCharacteristic entity with name, code, category, description, unit, isBoolean, minValue, maxValue
* Added regulationCharacteristicIds field to Waste, NaturalRegulator, Ecosystem, and ModuleComponent
* Updated all configuration pages to use regulation characteristics from centralized configuration
* Created RegulationCharacteristicsConfigurationPage for managing characteristics
* Added seeds for regulation characteristics (31 characteristics covering all categories)
* Added seeds for companies (4NK Water & Waste default company)

**Evolutions :**
* Module components can now have associated administrative procedures with status (toDo, done, na)
* Regulation characteristics are now centralized and can be referenced by multiple entities
* All regulation needs and characteristics are now managed through a single configuration page
* Business plans can be added to all entities (already implemented, documented in data_schemas.md)
* Updated data_schemas.md with complete documentation of all entities, relations, and validation rules

**Page affectées :**
* src/pages/configuration/ModuleComponentsConfigurationPage.tsx - Added administrative procedures section
* src/pages/configuration/RegulationCharacteristicsConfigurationPage.tsx - New page for managing characteristics
* src/pages/configuration/WasteConfigurationPage.tsx - Updated to use regulation characteristics
* src/pages/configuration/RegulatorsConfigurationPage.tsx - Updated to use regulation characteristics
* src/pages/configuration/EcosystemsConfigurationPage.tsx - Updated to use regulation characteristics
* src/types/index.ts - Added new interfaces and fields
* src/utils/storage.ts - Added regulation characteristics and companies to storage
* data_schemas.md - Complete documentation update
* data/seeds/regulation-characteristics-seeds.json - New seed file
* data/seeds/companies-seeds.json - New seed file
2025-12-10 08:27:52 +01:00

849 lines
28 KiB
Markdown

# Data Schemas and Relations
## 1. JSON Data Structure
### 1.1 Root Storage Structure
```json
{
"version": "1.0.0",
"lastModified": "2024-01-01T00:00:00Z",
"users": [],
"wastes": [],
"regulators": [],
"services": [],
"wasteOrigins": [],
"transporters": [],
"moduleComponents": [],
"ecosystems": [],
"regulationCharacteristics": [],
"treatmentSites": [],
"wasteSites": [],
"investors": [],
"administrativeProcedures": [],
"companies": [],
"projects": []
}
```
## 2. Entity Schemas
### 2.1 User Schema
```json
{
"id": "string (UUID)",
"username": "string",
"password": "string (hashed or plain for localhost)",
"createdAt": "ISO 8601 date string",
"lastLogin": "ISO 8601 date string"
}
```
### 2.2 Waste Schema
```json
{
"id": "string (UUID)",
"name": "string",
"originType": "string (animals|markets|restaurants|other)",
"originSubType": "string (specific type, optional)",
"wasteOriginId": "string (optional, reference to WasteOrigin)",
"originUnitsPer1000m3Methane": "number",
"bmp": "number (Nm³ CH₄/kg VS)",
"waterPercentage": "number (0-100)",
"regulationNeeds": "string[] (array of regulation need codes)",
"regulationCharacteristicIds": "string[] (optional, references to RegulationCharacteristic)",
"regulatoryCharacteristics": {
"nitrogen": "number (optional)",
"ammoniacalNitrogen": "number (optional)",
"phosphorus": "number (optional)",
"potassium": "number (optional)",
"carbonNitrogenRatio": "number (optional)",
"arsenicElimination": "boolean (optional)",
"zincElimination": "boolean (optional)",
"aluminumElimination": "boolean (optional)",
"copperElimination": "boolean (optional)",
"heavyMetalsElimination": "boolean (optional)",
"pathogenElimination": "boolean (optional)",
"lowCNRatioEnrichment": "boolean (optional)",
"medicationElimination": "boolean (optional)",
"depositElimination": "boolean (optional)",
"odorElimination": "boolean (optional)",
"turbidityReduction": "boolean (optional)",
"sodiumReduction": "boolean (optional)",
"chlorineReduction": "boolean (optional)",
"electricalConductivityReduction": "boolean (optional)",
"sulfideElimination": "boolean (optional)",
"methaneElimination": "boolean (optional)",
"co2Elimination": "boolean (optional)",
"polyphenolElimination": "boolean (optional)",
"refractoryFractionsElimination": "boolean (optional)",
"microbiologicalCompetition": "boolean (optional)",
"oilEmulsification": "boolean (optional)",
"acidityReduction": "boolean (optional)",
"phIncrease": "boolean (optional)",
"phReduction": "boolean (optional)",
"phAdjustment": "number (optional, -14 to 14)"
},
"regulators": [
{
"regulatorId": "string (reference to NaturalRegulator)",
"percentage": "number (0-100, percentage of global volume)"
}
],
"maxStorageDuration": "number (days)",
"businessPlan": "BusinessPlan (optional)",
"notes": "string (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.3 Natural Regulator Schema
```json
{
"id": "string (UUID)",
"name": "string",
"type": "string",
"regulationCharacteristicIds": "string[] (optional, references to RegulationCharacteristic)",
"regulatoryCharacteristics": {
"nitrogen": "number (optional)",
"ammoniacalNitrogen": "number (optional)",
"phosphorus": "number (optional)",
"potassium": "number (optional)",
"carbonNitrogenRatio": "number (optional)",
"arsenicElimination": "boolean (optional)",
"zincElimination": "boolean (optional)",
"aluminumElimination": "boolean (optional)",
"copperElimination": "boolean (optional)",
"heavyMetalsElimination": "boolean (optional)",
"metalBinding": "boolean (optional)",
"pathogenReduction": "boolean (optional)",
"lowCNRatioEnrichment": "boolean (optional)",
"medicationElimination": "boolean (optional)",
"depositElimination": "boolean (optional)",
"odorElimination": "boolean (optional)",
"turbidityReduction": "boolean (optional)",
"sodiumReduction": "boolean (optional)",
"chlorineReduction": "boolean (optional)",
"electricalConductivityReduction": "boolean (optional)",
"sulfideElimination": "boolean (optional)",
"methaneElimination": "boolean (optional)",
"co2Elimination": "boolean (optional)",
"polyphenolElimination": "boolean (optional)",
"refractoryFractionsElimination": "boolean (optional)",
"microbiologicalCompetition": "boolean (optional)",
"oilEmulsification": "boolean (optional)",
"acidityReduction": "boolean (optional)",
"phIncrease": "boolean (optional)",
"phReduction": "boolean (optional)",
"phAdjustment": "number (optional, -14 to 14)"
},
"applicationConditions": "string",
"dosageRequirements": {
"min": "number",
"max": "number",
"unit": "string (kg/t|L/t|%)"
},
"businessPlan": "BusinessPlan (optional)",
"notes": "string (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.4 Service Schema
```json
{
"id": "string (UUID)",
"name": "string",
"type": "string (rawRental|biologicalTreatment|bitcoinManagement|fertilizers|wasteHeat|carbonCredits|brownfield|transport)",
"pricing": {
"year1": "number (€/module/year)",
"year2": "number (€/module/year)",
"year3": "number (€/module/year)",
"year4": "number (€/module/year)",
"year5": "number (€/module/year)",
"year6": "number (€/module/year)",
"year7": "number (€/module/year)",
"year8": "number (€/module/year)",
"year9": "number (€/module/year)",
"year10": "number (€/module/year)"
},
"businessPlan": "BusinessPlan (optional)",
"notes": "string (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.5 WasteOrigin Schema
```json
{
"id": "string (UUID)",
"name": "string",
"type": "string",
"subType": "string (optional)",
"description": "string (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.6 Transporter Schema
```json
{
"id": "string (UUID)",
"name": "string",
"type": "string",
"description": "string (optional)",
"contact": {
"name": "string",
"email": "string (optional)",
"phone": "string (optional)",
"address": "string (optional)"
},
"capacity": "string (e.g., '10 tons', '20 m³')",
"transportConditions": "string (e.g., 'refrigerated', 'hazardous materials')",
"businessPlan": "BusinessPlan (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.7 ModuleComponent Schema
```json
{
"id": "string (UUID)",
"name": "string",
"type": "string (firstMethanization|waterEvaporation|bioremediationEcosystem1|bioremediationEcosystem2|bioremediationEcosystem3|secondMethanization|waterEvaporationComposting|waterUvcTreatment|waterStorage|spirulinaWaterStorage|solarPanels|bitcoinMining)",
"isOptional": "boolean",
"defaultDuration": "number",
"durationUnit": "string (days|hours)",
"waterConsumptionPerDay": {
"january": "number (optional)",
"february": "number (optional)",
"march": "number (optional)",
"april": "number (optional)",
"may": "number (optional)",
"june": "number (optional)",
"july": "number (optional)",
"august": "number (optional)",
"september": "number (optional)",
"october": "number (optional)",
"november": "number (optional)",
"december": "number (optional)"
},
"heatConsumptionPerDay": {
"january": "number (optional)",
"february": "number (optional)",
"march": "number (optional)",
"april": "number (optional)",
"may": "number (optional)",
"june": "number (optional)",
"july": "number (optional)",
"august": "number (optional)",
"september": "number (optional)",
"october": "number (optional)",
"november": "number (optional)",
"december": "number (optional)"
},
"powerConsumption": {
"kwh": "number (optional)",
"kw": "number (optional)"
},
"totalWetWasteCapacity": "number (optional, tons)",
"totalDryWasteCapacity": "number (optional, tons)",
"totalCompostCapacity": "number (optional, tons)",
"totalWaterCapacity": "number (optional, m³ or L)",
"methaneProduction": "number (optional, m³/day or m³/cycle)",
"addedBiomassProduction": "number (optional, tons/day or tons/cycle)",
"waterProduction": "number (optional, m³/day or L/day)",
"heatProduction": "number (optional, kJ/day or kWh/day)",
"immobilizationDuration": "number (optional, days)",
"wasteTypes": "string[] (optional, array of waste IDs)",
"dimensions": {
"length": "number (optional, meters)",
"height": "number (optional, meters)",
"width": "number (optional, meters)"
},
"groundSurface": "number (optional, m²)",
"heatNeedsPerDay": {
"january": "number (optional)",
"february": "number (optional)",
"march": "number (optional)",
"april": "number (optional)",
"may": "number (optional)",
"june": "number (optional)",
"july": "number (optional)",
"august": "number (optional)",
"september": "number (optional)",
"october": "number (optional)",
"november": "number (optional)",
"december": "number (optional)"
},
"coolingNeedsPerDay": {
"january": "number (optional)",
"february": "number (optional)",
"march": "number (optional)",
"april": "number (optional)",
"may": "number (optional)",
"june": "number (optional)",
"july": "number (optional)",
"august": "number (optional)",
"september": "number (optional)",
"october": "number (optional)",
"november": "number (optional)",
"december": "number (optional)"
},
"productionPower": {
"kwh": "number (optional)",
"kw": "number (optional)"
},
"annualExploitationETP": "number (optional, Full Time Equivalent)",
"annualMaintenanceETP": "number (optional, Full Time Equivalent)",
"annualSupervisionETP": "number (optional, Full Time Equivalent)",
"totalMaterialCost": "number (optional, CAPEX, €/year)",
"annualExploitationConsumablesCost": "number (optional, €/year)",
"annualMaintenanceConsumablesCost": "number (optional, €/year)",
"lifetime": "number (optional, years)",
"regulators": [
{
"regulatorId": "string (reference to NaturalRegulator)",
"percentage": "number (0-100, percentage of total volume)",
"dosage": "number (optional, specific dosage)"
}
],
"services": [
{
"serviceId": "string (reference to Service)",
"notes": "string (optional)"
}
],
"administrativeProcedures": [
{
"procedureId": "string (reference to AdministrativeProcedure)",
"status": "string (toDo|done|na)",
"notes": "string (optional)"
}
],
"regulationCharacteristicIds": "string[] (optional, references to RegulationCharacteristic)",
"businessPlan": "BusinessPlan (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.8 Ecosystem Schema
```json
{
"id": "string (UUID)",
"name": "string",
"description": "string (optional)",
"primaryRegulationNeeds": [
"string (regulation need code)",
"string (regulation need code)",
"string (regulation need code)"
],
"regulationCharacteristicIds": "string[] (optional, references to RegulationCharacteristic)",
"regulators": [
{
"regulatorId": "string (reference to NaturalRegulator)",
"percentage": "number (0-100, percentage of contribution)",
"role": "string (primary|secondary|support)"
}
],
"effectiveness": {
"regulationNeedCode": "number (0-100, percentage effectiveness)"
},
"compatibleWasteTypes": "string[] (optional, array of waste IDs, empty means all)",
"applicationConditions": "string (optional)",
"treatmentDuration": "number (optional, days)",
"businessPlan": "BusinessPlan (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.9 RegulationCharacteristic Schema
```json
{
"id": "string (UUID)",
"name": "string",
"code": "string (unique identifier, e.g., 'pathogenElimination', 'heavyMetalsElimination')",
"category": "string (nutrient|heavyMetal|biological|chemical|biologicalProcess|ph|other)",
"description": "string (optional)",
"unit": "string (optional, e.g., 'kg/t', '%', 'pH')",
"isBoolean": "boolean (true for capability/need, false for numeric value)",
"minValue": "number (optional, minimum value if numeric)",
"maxValue": "number (optional, maximum value if numeric)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.10 Treatment Site Schema
```json
{
"id": "string (UUID)",
"name": "string",
"status": "string (toBeApproached|loiOk|inProgress|completed)",
"location": {
"address": "string (optional)",
"coordinates": {
"lat": "number (optional)",
"lng": "number (optional)"
}
},
"altitude": "number (meters)",
"availableGroundSurface": "number (m²)",
"monthlyTemperatures": [
"number (January, °C)",
"number (February, °C)",
"number (March, °C)",
"number (April, °C)",
"number (May, °C)",
"number (June, °C)",
"number (July, °C)",
"number (August, °C)",
"number (September, °C)",
"number (October, °C)",
"number (November, °C)",
"number (December, °C)"
],
"subscribedServices": "string[] (array of service IDs)",
"transporters": [
{
"transporterId": "string (reference to Transporter)",
"isPrimary": "boolean (optional)",
"notes": "string (optional)"
}
],
"investors": [
{
"investorId": "string (reference to Investor)",
"status": "string (toBeApproached|loiOk|inProgress|completed)",
"amount": "number (€)",
"notes": "string (optional)"
}
],
"administrativeProcedures": [
{
"procedureId": "string (reference to AdministrativeProcedure)",
"status": "string (toDo|done|na)",
"notes": "string (optional)"
}
],
"businessPlan": "BusinessPlan (optional)",
"notes": "string (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.11 Waste Site Schema
```json
{
"id": "string (UUID)",
"name": "string",
"type": "string",
"status": "string (toBeApproached|loiOk|inProgress|completed)",
"wasteType": "string (reference to waste ID)",
"quantityRange": {
"min": "number (t/day)",
"max": "number (t/day)"
},
"contact": {
"name": "string",
"email": "string (optional)",
"phone": "string (optional)",
"address": "string (optional)"
},
"collectionType": "string",
"distance": "number (km, from treatment site)",
"transporters": [
{
"transporterId": "string (reference to Transporter)",
"isPrimary": "boolean (optional)",
"notes": "string (optional)"
}
],
"businessPlan": "BusinessPlan (optional)",
"notes": "string (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.12 Investor Schema
```json
{
"id": "string (UUID)",
"name": "string",
"type": "string",
"amountRange": {
"min": "number (€)",
"max": "number (€)"
},
"geographicRegions": "string[]",
"wasteRange": {
"min": "number (t/day)",
"max": "number (t/day)"
},
"wasteTypes": "string[] (array of waste type IDs)",
"solarPanelsRange": {
"min": "number (kW)",
"max": "number (kW)"
},
"notes": "string (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.13 Administrative Procedure Schema
```json
{
"id": "string (UUID)",
"name": "string",
"type": "string (ICPE|spreading|other)",
"delays": "number (days)",
"contact": {
"name": "string",
"email": "string (optional)",
"phone": "string (optional)",
"organization": "string (optional)"
},
"regions": "string[]",
"businessPlan": "BusinessPlan (optional)",
"notes": "string (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.14 Company Schema
```json
{
"id": "string (UUID)",
"name": "string",
"legalName": "string (optional)",
"registrationNumber": "string (optional)",
"address": "string (optional)",
"contact": {
"email": "string (optional)",
"phone": "string (optional)",
"website": "string (optional)"
},
"businessPlan": "BusinessPlan (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
### 2.15 BusinessPlan Schema
```json
{
"revenues": {
"rawRental": "number[] (10 years, €/year)",
"biologicalTreatment": "number[] (10 years, €/year)",
"bitcoinManagement": "number[] (10 years, €/year)",
"fertilizers": "number[] (10 years, €/year)",
"wasteHeat": "number[] (10 years, €/year)",
"carbonCredits": "number[] (10 years, €/year)",
"brownfield": "number[] (10 years, €/year)",
"transport": "number[] (10 years, €/year)",
"commercialPartnerships": "number[] (10 years, €/year)",
"other": "number[] (10 years, €/year)"
},
"variableCosts": {
"rentalServices": "number[] (10 years, €/year)",
"commissions": "number[] (10 years, €/year)",
"otherVariable": "number[] (10 years, €/year)",
"transport": "number[] (10 years, €/year)"
},
"fixedCosts": {
"salaries": "number[] (10 years, €/year)",
"marketing": "number[] (10 years, €/year)",
"rd": "number[] (10 years, €/year)",
"administrative": "number[] (10 years, €/year)",
"otherGeneral": "number[] (10 years, €/year)"
},
"investments": {
"equipment": "number[] (10 years, €/year)",
"technology": "number[] (10 years, €/year)",
"patents": "number[] (10 years, €/year)"
},
"useOfFunds": {
"productDevelopment": "number[] (10 years, €/year)",
"marketing": "number[] (10 years, €/year)",
"team": "number[] (10 years, €/year)",
"structure": "number[] (10 years, €/year)"
},
"kpis": {
"activeUsers": "number[] (10 years)",
"cac": "number[] (10 years, €)",
"ltv": "number[] (10 years, €)",
"breakEvenDays": "number[] (10 years)"
}
}
```
### 2.16 Project Schema
```json
{
"id": "string (UUID)",
"name": "string",
"startDate": "ISO 8601 date string",
"endDate": "ISO 8601 date string",
"treatmentSiteId": "string (reference to treatment site)",
"collectionSiteIds": "string[] (array of waste site IDs)",
"numberOfModules": "number",
"transportBySite": "boolean",
"wasteCharacteristicsOverride": {
"wasteId": "string (optional, reference to waste)",
"bmp": "number (optional, override)",
"waterPercentage": "number (optional, override)",
"regulatoryNeeds": "string[] (optional, override)"
},
"administrativeProcedures": [
{
"procedureId": "string (reference to administrative procedure)",
"status": "string (toDo|done|na)"
}
],
"investments": [
{
"investorId": "string (reference to investor)",
"status": "string (toBeApproached|loiOk|inProgress|completed)",
"amount": "number (€)"
}
],
"businessPlan": "BusinessPlan (optional)",
"notes": "string (optional)",
"createdAt": "ISO 8601 date string",
"updatedAt": "ISO 8601 date string"
}
```
## 3. Relations Between Entities
### 3.1 Project Relations
```
Project (1) ──→ (1) TreatmentSite
Project (1) ──→ (N) WasteSite
Project (1) ──→ (N) AdministrativeProcedure (with status)
Project (1) ──→ (N) Investment (with investor reference and status)
Project (1) ──→ (1) Waste (optional override)
Project (1) ──→ (1) BusinessPlan (optional)
```
### 3.2 Treatment Site Relations
```
TreatmentSite (1) ──→ (N) Service (subscribed services)
TreatmentSite (1) ──→ (N) Project
TreatmentSite (1) ──→ (N) Transporter (with isPrimary flag)
TreatmentSite (1) ──→ (N) Investor (with status and amount)
TreatmentSite (1) ──→ (N) AdministrativeProcedure (with status)
TreatmentSite (1) ──→ (1) BusinessPlan (optional)
```
### 3.3 Waste Site Relations
```
WasteSite (1) ──→ (1) Waste (waste type)
WasteSite (N) ──→ (1) Project
WasteSite (1) ──→ (N) Transporter (with isPrimary flag)
WasteSite (1) ──→ (1) BusinessPlan (optional)
```
### 3.4 Waste Relations
```
Waste (N) ──→ (1) WasteOrigin (optional, allows n wastes to 1 origin)
Waste (1) ──→ (N) NaturalRegulator (with percentage of global volume)
Waste (1) ──→ (N) RegulationCharacteristic (via regulationCharacteristicIds)
Waste (1) ──→ (1) BusinessPlan (optional)
```
### 3.5 Natural Regulator Relations
```
NaturalRegulator (1) ──→ (N) RegulationCharacteristic (via regulationCharacteristicIds)
NaturalRegulator (1) ──→ (N) Waste (via WasteRegulatorAssociation)
NaturalRegulator (1) ──→ (N) Ecosystem (via EcosystemRegulatorAssociation)
NaturalRegulator (1) ──→ (N) ModuleComponent (via ModuleComponentRegulatorAssociation)
NaturalRegulator (1) ──→ (1) BusinessPlan (optional)
```
### 3.6 Module Component Relations
```
ModuleComponent (1) ──→ (N) NaturalRegulator (with percentage and optional dosage)
ModuleComponent (1) ──→ (N) Service (with optional notes)
ModuleComponent (1) ──→ (N) AdministrativeProcedure (with status and notes)
ModuleComponent (1) ──→ (N) RegulationCharacteristic (via regulationCharacteristicIds)
ModuleComponent (1) ──→ (N) Waste (compatible waste types)
ModuleComponent (1) ──→ (1) BusinessPlan (optional)
```
### 3.7 Ecosystem Relations
```
Ecosystem (1) ──→ (N) NaturalRegulator (with percentage and role)
Ecosystem (1) ──→ (N) RegulationCharacteristic (via regulationCharacteristicIds)
Ecosystem (1) ──→ (N) Waste (compatible waste types, optional, empty means all)
Ecosystem (1) ──→ (1) BusinessPlan (optional)
```
### 3.8 Service Relations
```
Service (N) ──→ (1) TreatmentSite (subscribed)
Service (N) ──→ (N) ModuleComponent (via ModuleComponentServiceAssociation)
Service (1) ──→ (1) BusinessPlan (optional)
```
### 3.9 Transporter Relations
```
Transporter (N) ──→ (1) TreatmentSite (via SiteTransporterAssociation)
Transporter (N) ──→ (1) WasteSite (via SiteTransporterAssociation)
Transporter (1) ──→ (1) BusinessPlan (optional)
```
### 3.10 Investor Relations
```
Investor (1) ──→ (N) Investment (in projects)
Investor (1) ──→ (N) Waste (waste type preferences)
Investor (N) ──→ (1) TreatmentSite (via TreatmentSiteInvestorAssociation)
```
### 3.11 Administrative Procedure Relations
```
AdministrativeProcedure (1) ──→ (N) Project (with status per project)
AdministrativeProcedure (1) ──→ (N) TreatmentSite (via TreatmentSiteProcedureAssociation)
AdministrativeProcedure (1) ──→ (N) ModuleComponent (via ModuleComponentProcedureAssociation)
AdministrativeProcedure (1) ──→ (1) BusinessPlan (optional)
```
### 3.12 RegulationCharacteristic Relations
```
RegulationCharacteristic (1) ──→ (N) Waste (via regulationCharacteristicIds)
RegulationCharacteristic (1) ──→ (N) NaturalRegulator (via regulationCharacteristicIds)
RegulationCharacteristic (1) ──→ (N) Ecosystem (via regulationCharacteristicIds)
RegulationCharacteristic (1) ──→ (N) ModuleComponent (via regulationCharacteristicIds)
```
### 3.13 Company Relations
```
Company (1) ──→ (1) BusinessPlan (optional)
```
## 4. Data Validation Rules
### 4.1 Required Fields
- All entities must have: `id`, `createdAt`
- Projects must have: `name`, `startDate`, `endDate`, `treatmentSiteId`, `numberOfModules`
- Wastes must have: `name`, `bmp`, `waterPercentage`, `regulationNeeds`
- Services must have: `name`, `type`, `pricing` (all 10 years)
- Natural Regulators must have: `name`, `type`, `applicationConditions`, `dosageRequirements`
- Module Components must have: `name`, `type`, `isOptional`, `defaultDuration`, `durationUnit`
- Ecosystems must have: `name`, `primaryRegulationNeeds` (exactly 3), `regulators`, `effectiveness`
- Regulation Characteristics must have: `name`, `code`, `category`
- Companies must have: `name`
### 4.2 Value Constraints
- `waterPercentage`: 0-100
- `bmp`: > 0
- `numberOfModules`: > 0
- `startDate` < `endDate`
- All monetary values: >= 0
- All quantities: >= 0
- Regulator percentages in WasteRegulatorAssociation: 0-100, total <= 100
- Regulator percentages in EcosystemRegulatorAssociation: 0-100, total should equal 100
- Regulator percentages in ModuleComponentRegulatorAssociation: 0-100, total <= 100
- Effectiveness values: 0-100
- pH adjustment: -14 to 14
- `primaryRegulationNeeds` in Ecosystem: exactly 3 unique values
### 4.3 Reference Integrity
- `treatmentSiteId` must exist in `treatmentSites`
- `collectionSiteIds` must exist in `wasteSites`
- `wasteId` in wasteCharacteristicsOverride must exist in `wastes`
- All `procedureId` must exist in `administrativeProcedures`
- All `investorId` must exist in `investors`
- All `serviceId` in subscribedServices must exist in `services`
- All `regulatorId` in associations must exist in `regulators`
- All `transporterId` in associations must exist in `transporters`
- All `wasteOriginId` must exist in `wasteOrigins`
- All `regulationCharacteristicIds` must exist in `regulationCharacteristics`
- All `wasteType` in WasteSite must exist in `wastes`
- All `wasteTypes` in ModuleComponent and Ecosystem must exist in `wastes`
## 5. Import/Export Format
### 5.1 Export
- Export complete storage structure as JSON
- Include all entities
- Include version number
- Include lastModified timestamp
### 5.2 Import
- Replace entire storage with imported JSON
- Validate structure
- Validate references
- Validate constraints
- If validation fails, keep existing data and show error
### 5.3 Import Validation
1. Check JSON structure validity
2. Check version compatibility
3. Validate all required fields
4. Validate all value constraints
5. Validate all reference integrity
6. If any validation fails, reject import and show detailed errors
## 6. Data Storage Keys
### 6.1 LocalStorage Keys
```
"4nkwaste_simulator_data" - Complete application data (JSON string)
"4nkwaste_simulator_user" - Current user session
"4nkwaste_simulator_version" - Data version
```
### 6.2 IndexedDB Structure (if used)
```
Database: "4nkwaste_simulator"
- ObjectStore: "wastes"
- ObjectStore: "regulators"
- ObjectStore: "services"
- ObjectStore: "wasteOrigins"
- ObjectStore: "transporters"
- ObjectStore: "moduleComponents"
- ObjectStore: "ecosystems"
- ObjectStore: "regulationCharacteristics"
- ObjectStore: "treatmentSites"
- ObjectStore: "wasteSites"
- ObjectStore: "investors"
- ObjectStore: "administrativeProcedures"
- ObjectStore: "companies"
- ObjectStore: "projects"
- ObjectStore: "users"
```
## 7. Business Plan Aggregation
Business plans can be associated with multiple entities:
- **Waste**: Business plan for waste-specific operations
- **NaturalRegulator**: Business plan for regulator-specific operations
- **Service**: Business plan for service-specific operations
- **Transporter**: Business plan for transport operations
- **ModuleComponent**: Business plan for component-specific operations
- **Ecosystem**: Business plan for ecosystem-specific operations
- **TreatmentSite**: Business plan for site-specific operations
- **WasteSite**: Business plan for waste site operations
- **AdministrativeProcedure**: Business plan for procedure-related operations
- **Company**: Business plan for company-level operations
- **Project**: Business plan for project-level operations
The **Yields** page aggregates all business plans from entities associated with a project:
- Project's own business plan
- Treatment Site's business plan
- All Waste Sites' business plans
- All Module Components' business plans (if used in the project)
- All Services' business plans (if subscribed)
- Company's business plan (if applicable)