# layeddie/bird_app architecture

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

- Interactive diagram: https://gitdiagram.com/layeddie/bird_app
- Repository: https://github.com/layeddie/bird_app

## Overview

##### Main Components

A. Hardware Layer:
- Raspberry Pi 3 as the main controller
- Connected peripherals:
- Camera (Pi Camera V2)
- LED (GPIO 18)
- Servo Motor (GPIO 23)
- DHT22 Sensor (GPIO 4)

B. Software Components:
- Three main applications:
1. bird_app_firmware (Nerves firmware application)
2. bird_app_hardware (Hardware interface layer)
3. bird_app_ui (Phoenix web application)

**┌─ User Interface Layer ─────────────────────┐**
- Web Dashboard (Phoenix LiveView)         │
- Telegram Bot Interface                   │
- ┬───────────────────────┘
- ↕
**┌─ Application Layer ─────────────────────────┐**
- BirdAppUi                                   │
- Phoenix Endpoints                        │
- Live Components                          │
- Controllers                              │
- Channels                                 │
- ┬───────────────────────┘
- ↕
**┌─ Hardware Interface Layer ──────────────────┐**
- BirdAppHardware                             │
- Camera Module                            │
- LED Controller                           │
- Servo Controller                         │
- DHT Sensor Module                        │
- ┬───────────────────────┘
- ↕
**┌─ Firmware Layer ───────────────────────────┐**
- BirdAppFirmware (Nerves)                   │
- Hardware Initialization & Management     │
- ┬───────────────────────┘
- ↕
**┌─ Physical Hardware Layer ──────────────────┐**
- Raspberry Pi 3                             │
- Camera V2                               │
- LED (GPIO 18)                           │
- Servo Motor (GPIO 23)                   │
- DHT22 Sensor (GPIO 4)                   │
- ┘

##### Data Flow Indicators

- User interactions from UI to hardware
- Sensor data flow from hardware to UI
- Camera stream flow
- Telegram bot communications
- Temperature/humidity data flow
- LED and servo control signals

##### Component Details

For each major component, include:
- Name
- Primary function
- Key dependencies
- Communication protocols

##### Notes

- Keep the production vs development environment configurations visible
- Read-only nature of the Nerves root filesystem
- Network configuration options (WiFi setup)
- Static asset compilation and deployment flow

