Spaces:
Configuration error
Configuration error
Commit Β·
d2f3059
1
Parent(s): 55714d6
docs: exhaustive repository architecture map and Grand Tour update
Browse files
README.md
CHANGED
|
@@ -4,85 +4,99 @@ Eatlytic is a high-performance, AI-native nutritional analysis engine designed t
|
|
| 4 |
|
| 5 |
---
|
| 6 |
|
| 7 |
-
## π The Eatlytic
|
| 8 |
-
|
| 9 |
-
The system
|
| 10 |
-
|
| 11 |
-
### **1.
|
| 12 |
-
|
| 13 |
-
- **
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
- **
|
| 18 |
-
- **
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
- **
|
| 22 |
-
- **
|
| 23 |
-
- **
|
| 24 |
-
|
| 25 |
-
### **
|
| 26 |
-
|
| 27 |
-
- **
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
- **
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
---
|
| 33 |
|
| 34 |
-
## π
|
| 35 |
|
| 36 |
```text
|
| 37 |
Eatlytic-App-main/
|
|
|
|
|
|
|
|
|
|
| 38 |
βββ app/
|
| 39 |
β βββ models/
|
| 40 |
-
β β βββ db.py #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
β βββ services/
|
| 42 |
-
β βββ ocr.py #
|
| 43 |
-
β βββ llm.py # Universal AI Brain
|
| 44 |
-
β βββ
|
| 45 |
-
β βββ
|
| 46 |
-
β βββ
|
| 47 |
-
β βββ duel_service.py # Persona-Weighted
|
| 48 |
-
β βββ alternatives.py #
|
| 49 |
-
β βββ hash_service.py #
|
| 50 |
-
β βββ research_engine.py # Live Web Research
|
| 51 |
-
β βββ formatter.py # Post-processing &
|
| 52 |
-
β βββ explanation_engine.py
|
| 53 |
-
β βββ auth.py #
|
| 54 |
-
β βββ payments.py # Quota
|
| 55 |
-
βββ
|
| 56 |
-
βββ
|
| 57 |
-
βββ
|
| 58 |
-
|
| 59 |
-
βββ
|
| 60 |
-
βββ
|
| 61 |
-
βββ
|
| 62 |
-
βββ
|
| 63 |
-
βββ
|
| 64 |
-
βββ
|
| 65 |
-
βββ
|
| 66 |
-
βββ .
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
```
|
| 69 |
|
| 70 |
---
|
| 71 |
|
| 72 |
-
## β‘
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
### **Universal Product Alternatives**
|
| 78 |
-
The `alternatives.py` module uses an **Ingredient-Pivot** matrix that recommends healthy swaps locally and globally (e.g., roasted Makhana for chips, or Poha for instant noodles).
|
| 79 |
-
|
| 80 |
-
---
|
| 81 |
-
|
| 82 |
-
## π οΈ Performance & Scalability
|
| 83 |
-
- **Quota Logic**: Built-in scan tracking in `main.py` prevents API abuse.
|
| 84 |
-
- **Cache Safety Valve**: Automatically discards results with 0 macronutrients.
|
| 85 |
-
- **HuggingFace Ready**: Memory-optimized deployment for HF Spaces.
|
| 86 |
|
| 87 |
---
|
| 88 |
|
|
|
|
| 4 |
|
| 5 |
---
|
| 6 |
|
| 7 |
+
## π The Eatlytic "Grand Tour" Architecture
|
| 8 |
+
|
| 9 |
+
The system is organized into a modular, horizontally scalable architecture:
|
| 10 |
+
|
| 11 |
+
### **1. The Intelligence Services (`app/services/`)**
|
| 12 |
+
The "Brain" of Eatlytic, where raw pixels become data:
|
| 13 |
+
- **`ocr.py`**: The Multi-Pass Global OCR Engine. Features auto-script detection and 3-pass retry (Denoise/Sharpen/Binary).
|
| 14 |
+
- **`llm.py`**: The Universal AI Brain. Merges OCR text with global knowledge to produce high-fidelity JSON (Molecular Insight, ELI5, Age Warnings).
|
| 15 |
+
- **`label_detector.py`**: CV ROI targeting using **MSER (Maximally Stable Extremal Regions)** text-density heatmaps.
|
| 16 |
+
- **`image.py`**: The **"Never Reject"** repair pipeline (Upscale, Wiener deconvolution, CLAHE).
|
| 17 |
+
- **`fake_detector.py`**: The Atwater Physics Validator (Universal 20% tolerance floor).
|
| 18 |
+
- **`duel_service.py`**: Head-to-head persona-weighted product comparison logic.
|
| 19 |
+
- **`alternatives.py`**: Global healthy swap matrix (Ingredient-Pivot logic).
|
| 20 |
+
- **`hash_service.py`**: Perceptual Hashing (pHash) for instant deduplication.
|
| 21 |
+
- **`research_engine.py`**: Live Web Research (DDG) for messy-label fallback.
|
| 22 |
+
- **`explanation_engine.py`**: Global/ICMR RDA benchmarking and INS/E-number scanner.
|
| 23 |
+
- **`formatter.py`**: Result post-processing and text-tiering for WhatsApp/Web.
|
| 24 |
+
|
| 25 |
+
### **2. The API Layer (`app/routes/`)**
|
| 26 |
+
Handles user interaction, security, and business logic:
|
| 27 |
+
- **`auth.py`**: User authentication, session management, and Supabase security integration.
|
| 28 |
+
- **`benchmarks.py`**: Internal performance tracking (Latency, accuracy, and ROI stats).
|
| 29 |
+
- **`food_db.py`**: Analytics and Scan History (The backbone of the "History" tab).
|
| 30 |
+
- **`payments.py`**: Quota management and **Razorpay** integration for Pro activation.
|
| 31 |
+
|
| 32 |
+
### **3. The Persistence Layer (`app/models/`)**
|
| 33 |
+
The source of truth for the platform:
|
| 34 |
+
- **`db.py`**: Hybrid persistence engine. Uses **Supabase** for production clusters and **SQLite (WAL mode)** for local development and offline caching.
|
| 35 |
+
|
| 36 |
+
### **4. Maintenance & CLI Tooling (Root)**
|
| 37 |
+
Scripts for system upkeep and data repair:
|
| 38 |
+
- **`flush_cache.py`**: Clears broken or 0-nutrient cache entries.
|
| 39 |
+
- **`scrub_meat.py`**: Repairs categorization errors across the database.
|
| 40 |
+
- **`inspect_db.py`**: Terminal-based dashboard for viewing live scans and quotas.
|
| 41 |
+
- **`deploy.sh`**: Manual deployment script for server environments.
|
| 42 |
|
| 43 |
---
|
| 44 |
|
| 45 |
+
## π Exhaustive File Structure
|
| 46 |
|
| 47 |
```text
|
| 48 |
Eatlytic-App-main/
|
| 49 |
+
βββ .github/
|
| 50 |
+
β βββ workflows/
|
| 51 |
+
β βββ sync_to_huggingface.yml # CI/CD: HF Spaces sync
|
| 52 |
βββ app/
|
| 53 |
β βββ models/
|
| 54 |
+
β β βββ db.py # Persistence: Supabase/SQLite hybrid
|
| 55 |
+
οΏ½οΏ½οΏ½ βββ routes/
|
| 56 |
+
β β βββ auth.py # API: User Auth & Tokens
|
| 57 |
+
β β βββ benchmarks.py # API: Performance Monitoring
|
| 58 |
+
β β βββ food_db.py # API: History & Analytics
|
| 59 |
+
β β βββ payments.py # API: Razorpay & Quotas
|
| 60 |
β βββ services/
|
| 61 |
+
β βββ ocr.py # Logic: Global OCR (18+ Scripts)
|
| 62 |
+
β βββ llm.py # Logic: Universal AI Brain
|
| 63 |
+
β βββ label_detector.py # Vision: MSER ROI Targeting
|
| 64 |
+
β βββ image.py # Vision: "Never Reject" Repair
|
| 65 |
+
β βββ fake_detector.py # Physics: Atwater Validation
|
| 66 |
+
β βββ duel_service.py # Feature: Persona-Weighted Duels
|
| 67 |
+
β βββ alternatives.py # Feature: Ingredient Swaps
|
| 68 |
+
β βββ hash_service.py # Performance: pHash Deduplication
|
| 69 |
+
β βββ research_engine.py # Fallback: Live Web Research
|
| 70 |
+
β βββ formatter.py # UX: Post-processing & Formatting
|
| 71 |
+
β βββ explanation_engine.py # Science: RDA & INS Scanning
|
| 72 |
+
β βββ auth.py # Logic: Backend Security
|
| 73 |
+
β βββ payments.py # Logic: Quota Verification
|
| 74 |
+
βββ data/
|
| 75 |
+
β βββ eatlytic.db # Local Persistence (fallback)
|
| 76 |
+
β βββ ai_cache.json # Local AI result cache
|
| 77 |
+
β βββ ocr_cache.json # Local OCR heatmap cache
|
| 78 |
+
βββ main.py # Application Core (FastAPI)
|
| 79 |
+
βββ index.html # Frontend Entry Point
|
| 80 |
+
βββ test_critical.py # Stability: Pipeline stress tests
|
| 81 |
+
βββ test_phash.py # Logic: Deduplication verification
|
| 82 |
+
βββ test_poison_pill.py # Security: Input resilience tests
|
| 83 |
+
βββ conftest.py # Testing: Framework config
|
| 84 |
+
βββ flush_cache.py # Maintenance: Cache Repair
|
| 85 |
+
βββ inspect_db.py # Maintenance: DB Explorer
|
| 86 |
+
βββ scrub_meat.py # Maintenance: Data Repair
|
| 87 |
+
βββ Dockerfile # Infrastructure: Docker Image
|
| 88 |
+
βββ docker-compose.yml # Infrastructure: Local orchestration
|
| 89 |
+
βββ requirements.txt # Dependencies: System packages
|
| 90 |
+
βββ .env # Configuration: API Keys/URLs
|
| 91 |
+
βββ Eatlytic-12Week-Roadmap.md # Strategy: Future Growth
|
| 92 |
```
|
| 93 |
|
| 94 |
---
|
| 95 |
|
| 96 |
+
## β‘ Performance & Compliance
|
| 97 |
+
- **DPDP Compliant**: Built-in data erasure (`/api/v1/user/delete`) and retention management in `db.py`.
|
| 98 |
+
- **HuggingFace Ready**: Auto-deploy via `.github/workflows` with tailored memory management for C-based vision libraries.
|
| 99 |
+
- **Cache Safety Valve**: Automatically discards suspect entries to ensure 100% data integrity.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
---
|
| 102 |
|