# prathameshv07/aquasense_ai architecture

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

- Interactive diagram: https://gitdiagram.com/prathameshv07/aquasense_ai
- Repository: https://github.com/prathameshv07/aquasense_ai

## Overview

##### Project Type & Purpose
- AquaSense AI is a web-based platform for water quality assessment.
- It integrates Django for the backend (using the standard project structure with config and home directories) and uses HTML, CSS (with Bootstrap) for the frontend.
- It also leverages multiple pre-trained scikit-learn machine learning models (stored as .pkl files under static/model) for predicting water quality metrics.
- Additional integration includes IoT sensor input and Firebase-based contact/feedback functionality.

##### Main Components
a. Client/User Interfaces:
– Web Browser: Renders user pages for manual input and IoT sensor-based input.
– Static Assets: HTML templates, CSS files, images, and documentation (located in home/templates and static directories).

b. Web Application Backend:
– Django Application: Represented by key modules (manage.py, config/, home/ directories) handling HTTP request routing, business logic, and interactions with the ML prediction engine.
– URL Routing & Views: Capture how HTTP requests from the frontend are mapped through home/urls.py and handled by views in home/views.py (including forms and contact input).
– Admin Interface: Provided by Django’s admin (evident in home/admin.py and staticfiles/admin).

c. Machine Learning Component:
– ML Prediction Engine: Highlight that various ML models (e.g., Gradient Boosting Regression among others) are pre-trained and loaded via pickle (stored under static/model for both “eight parameter” and “four parameter” categories).
– Data Flow: Show how water parameter inputs from both manual forms and IoT inputs are passed on to these ML models for processing and prediction.

d. Data Sources & Integration:
– Database: Even if not explicitly detailed in the file tree, the use of Django ORM implies an underlying relational database for user data, water quality records, and logs.
– IoT Sensor Data: Represent a dedicated pathway or integration point that provides real-time sensor input for four key water parameters.
– External Services: Firebase for managing contact and feedback functionality (as noted in the README).

##### Relationships & Interactions
– The Client (browser) and Django views/controllers (HTTP requests/responses).
– Django controllers and the ML Prediction Engine for data and prediction requests.
– Django controllers and the Database (for persistence).
– Django’s contact endpoints and Firebase integration.
- How user input drives the processing flow: from data acquisition, through ML model selection/execution, to delivering remediation recommendations and water quality predictions back to the user.

##### Architectural Patterns & Design Principles
- Follow a Model-View-Controller (MVC) pattern typical of Django projects.
- Separation of concerns: frontend rendering vs. backend logic vs. ML processing.
- Incorporate modular design to reflect the separation between water quality analysis, user input (both manual and IoT), and the external integration with Firebase.