Remember to maintain a balance between showing enough detail to understand the system while keeping it clean and readable. The focus should be on the interaction between the three main applications (firmware, hardware, and UI) and how they interface with the physical components.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef app fill:#2ecc71,stroke:#27ae60,color:white
    classDef hardware fill:#e67e22,stroke:#d35400,color:white
    classDef firmware fill:#9b59b6,stroke:#8e44ad,color:white
    classDef physical fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    %% User Interface Layer
    subgraph UI[User Interface Layer]
        WebDash["Web Dashboard"]
        TeleBot["Telegram Bot Interface"]
        LiveComp["Live Components"]
        PowerSwitch["Power Switch Component"]
        ServoSwitch["Servo Switch Component"]
        StatsDisp["Stats Display Component"]
    end

    %% Application Layer
    subgraph APP[Application Layer]
        Endpoint["Phoenix Endpoint"]
        Router["Router"]
        Channels["Channels"]
        Controllers["Controllers"]
        Streamer["Video Streamer"]
    end

    %% Hardware Interface Layer
    subgraph HW[Hardware Interface Layer]
        CamMod["Camera Module"]
        LEDCtrl["LED Controller"]
        ServoCtrl["Servo Controller"]
        DHTMod["DHT Sensor Module"]
        HWConfig["Hardware Configuration"]
    end

    %% Firmware Layer
    subgraph FW[Firmware Layer]
        FirmwareApp["Main Firmware Application"]
        FirmwareConfig["Firmware Configuration"]
    end

    %% Physical Hardware Layer
    subgraph PHY[Physical Hardware Layer]
        RPI["Raspberry Pi 3"]
        Camera["Camera V2"]
        LED["LED (GPIO 18)"]
        Servo["Servo Motor (GPIO 23)"]
        DHT["DHT22 Sensor (GPIO 4)"]
    end

    %% External Services
    TeleAPI["Telegram API"]:::external

    %% Connections
    WebDash --> Endpoint
    TeleBot --> TeleAPI
    LiveComp --> Endpoint
    PowerSwitch --> Controllers
    ServoSwitch --> Controllers
    StatsDisp --> Controllers

    Endpoint --> Router
    Router --> Controllers
    Router --> Channels
    Controllers --> Streamer
    
    Channels --> HWConfig
    Controllers --> HWConfig
    
    CamMod --> Camera
    LEDCtrl --> LED
    ServoCtrl --> Servo
    DHTMod --> DHT
    
    HWConfig --> FirmwareApp
    FirmwareApp --> FirmwareConfig
    FirmwareConfig --> RPI

    %% Click Events
    click WebDash "https://github.com/layeddie/bird_app/blob/master/bird_app_ui/lib/bird_app_ui_web/live/dashboard_live.ex"
    click TeleBot "https://github.com/layeddie/bird_app/blob/master/bird_app_ui/lib/bird_app_ui/telegram.ex"
    click LiveComp "https://github.com/layeddie/bird_app/tree/master/bird_app_ui/lib/bird_app_ui_web/live/components/"
    click PowerSwitch "https://github.com/layeddie/bird_app/blob/master/bird_app_ui/lib/bird_app_ui_web/live/components/power_switch_component.ex"
    click ServoSwitch "https://github.com/layeddie/bird_app/blob/master/bird_app_ui/lib/bird_app_ui_web/live/components/servo_switch_component.ex"
    click StatsDisp "https://github.com/layeddie/bird_app/blob/master/bird_app_ui/lib/bird_app_ui_web/live/components/stats_component.ex"
    click Endpoint "https://github.com/layeddie/bird_app/blob/master/bird_app_ui/lib/bird_app_ui_web/endpoint.ex"
    click Channels "https://github.com/layeddie/bird_app/blob/master/bird_app_ui/lib/bird_app_ui_web/channels/user_socket.ex"
    click Router "https://github.com/layeddie/bird_app/blob/master/bird_app_ui/lib/bird_app_ui_web/router.ex"
    click Controllers "https://github.com/layeddie/bird_app/blob/master/bird_app_ui/lib/bird_app_ui_web/controllers/snap_controller.ex"
    click Streamer "https://github.com/layeddie/bird_app/blob/master/bird_app_ui/lib/bird_app_ui_web/streamer.ex"
    click CamMod "https://github.com/layeddie/bird_app/blob/master/bird_app_hardware/lib/bird_app_hardware/camera.ex"
    click LEDCtrl "https://github.com/layeddie/bird_app/blob/master/bird_app_hardware/lib/bird_app_hardware/led.ex"
    click ServoCtrl "https://github.com/layeddie/bird_app/blob/master/bird_app_hardware/lib/bird_app_hardware/servo.ex"
    click DHTMod "https://github.com/layeddie/bird_app/blob/master/bird_app_hardware/lib/bird_app_hardware/dht.ex"
    click HWConfig "https://github.com/layeddie/bird_app/blob/master/bird_app_hardware/lib/bird_app_hardware/configuration.ex"
    click FirmwareApp "https://github.com/layeddie/bird_app/blob/master/bird_app_firmware/lib/bird_app_firmware.ex"
    click FirmwareConfig "https://github.com/layeddie/bird_app/blob/master/bird_app_firmware/config/target.exs"

    %% Style Applications
    class WebDash,TeleBot,LiveComp,PowerSwitch,ServoSwitch,StatsDisp ui
    class Endpoint,Router,Channels,Controllers,Streamer app
    class CamMod,LEDCtrl,ServoCtrl,DHTMod,HWConfig hardware
    class FirmwareApp,FirmwareConfig firmware
    class RPI,Camera,LED,Servo,DHT physical
```
