# ivadim/fruitnanny architecture

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

- Interactive diagram: https://gitdiagram.com/ivadim/fruitnanny
- Repository: https://github.com/ivadim/fruitnanny

## Overview

##### Project type and purpose
- Fruitnanny is a full-stack, Docker-based IoT streaming application (“DIY geek baby monitor”) built on Node.js.
- It runs on a Raspberry Pi, captures video/audio via a NoIR camera and GStreamer pipelines, reads temperature/humidity/light/motion via Python scripts, provides a custom Web UI, and uses WebRTC (Janus Gateway) to stream media to browsers.

##### File structure
- Top-level directories and their roles:
- bin/ – Python and shell scripts to read sensors or trigger recording.
- docker/ – Dockerfiles for each service: fruitnanny (Node.js app), gstreamer (media pipelines), janus (WebRTC gateway), notification.
- configuration/ – Janus, nginx, systemd, SSL configs.
- server/ – Express app entrypoint (app.js/app.ts) and route handlers for sensors, buttons, light, DHT.
- public/ & views/ – Static assets (JS widgets, CSS, third-party libraries) and EJS templates for the UI.
- docker-compose*.yml – Orchestrates services into a single Docker network.

##### README for additional insights
- Confirms use of Node.js, WebRTC via Janus, GStreamer for audio/video capture, sensors via Python.
- Describes that browsers connect over HTTP(S) for UI and negotiate WebRTC sessions with Janus directly.
- Installation uses Docker Compose to deploy all services on the Pi.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Hardware Layer
    subgraph "Hardware Layer"
        direction TB
        Camera["Camera Module"]:::hardware
        Microphone["Microphone"]:::hardware
        IRLight["IR Light Array"]:::hardware
        DHT22["DHT22 Sensor"]:::hardware
        Motion["Motion Sensor"]:::hardware
        LightSensor["Light Sensor"]:::hardware
    end

    %% Docker Host / Network
    subgraph "Docker Host" 
        direction TB
        subgraph "Docker Network"
            direction TB
            GStreamer["GStreamer Container"]:::service
            SensorScripts["Sensor Scripts"]:::service
            Janus["Janus WebRTC Gateway"]:::gateway
            NodeApp["Node.js Application"]:::app
            Notification["Notification Service"]:::notification
            ReverseProxy["Reverse Proxy (nginx)"]:::proxy
        end
    end

    %% Client Layer
    Client["Client Browser"]:::client
    STUNTURN["STUN/TURN Servers"]:::client

    %% Connections
    Camera -->|RTP| GStreamer
    Microphone -->|RTP| GStreamer
    IRLight -->|Control via Node.js| NodeApp
    DHT22 -->|Python JSON/REST| SensorScripts
    Motion -->|Shell JSON/REST| SensorScripts
    LightSensor -->|Shell JSON/REST| SensorScripts

    SensorScripts -->|HTTPS REST| NodeApp
    GStreamer -->|RTP Stream| Janus
    NodeApp -->|HTTP API| Janus
    Janus -->|HTTP API| NodeApp
    NodeApp -->|Trigger Alerts| Notification
    ReverseProxy -->|Proxy HTTPS| NodeApp
    ReverseProxy -->|Proxy WS/HTTP| Janus

    Client -->|HTTPS UI & REST| ReverseProxy
    Client -->|WebRTC Signaling & RTP| STUNTURN
    Client -->|WebRTC to Janus| ReverseProxy

    %% Click Events
    click GStreamer "https://github.com/ivadim/fruitnanny/tree/master/docker/gstreamer/"
    click SensorScripts "https://github.com/ivadim/fruitnanny/tree/master/bin/"
    click Janus "https://github.com/ivadim/fruitnanny/tree/master/docker/janus/"
    click NodeApp "https://github.com/ivadim/fruitnanny/tree/master/docker/fruitnanny/Dockerfile"
    click Notification "https://github.com/ivadim/fruitnanny/tree/master/docker/notification/Dockerfile"
    click ReverseProxy "https://github.com/ivadim/fruitnanny/tree/master/configuration/nginx/fruitnanny_https"
    click Camera "https://github.com/ivadim/fruitnanny/blob/master/bin/video.sh"
    click Microphone "https://github.com/ivadim/fruitnanny/blob/master/bin/audio.sh"
    click IRLight "https://github.com/ivadim/fruitnanny/blob/master/bin/video.sh"
    click DHT22 "https://github.com/ivadim/fruitnanny/blob/master/bin/dht22.py"
    click Motion "https://github.com/ivadim/fruitnanny/blob/master/bin/motion.py"
    click LightSensor "https://github.com/ivadim/fruitnanny/blob/master/bin/light.sh"

    %% Styles
    classDef hardware fill:#f2f2f2,stroke:#333,stroke-width:1px
    classDef service fill:#AED6F1,stroke:#1B4F72,stroke-width:1px
    classDef gateway fill:#85C1E9,stroke:#1A5276,stroke-width:1px
    classDef app fill:#5499C7,stroke:#154360,stroke-width:1px
    classDef notification fill:#5DADE2,stroke:#1F618D,stroke-width:1px
    classDef proxy fill:#D6EAF8,stroke:#2874A6,stroke-width:1px
    classDef client fill:#A9DFBF,stroke:#145A32,stroke-width:1px
    classDef network stroke-dasharray: 5 5,stroke:#999
    class DockerHost network
    class DockerNetwork network
```