##### Technologies and Frameworks
- Backend: Django (Python) with its config and home directories.
- Machine Learning: scikit-learn models (loaded via pickle).
- Frontend: HTML, CSS, Bootstrap.
- Cloud/Integration: Firebase for real-time contact system.
- Deployment: Vercel configuration is noted (vercel.json), which could be an additional external integration point.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Client / Frontend"
        WB("Web Browser"):::frontend
        subgraph "HTML Templates"
            home_html("home.html"):::frontend
            manual_input("manual_input.html"):::frontend
            contact_html("contact.html"):::frontend
            iot_input("iot_input.html"):::frontend
            suggestions("suggestions.html"):::frontend
        end
        subgraph "Static Assets"
            style_css("style.css"):::frontend
            static_images("Images"):::frontend
            static_docs("Documentation"):::frontend
        end
    end

    %% Backend Layer
    subgraph "Django Web Server"
        manage_py("manage.py"):::backend
        subgraph "Django Core (Config)"
            config_settings("settings.py"):::backend
            config_urls("urls.py"):::backend
            config_wsgi("wsgi.py"):::backend
            config_asgi("asgi.py"):::backend
        end
        subgraph "Application Logic (home)"
            home_views("views.py"):::backend
            home_forms("forms.py"):::backend
            home_models("models.py"):::backend
            home_admin("admin.py"):::backend
            home_urls("urls.py"):::backend
        end
    end

    %% Machine Learning Layer
    subgraph "ML Prediction Engine"
        ml_model_eight("ML Model (8-parameter)"):::ml
        ml_model_four("ML Model (4-parameter)"):::ml
        alt_ml("Alternate ML Files"):::ml
    end

    %% Other Components
    database("Relational Database"):::database
    iot_sensors("IoT Sensor Data"):::external
    firebase("Firebase (Contact/Feedback)"):::external

    %% Data Flow Connections
    WB -->|"HTTP_Request"| manage_py
    home_html --- WB
    manual_input --- WB
    contact_html --- WB
    iot_input --- WB
    suggestions --- WB
    style_css --- WB

    manage_py -->|"Routing"| config_urls
    config_urls -->|"Routes To"| home_urls
    home_views -->|"Processes Data"| ml_model_eight
    home_views -->|"Processes Data"| ml_model_four
    ml_model_eight -->|"Returns Prediction"| home_views
    ml_model_four -->|"Returns Prediction"| home_views
    home_views -->|"Stores/Queries"| database
    home_views -->|"Receives SensorData"| iot_sensors
    home_views -->|"Sends Contact Data"| firebase
    alt_ml --- ml_model_eight
    alt_ml --- ml_model_four

    %% Response Flow
    home_views -->|"HTTP_Response"| WB

    %% Click Events for Frontend Templates & Static Assets
    click home_html "https://github.com/prathameshv07/aquasense_ai/blob/main/home/templates/home.html"
    click manual_input "https://github.com/prathameshv07/aquasense_ai/blob/main/home/templates/manual_input.html"
    click contact_html "https://github.com/prathameshv07/aquasense_ai/blob/main/home/templates/contact.html"
    click iot_input "https://github.com/prathameshv07/aquasense_ai/blob/main/home/templates/iot_input.html"
    click suggestions "https://github.com/prathameshv07/aquasense_ai/blob/main/home/templates/suggestions.html"
    click style_css "https://github.com/prathameshv07/aquasense_ai/blob/main/static/home/style.css"
    click static_images "https://github.com/prathameshv07/aquasense_ai/tree/main/static/images"
    click static_docs "https://github.com/prathameshv07/aquasense_ai/tree/main/static/documentation"

    %% Click Events for Django Backend
    click manage_py "https://github.com/prathameshv07/aquasense_ai/blob/main/manage.py"
    click config_settings "https://github.com/prathameshv07/aquasense_ai/blob/main/config/settings.py"
    click config_urls "https://github.com/prathameshv07/aquasense_ai/blob/main/config/urls.py"
    click config_wsgi "https://github.com/prathameshv07/aquasense_ai/blob/main/config/wsgi.py"
    click config_asgi "https://github.com/prathameshv07/aquasense_ai/blob/main/config/asgi.py"
    click home_views "https://github.com/prathameshv07/aquasense_ai/blob/main/home/views.py"
    click home_forms "https://github.com/prathameshv07/aquasense_ai/blob/main/home/forms.py"
    click home_models "https://github.com/prathameshv07/aquasense_ai/blob/main/home/models.py"
    click home_admin "https://github.com/prathameshv07/aquasense_ai/blob/main/home/admin.py"
    click home_urls "https://github.com/prathameshv07/aquasense_ai/blob/main/home/urls.py"

    %% Click Events for ML Component
    click ml_model_eight "https://github.com/prathameshv07/aquasense_ai/blob/main/static/model/eight parameter/GBR_model.pkl"
    click ml_model_four "https://github.com/prathameshv07/aquasense_ai/blob/main/static/model/four parameter/model.pkl"
    click alt_ml "https://github.com/prathameshv07/aquasense_ai/tree/main/staticfiles/model"

    %% Click Events for External IoT and Firebase
    click iot_sensors "https://github.com/prathameshv07/aquasense_ai/blob/main/home/templates/iot_input.html"
    click firebase "https://github.com/prathameshv07/aquasense_ai/blob/main/home/templates/contact.html"

    %% Styles
    classDef frontend fill:#D9EAD3,stroke:#333,stroke-width:2px;
    classDef backend fill:#C9DAF8,stroke:#333,stroke-width:2px;
    classDef ml fill:#F9CB9C,stroke:#333,stroke-width:2px;
    classDef database fill:#F4CCCC,stroke:#333,stroke-width:2px;
    classDef external fill:#FFD966,stroke:#333,stroke-width:2px;
```
