# shrey-14/smart-resto architecture

> Architecture diagram of the GitHub repository shrey-14/smart-resto, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shrey-14/smart-resto
- Repository: https://github.com/shrey-14/smart-resto

## Overview

##### Project Type and Purpose
- SmartResto is a full-stack, AI-driven kitchen management web application.
- Frontend: React/TypeScript SPA for interactive dashboards, uploads, and real-time views.
- Backend: FastAPI service orchestrating ML pipelines for vision, forecasting, waste prediction, and menu optimization.
- Purpose: reduce food waste and improve kitchen efficiency via computer vision, forecasting, and generative AI.

##### High-Level Components
a. Frontend (React/TS)
- UI layers: Layout (Navbar, Sidebar), Pages (Index, Inventory, NotFound), Feature Components (Inventory, Waste, Sales, Cost tools).
- Services: HTTP client (`src/services/api.ts`) for REST calls to backend.
b. Backend (FastAPI)
- API layer (`api.py`, `main.py`) – exposes endpoints for vision, forecasting, spoilage, menu optimization.
- ML modules:
– Vision Analysis (YOLOv8, waste_heatmap, classification)
– Inventory Tracking (stock_detection, live inventory)
– Food Spoilage Detection (LLaMA inference)
– Menu Optimization (cost_optimizer, recipe_generator, recipe_recommender)
- Config & Storage: `config.yaml`, output CSVs, local data folders.
- Entrypoint script (`run_api.sh`).
c. Data Stores
- Model artifacts (YOLO weights, LLaMA checkpoint references via Groq).
- CSV outputs under `src/data/output` for visualization and downstream modules.
- (Optionally) a database or object store for production‐grade persistence.
d. External Services
- Groq API for LLaMA inference.
- Optional cloud storage or real‐time camera feeds.

##### Relationships & Data Flow
- User interacts with Frontend → triggers REST calls to Backend.
- For Spoilage & Waste Prediction: historical data or live inputs → preprocessor → model inference (LLaMA/XGBoost/Prophet) → output CSVs/JSON → API returns predictions → front-end dashboards (SpoilageForecast, WasteQuantifier).
- For Menu Optimization: near‐expiry item list → recipe generator & cost optimizer → recommended dishes → UI component (DailySpecials).
- Data flows bi-directionally: user uploads sales CSV → backend ingest → forecasting → feed results back to UI (SalesPredictor).

