# Architecture Diagram

KLNavBot follows a layered architecture where onboard sensing, embedded control, cloud synchronization, and web visualization work together as one delivery system.

```mermaid
flowchart LR
    subgraph Robot[ESP32 Delivery Robot]
        GPS[NEO-6M GPS]
        US[HC-SR04 Ultrasonic Sensor]
        MCU[ESP32 Firmware]
        MOTORS[L298N Motor Driver]
        GPS --> MCU
        US --> MCU
        MCU --> MOTORS
    end

    subgraph Cloud[Firebase Cloud Layer]
        DB[(Realtime Database)]
        AUTH[Firebase Auth / Rules]
        DB --- AUTH
    end

    subgraph Web[Web Dashboard]
        UI[Monitoring UI]
        MAP[Route Map]
        OP[Manual Control + OTP]
        UI --> MAP
        UI --> OP
    end

    MCU <--> DB
    DB <--> UI
    DB <--> MAP
    OP <--> DB

    style Robot fill:#eef6ff,stroke:#2563eb,stroke-width:1px
    style Cloud fill:#ecfdf5,stroke:#059669,stroke-width:1px
    style Web fill:#fff7ed,stroke:#ea580c,stroke-width:1px
```

### Design Summary

- The ESP32 is the control center for all sensing, motion, and cloud exchange.
- GPS provides location telemetry for tracking and delivery visibility.
- Ultrasonic sensing enforces a safety stop whenever an obstacle is too close.
- Firebase acts as the shared state bus between firmware and dashboard.
- The dashboard turns live cloud data into an operator-friendly robot interface.
