# mitshah2406/ecosaathi_waste-management architecture

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

- Interactive diagram: https://gitdiagram.com/mitshah2406/ecosaathi_waste-management
- Repository: https://github.com/mitshah2406/ecosaathi_waste-management

## Overview

##### Project Type and Purpose
- EcoSaathi is a full-stack, multi-component waste-management system built for a hackathon.
- It comprises:
- A Node.js/Express backend (pict_backend) exposing REST APIs and serving an admin UI.
- A Flutter mobile front-end (pict_frontend) implementing BLoC/Provider for state management.
- A Django microservice (route_optimization) for route-optimization (CVRP) using Google Maps APIs.
- ML modules (in ML/, waste_ml_model/, wastebot/) for bin-fill detection, litterbug detection, and chatbot.

##### Top-Level Component Breakdown
A. IoT Edge & Sensors
B. Backend Services
C. Route-Optimization Microservice
D. Mobile Frontend
E. External Services & Datastores

##### Relationships & Data Flows
- IoT devices (bin-fill sensors or CCTV) → HTTP/ MQTT → Node Backend “pict_backend.”
- pict_backend → WhatsApp API (Meta Developers) for notifications.
- pict_backend → Flutter Web-admin UI (EJS views + frontend-js assets).
- Flutter Mobile App ↔ pict_backend REST API (auth, events, biowaste, reports, tasks, chat, user profile).
- Flutter Mobile App → Django Route-Optimization Service → Google Maps API (Distance Matrix, Directions, Geocoding).
- Flutter Mobile App → Gemini API via ChatBotService for “WasteBot” queries.
- ML Detection:
- Litterbug Detector (YOLOv8 trained on Taco Trash) could be hosted as a separate service or embedded on device (waste_ml_model).
- pict_frontend/utils/recognition.dart hints at on-device inference or a proxied endpoint.

##### Architectural Patterns & Design Principles
- pict_backend uses MVC:
- models/ (Mongoose or Sequelize models in models/)
- controllers/ (REST logic)
- routes/router.js (HTTP routing)
- views/ + public/ + frontend-js for web-admin UI
- Flutter client uses BLoC + Provider pattern for state management (lib/bloc/, lib/providers/).
- The route optimizer is a self-contained Django app exposing REST endpoints.
- Separation of concerns:
- Microservices for domain-specific logic (route optimization)
- On-device or server-hosted ML modules
- Single Node backend for core business logic

- Node.js, Express, EJS, MongoDB or SQL (whichever db.js config uses)
- Docker & Docker Compose (pict_backend/Dockerfile + compose.yaml)
- Flutter (pict_frontend) with Dart, BLoC, Provider
- Django, Python, Google Maps APIs, SQLite (route_optimization)
- YOLOv8, OpenCV or TensorFlow Lite (ML folder & waste_ml_model)
- Gemini API (for WasteBot chats)
- Meta WhatsApp API (notification module)