##### Important Architectural Patterns
- Modular ML pipelines: each domain (vision, forecasting, generative AI) lives in own package under `backend/src`.
- Clear separation of concerns: API layer vs. data preprocessing vs. prediction modules.
- Stateless backend with potential for horizontal scaling behind a load balancer.
- Frontend is a single‐page application, decoupled from backend.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend
    subgraph "Frontend (React/TS)" 
        direction TB
        Browser["Browser / React TS App"]:::frontend
        App["App.tsx"]:::frontend
        Pages["Pages"]:::frontend
        Layout["Layout Components"]:::frontend
        Features["Feature Components"]:::frontend
        APIClient["api.ts (HTTP Client)"]:::frontend
    end

    %% Backend
    subgraph "Backend (FastAPI Service)" 
        direction TB
        API["API Layer"]:::backend
        subgraph "ML Modules"
            direction TB
            Vision["Vision Analysis"]:::backend
            InventoryMod["Inventory Tracking"]:::backend
            Spoilage["Spoilage Detection"]:::backend
            DemandWaste["Demand & Waste Prediction"]:::backend
            SalesForecast["Sales Forecasting"]:::backend
            MenuOpt["Menu Optimization"]:::backend
        end
        Config["config.yaml"]:::backend
        Entrypoint["run_api.sh"]:::backend
    end

    %% Data Stores
    ModelArtifacts["Model Artifacts"]:::datastore
    OutputData["Output Data / CSVs"]:::datastore

    %% External
    Camera["Camera Feed / Upload"]:::external
    Groq["Groq API (LLaMA)"]:::external

    %% Connections
    Camera -->|"Image Frames"| Vision
    Vision -->|"Detection Results"| OutputData
    Vision --> InventoryMod
    InventoryMod --> OutputData
    Spoilage --> OutputData
    DemandWaste --> OutputData
    SalesForecast --> OutputData
    MenuOpt --> Groq
    Groq --> MenuOpt
    Browser -->|"HTTP/REST"| API
    API --> Vision
    API --> InventoryMod
    API --> Spoilage
    API --> DemandWaste
    API --> SalesForecast
    API --> MenuOpt
    OutputData --> Browser

    %% Click Events - Frontend
    click App "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/App.tsx"
    click Pages "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/pages/Index.tsx"
    click Pages "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/pages/inventory.tsx"
    click Pages "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/pages/NotFound.tsx"
    click Layout "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/layout/Navbar.tsx"
    click Layout "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/layout/Sidebar.tsx"
    click Layout "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/layout/PageLayout.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/inventory/LiveInventoryDetection.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/inventory/SimpleInventoryScanner.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/inventory/StockDetectionDisplay.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/inventory/SmartRestocking.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/inventory/VisualInventoryScanner.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/inventory/VisualStockScanner.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/waste/SpoilageDetection.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/waste/SpoilageForecast.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/waste/WasteCategorization.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/waste/WasteMapping.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/waste/WasteQuantifier.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/waste/WasteTypes.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/waste/CreativeWasteAgent.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/sales/SalesPredictor.tsx"
    click Features "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/components/dashboard/DailySpecials.tsx"
    click APIClient "https://github.com/shrey-14/smart-resto/blob/main/frontend/src/services/api.ts"

    %% Click Events - Backend
    click API "https://github.com/shrey-14/smart-resto/blob/main/backend/api.py"
    click API "https://github.com/shrey-14/smart-resto/blob/main/backend/main.py"
    click Entrypoint "https://github.com/shrey-14/smart-resto/blob/main/backend/run_api.sh"
    click Config "https://github.com/shrey-14/smart-resto/blob/main/backend/config/config.yaml"
    click OutputData "https://github.com/shrey-14/smart-resto/tree/main/backend/src/data/output/"
    click OutputData "https://github.com/shrey-14/smart-resto/tree/main/backend/src/data/output/detection_images/"
    click OutputData "https://github.com/shrey-14/smart-resto/blob/main/backend/src/data/output/stock_prediction/predicted_items.csv"
    click Vision "https://github.com/shrey-14/smart-resto/blob/main/backend/src/vision_analyis/PlDashboard.py"
    click Vision "https://github.com/shrey-14/smart-resto/blob/main/backend/src/vision_analyis/food_waste_classification.py"
    click Vision "https://github.com/shrey-14/smart-resto/blob/main/backend/src/vision_analyis/waste_heatmap.py"
    click InventoryMod "https://github.com/shrey-14/smart-resto/blob/main/backend/src/inventory_tracking/inventory_tracking.py"
    click InventoryMod "https://github.com/shrey-14/smart-resto/blob/main/backend/src/inventory_tracking/inventory_tracking_and_stock_detection.py"
    click InventoryMod "https://github.com/shrey-14/smart-resto/blob/main/backend/src/inventory_tracking/stock_detection.py"
    click Spoilage "https://github.com/shrey-14/smart-resto/blob/main/backend/src/food_spoilage_detection/food_spoilage_detection.py"
    click DemandWaste "https://github.com/shrey-14/smart-resto/blob/main/backend/src/demand_waste/data_preprocessor.py"
    click DemandWaste "https://github.com/shrey-14/smart-resto/blob/main/backend/src/demand_waste/waste_predictor.py"
    click SalesForecast "https://github.com/shrey-14/smart-resto/blob/main/backend/src/smart_kitchen/sales_forecaster_prophet.py"
    click SalesForecast "https://github.com/shrey-14/smart-resto/blob/main/backend/src/smart_kitchen/sales_forecaster_xgboost.py"
    click SalesForecast "https://github.com/shrey-14/smart-resto/blob/main/backend/src/smart_kitchen/data_preprocessor.py"
    click MenuOpt "https://github.com/shrey-14/smart-resto/blob/main/backend/src/menu_optimization/cost_optimizer.py"
    click MenuOpt "https://github.com/shrey-14/smart-resto/blob/main/backend/src/menu_optimization/recipe_generator.py"
    click MenuOpt "https://github.com/shrey-14/smart-resto/blob/main/backend/src/menu_optimization/recipe_recommender.py"
    click Entrypoint "https://github.com/shrey-14/smart-resto/blob/main/backend/requirements.txt"

    %% Styles
    classDef frontend fill:#C3DDF9,stroke:#0366d6,color:#000
    classDef backend fill:#C6F6D5,stroke:#228B22,color:#000
    classDef datastore fill:#FFE4B5,stroke:#FF8C00,color:#000
    classDef external fill:#E1C6F0,stroke:#800080,color:#000
```
