# igobyjack/neptune_interface architecture

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

- Interactive diagram: https://gitdiagram.com/igobyjack/neptune_interface
- Repository: https://github.com/igobyjack/neptune_interface

## Overview

##### Project Type and Purpose
- The project is an IoT solution designed for precision lawn care. It uses a moisture sensor connected to a microcontroller (Arduino) to detect soil moisture alongside data from an external weather API. These combined inputs guide whether or not to water the lawn.
- The system comprises three core parts: an Arduino script running on a microcontroller, a Raspberry Pi acting as the backbone (running an async WebSocket server), and a webpage that presents data to end users in real time.

##### Key Components Identified from the File Tree and README
a. Sensor/Microcontroller Component:
- File: sensor_reading/sensor_reading.ino
- Role: Written in C++ for Arduino, this script reads the moisture sensor data.
b. Raspberry Pi Backend Component:
- File: backend/server_reader.py
- Role: An asynchronous WebSocket server that:
- Reads incoming sensor data (likely from a serial port).
- Broadcasts the data to connected webpage clients.
c. Web Interface Component:
- File: webpage/index.html
- Role: A client-facing webpage served by the Raspberry Pi’s WiFi network.
- Uses JavaScript to establish a WebSocket connection and update in real time.
d. Testing/Experimental Components:
- Files in the testing/ directory (app.py, logger.py, moisturelog.csv)
- Role: Proof-of-concept and debugging scripts to experiment with serial port data reading and interface behavior.

##### Relationships and Data Flow
- Data originates at the moisture sensor, processed by the Arduino microcontroller.
- The processed sensor data is sent over (presumably via a serial connection) to the Raspberry Pi.
- The Python-based asynchronous WebSocket server on the Raspberry Pi (server_reader.py) receives this data.
- The server then pushes the sensor data to connected clients through the WebSocket.
- On the client side, the webpage (index.html) uses JavaScript to listen for these incoming updates and reflects them on the UI.
- Additionally, there is an external dependency on the Open Weather API, which can be visualized as a separate external service that influences the logic for watering decisions.

##### Architectural Patterns and Technologies
- Microcontroller (Arduino) reading hardware sensor data.
- Asynchronous WebSocket for real-time communication on the backend.
- Client-server architecture with the Raspberry Pi serving both as a data receiver and a WiFi access point.
- Separation of concerns: distinct modules for sensor reading, server-side communication, and client-side display.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A_SENSOR["Arduino - sensor_reading.ino (Moisture Sensor)"]
    subgraph "Raspberry Pi"
        WS["Async WebSocket Server (server_reader.py)"]
        WSERV["Webserver for Webpage (index.html hosted on local network)"]
        API["Data Aggregator & API Connector (Open Weather API integration)"]
    end
    CLIENT["Webpage Client (index.html + JavaScript)"]
    EXT["Open Weather API"]
    TEST["Testing/Experimental (testing/)"]

    A_SENSOR -->|"SensorData"| WS
    API -->|"AggregatedData"| WS
    WS -->|"WebSocketBroadcast"| CLIENT
    WSERV -->|"ServedContent"| CLIENT
    EXT -->|"ExternalWeatherData"| API

    click A_SENSOR "https://github.com/igobyjack/neptune_interface/blob/main/sensor_reading/sensor_reading.ino"
    click WS "https://github.com/igobyjack/neptune_interface/blob/main/backend/server_reader.py"
    click WSERV "https://github.com/igobyjack/neptune_interface/blob/main/webpage/index.html"
    click CLIENT "https://github.com/igobyjack/neptune_interface/blob/main/webpage/index.html"
    click TEST "https://github.com/igobyjack/neptune_interface/tree/main/testing/"

    class A_SENSOR sensor
    class WS,WSERV,API backend
    class CLIENT client
    class EXT external
    class TEST testing

    classDef sensor fill:#a2d9ce,stroke:#1abc9c,stroke-width:2px,color:#000
    classDef backend fill:#aed6f1,stroke:#3498db,stroke-width:2px,color:#000
    classDef client fill:#f9e79f,stroke:#f1c40f,stroke-width:2px,color:#000
    classDef external fill:#d7bde2,stroke:#8e44ad,stroke-width:2px,color:#000
    classDef testing fill:#fadbd8,stroke:#e74c3c,stroke-width:2px,color:#000
```