##### Don’t Overthink – Be Detailed
- Break out each major module into its core parts even if lightly: e.g., pict_backend/controllers vs. pict_backend/models.
- External dependencies explicitly.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% IoT Devices
    subgraph "IoT Edge & Sensors"
        direction TB
        IoT["Bins & CCTV Sensors"]:::iot
    end

    %% Backend Services
    subgraph "Node.js Backend (EcoSaathi Core)" 
        direction TB
        NB_app["app.js"]:::backend
        NB_dbconf["db.js"]:::backend
        NB_docker["Dockerfile"]:::backend
        NB_compose["compose.yaml"]:::backend
        subgraph "Models"
            NB_models["models/"]:::backend
        end
        subgraph "Controllers"
            NB_controllers["controllers/"]:::backend
        end
        NB_router["router.js"]:::backend
        subgraph "Web-Admin UI"
            NB_views["views/"]:::frontend
            NB_public["public/"]:::frontend
            NB_frontjs["frontend-js/"]:::frontend
        end
    end

    %% Database
    DB["Primary Database"]:::database

    %% External APIs
    subgraph "External Services"
        direction TB
        WhatsApp["WhatsApp API"]:::external
        Gemini["Gemini API"]:::external
        GoogleMaps["Google Maps APIs"]:::external
    end

    %% Django Route-Optimization
    subgraph "Django Route-Opt Microservice"
        direction TB
        DO_manage["manage.py"]:::backend
        subgraph "Django Project"
            DO_settings["route_optimization/"]:::backend
            DO_models["models.py"]:::backend
            DO_views["views.py"]:::backend
            DO_urls["urls.py"]:::backend
        end
        DO_db["db.sqlite3"]:::database
        DO_mig["migrations/"]:::backend
    end

    %% Flutter Mobile App
    subgraph "Flutter Mobile App" 
        direction TB
        FL_main["main.dart"]:::frontend
        subgraph "State Management"
            FL_bloc["bloc/"]:::frontend
            FL_prov["providers/"]:::frontend
        end
        subgraph "UI & Services"
            FL_pages["pages/"]:::frontend
            FL_services["services/"]:::frontend
            FL_utils["utils/"]:::frontend
            FL_widgets["widgets/"]:::frontend
        end
    end

    %% On-Device ML
    subgraph "On-Device ML (Bin-Fill Detection)"
        direction TB
        ML_main["lib/main.dart"]:::ml
        ML_home["homepage.dart"]:::ml
        ML_models["assets/models/yoloNew.pt"]:::ml
        ML_android["android/"]:::ml
        ML_ios["ios/"]:::ml
    end

    %% ML Notebooks & Scripts
    subgraph "ML Prototypes & Scripts"
        direction TB
        ML_nb1["wasteclass.ipynb"]:::ml
        ML_script["FACIALRECOGNITION.py"]:::ml
    end

    %% WasteBot Chatbot
    subgraph "WasteBot Chatbot"
        direction TB
        WB_pubspec["pubspec.yaml"]:::frontend
        WB_lib["lib/"]:::frontend
    end

    %% Connections
    IoT -->|"MQTT/HTTP"| NB_app
    NB_app -->|"uses"| NB_dbconf
    NB_app -->|"routes via"| NB_router
    NB_router --> NB_controllers
    NB_controllers --> NB_models
    NB_app --> NB_views
    NB_app --> NB_public
    NB_app --> NB_frontjs
    NB_app -->|"HTTPS"| WhatsApp
    NB_app -->|"SQL/NoSQL"| DB

    FL_main -->|"HTTP REST"| NB_app
    FL_services -->|"calls"| NB_app

    FL_main -->|"HTTP REST"| DO_manage
    DO_manage --> DO_settings
    DO_settings --> DO_models
    DO_settings --> DO_views
    DO_settings --> DO_urls
    DO_settings --> DO_db
    DO_settings --> DO_mig
    DO_views -->|"API calls"| GoogleMaps

    FL_main -->|"API Key calls"| GoogleMaps
    FL_main -->|"ChatBotService"| Gemini

    ML_main -->|"on-device inference"| FL_utils

    WB_lib -->|"Gemini API"| Gemini

    %% Click Events
    click NB_app "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/pict_backend/app.js"
    click NB_dbconf "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/pict_backend/db.js"
    click NB_docker "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/pict_backend/Dockerfile"
    click NB_compose "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/pict_backend/compose.yaml"
    click NB_models "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/pict_backend/models/"
    click NB_controllers "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/pict_backend/controllers/"
    click NB_router "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/pict_backend/routes/router.js"
    click NB_views "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/pict_backend/views/"
    click NB_public "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/pict_backend/public/"
    click NB_frontjs "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/pict_backend/frontend-js/"

    click FL_main "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/pict_frontend/lib/main.dart"
    click FL_bloc "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/pict_frontend/lib/bloc/"
    click FL_prov "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/pict_frontend/lib/providers/"
    click FL_pages "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/pict_frontend/lib/pages/"
    click FL_services "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/pict_frontend/lib/services/"
    click FL_utils "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/pict_frontend/lib/utils/recognition.dart"
    click FL_utils "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/pict_frontend/lib/utils/geolocation_service.dart"
    click FL_widgets "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/pict_frontend/lib/widgets/"
    click FL_utils "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/pict_frontend/lib/utils/theme/"

    click DO_manage "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/route_optimization/manage.py"
    click DO_settings "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/route_optimization/route_optimization/"
    click DO_models "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/route_optimization/ecoSathi/models.py"
    click DO_views "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/route_optimization/ecoSathi/views.py"
    click DO_urls "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/route_optimization/ecoSathi/urls.py"
    click DO_db "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/route_optimization/db.sqlite3"
    click DO_mig "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/route_optimization/migrations/"

    click ML_main "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/waste_ml_model/lib/main.dart"
    click ML_home "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/waste_ml_model/lib/homepage.dart"
    click ML_models "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/waste_ml_model/assets/models/yoloNew.pt"
    click ML_android "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/waste_ml_model/android/"
    click ML_ios "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/waste_ml_model/ios/"

    click ML_nb1 "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/ML/wasteclass.ipynb"
    click ML_script "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/ML/FACIALRECOGNITION.py"

    click WB_pubspec "https://github.com/mitshah2406/ecosaathi_waste-management/blob/main/wastebot/pubspec.yaml"
    click WB_lib "https://github.com/mitshah2406/ecosaathi_waste-management/tree/main/wastebot/lib/"

    %% Styles
    classDef backend fill:#bbe1fa,stroke:#3282b8,color:#000
    classDef frontend fill:#d4f7dc,stroke:#28a745,color:#000
    classDef external fill:#ffd8a9,stroke:#ff7f11,color:#000
    classDef database fill:#fff3bf,stroke:#f4c430,color:#000
    classDef iot fill:#e0e0e0,stroke:#888888,color:#000
    classDef ml fill:#f0e6ff,stroke:#9d4edd,color:#000
```
