# duokhang1676/smart-shelf-cs17iuh architecture

> Architecture diagram of the GitHub repository duokhang1676/smart-shelf-cs17iuh, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/duokhang1676/smart-shelf-cs17iuh
- Repository: https://github.com/duokhang1676/smart-shelf-cs17iuh

## Overview

#### Purpose and System Shape
Smart Vending Shelf is an IoT retail system for weight-based inventory tracking, customer/behavior detection, QR payment, and unpaid-item alerts. It is a multi-runtime monorepo: embedded BLE sensor firmware, Jetson edge software, cloud API/MQTT integration, browser management dashboard, and Android staff app. Primary top-level guidance: `README.md`, `projects/README.md`.

#### Edge Runtime: Shelf Controller
The Jetson-hosted Python application is the physical-system coordinator. Its entry point is `projects/local_server/main.py`, with Flask/web-server setup in `projects/local_server/app/webserver.py`. Route modules expose local UI/API, payment/webhook, Wi-Fi, load-cell, debug, and WebSocket endpoints: `projects/local_server/app/routes/`.

It persists operational shelf/product/RFID/payment data as local JSON files under `projects/local_server/database/`, establishing an offline/local boundary before cloud synchronization.

#### Device and Perception Pipeline
The edge layer ingests:
- BLE/load-cell quantity updates and reconciliation through `projects/local_server/app/modules/update_loadcell_quantity.py` and `projects/local_server/app/modules/quantity_change_monitor.py`.
- RFID identity/state through `projects/local_server/app/modules/listen_rfid.py` and `projects/local_server/app/modules/rfid_state_monitor.py`.
- Camera detection and SORT tracking through `projects/local_server/app/modules/detector/` and `projects/local_server/app/modules/tracking_customer_behavior.py`.
- UART-connected XG26 sensor and voice-command processing through `projects/local_server/app/modules/xg26_sensor.py` and `projects/local_server/app/modules/voice_command_monitor.py`.

These signals drive inventory changes, cart/payment state, customer tracking, local alerts/UI, and cloud events.

#### Cloud Backend and External Boundaries
The Node.js/Express backend starts via `projects/cloud_server/smart-shelf-server-backend/app.js` and `projects/cloud_server/smart-shelf-server-backend/bin/www`. It separates HTTP routes, controllers, and MongoDB-style domain models in:
`projects/cloud_server/smart-shelf-server-backend/src/routes/`,
`projects/cloud_server/smart-shelf-server-backend/src/controller/`,
`projects/cloud_server/smart-shelf-server-backend/src/model/`.

Cloud boundaries include MongoDB Atlas, an MQTT broker, Cloudinary uploads, and SEPAY payment/webhooks, configured or represented in `src/config/database.js`, `src/config/mqtt.js`, and `src/config/cloudinary.js`. Authentication is enforced at the API middleware boundary in `src/middleware/auth.js`.

#### Management Dashboard
The Vite/React dashboard begins at `projects/cloud_server/smart-shelf-server-frontend/src/main.jsx`, with application composition in `src/App.jsx`. Pages manage shelves, products, receipts/orders, tasks, history, notifications, posters, users, and payment configuration under `src/pages/`. Service modules are the REST boundary to the cloud backend, e.g. `src/service/shefl.service.ts`, `src/service/product.service.ts`, and `src/service/receipt.service.ts`.

The dashboard also has a direct MQTT client path for live operational data: `src/lib/mqttClient.ts` and `src/lib/useMqtt.ts`, consumed by realtime shelf components such as `src/components/ShelfRealtimePanel.tsx`.

#### Android Staff Client
The native Android app is a separate staff-facing client, with shell entry activities at `projects/mobile_app/Android.IOT_Mobile_App/app/src/main/java/com/example/iot_employee_android/MainActivity.java` and `LoginActivity.java`. It calls cloud auth/shelf APIs through `api/AuthApi.java` and `api/ShelfApi.java`, presents shelf and history workflows, and includes local Bluetooth/socket facilities (`bluetooth/BluetoothManager.java`, `SocketService.java`). Its role is monitoring and operational access rather than edge control.

#### Embedded Firmware and Hardware Boundary
Silicon Labs firmware projects target the physical peripherals:
- BGM220 load-cell/HX711/LCD device: `projects/silabs-firmware-edge-device/app/bt_soc_bgm220_loadcell/main.c`, `hx711.c`, `ble.c`.
- EFR32xG26 BLE environmental sensor device: `projects/silabs-firmware-edge-device/app/bt_soc_xg26_sensor/main.c`, `advertise.c`, and `driver/`.
- XG26 audio capture/keyword classification: `app/i2s_mic_xg26_audio_data_capture/main.c` and `app/ml_xg26_audio_classifier/audio_classifier.cc`.

BLE is the MCU-to-Jetson boundary; UART is used for XG26 command reception. Silicon Labs bootloader projects provide device update infrastructure under `projects/silabs-firmware-edge-device/bootloader/`.

Main entry points: [`projects/local_server/app/modules/update_loadcell_quantity.py`](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/local_server/app/modules/update_loadcell_quantity.py) (Device Signal Processing), [`projects/cloud_server/smart-shelf-server-backend/app.js`](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/cloud_server/smart-shelf-server-backend/app.js) (Cloud API Server), [`projects/local_server/app/webserver.py`](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/local_server/app/webserver.py) (Local Web and API), [`projects/local_server/main.py`](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/local_server/main.py) (Shelf Controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Embedded Firmware"]
  node_loadcell_firmware{{"BGM220 Load-Cell Firmware<br/>embedded C<br/>[main.c]"}}
  node_xg26_sensor_firmware{{"XG26 Sensor Firmware<br/>embedded C<br/>[main.c]"}}
  node_audio_firmware{{"XG26 Audio Classifier<br/>embedded ML"}}
  node_bootloader["Device Bootloaders<br/>firmware update"]
end

subgraph group_edge["Jetson Edge Runtime"]
  node_edge_entry["Shelf Controller<br/>Python entry point<br/>[main.py]"]
  node_edge_web["Local Web and API<br/>Flask<br/>[webserver.py]"]
  node_device_signals["Device Signal Processing<br/>Python modules"]
  node_local_store[("Local Shelf Store<br/>JSON persistence")]
end

subgraph group_cloud["Cloud Backend"]
  node_cloud_app["Cloud API Server<br/>Node.js / Express<br/>[app.js]"]
  node_api_routes["HTTP Routes<br/>Express routes"]
  node_domain_controllers["Domain Controllers<br/>Express controllers"]
  node_domain_models["Domain Models<br/>MongoDB models"]
end

subgraph group_clients["Staff Clients"]
  node_dashboard["Management Dashboard<br/>Vite / React<br/>[main.jsx]"]
  node_dashboard_mqtt["Dashboard Realtime Client<br/>MQTT client<br/>[mqttClient.ts]"]
  node_android_app["Android Staff App<br/>native Android<br/>[MainActivity.java]"]
  node_android_local_io["Android Bluetooth and Socket<br/>mobile local I/O"]
end

node_mongodb[("MongoDB Atlas<br/>cloud database")]
node_mqtt["MQTT Broker<br/>event broker"]
node_payment_uploads["SEPAY and Cloudinary<br/>external services"]

node_loadcell_firmware -->|"BLE load-cell updates"| node_device_signals
node_xg26_sensor_firmware -->|"BLE sensor data"| node_device_signals
node_audio_firmware -->|"UART commands"| node_device_signals
node_bootloader -.->|"updates"| node_loadcell_firmware
node_bootloader -.->|"updates"| node_xg26_sensor_firmware
node_edge_entry -->|"starts"| node_edge_web
node_edge_entry -->|"coordinates"| node_device_signals
node_device_signals -->|"persists shelf state"| node_local_store
node_edge_web -->|"reads and writes"| node_local_store
node_device_signals -->|"publishes events"| node_mqtt
node_edge_web -->|"payment webhooks"| node_payment_uploads
node_cloud_app -->|"serves"| node_api_routes
node_api_routes -->|"dispatches"| node_domain_controllers
node_domain_controllers -->|"uses"| node_domain_models
node_domain_models -->|"persists"| node_mongodb
node_cloud_app -->|"publishes and subscribes"| node_mqtt
node_cloud_app -->|"integrates"| node_payment_uploads
node_dashboard -->|"authenticated REST API"| node_cloud_app
node_dashboard_mqtt -->|"live operational data"| node_mqtt
node_dashboard -->|"uses"| node_dashboard_mqtt
node_android_app -->|"auth and shelf APIs"| node_cloud_app
node_android_app -->|"uses"| node_android_local_io

click node_loadcell_firmware "https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/silabs-firmware-edge-device/app/bt_soc_bgm220_loadcell/main.c"
click node_xg26_sensor_firmware "https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/silabs-firmware-edge-device/app/bt_soc_xg26_sensor/main.c"
click node_audio_firmware "https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/silabs-firmware-edge-device/app/ml_xg26_audio_classifier/audio_classifier.cc"
click node_edge_entry "https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/local_server/main.py"
click node_edge_web "https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/local_server/app/webserver.py"
click node_device_signals "https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/local_server/app/modules/update_loadcell_quantity.py"
click node_cloud_app "https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/cloud_server/smart-shelf-server-backend/app.js"
click node_dashboard "https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/cloud_server/smart-shelf-server-frontend/src/main.jsx"
click node_dashboard_mqtt "https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/cloud_server/smart-shelf-server-frontend/src/lib/mqttClient.ts"
click node_android_app "https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/mobile_app/Android.IOT_Mobile_App/app/src/main/java/com/example/iot_employee_android/MainActivity.java"
click node_android_local_io "https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/mobile_app/Android.IOT_Mobile_App/app/src/main/java/com/example/iot_employee_android/bluetooth/BluetoothManager.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_loadcell_firmware,node_xg26_sensor_firmware,node_audio_firmware,node_bootloader toneBlue
class node_edge_entry,node_edge_web,node_device_signals,node_local_store toneAmber
class node_cloud_app,node_api_routes,node_domain_controllers,node_domain_models toneMint
class node_dashboard,node_dashboard_mqtt,node_android_app,node_android_local_io toneRose
class node_mongodb,node_mqtt,node_payment_uploads toneNeutral
```

## Components

### Embedded Firmware

- [BGM220 Load-Cell Firmware](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/silabs-firmware-edge-device/app/bt_soc_bgm220_loadcell/main.c): embedded C · Reads HX711 and publishes BLE data. · `projects/silabs-firmware-edge-device/app/bt_soc_bgm220_loadcell/main.c`
- [XG26 Sensor Firmware](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/silabs-firmware-edge-device/app/bt_soc_xg26_sensor/main.c): embedded C · BLE environmental sensor device. · `projects/silabs-firmware-edge-device/app/bt_soc_xg26_sensor/main.c`
- [XG26 Audio Classifier](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/silabs-firmware-edge-device/app/ml_xg26_audio_classifier/audio_classifier.cc): embedded ML · Captures audio and classifies keywords. · `projects/silabs-firmware-edge-device/app/ml_xg26_audio_classifier/audio_classifier.cc`
- **Device Bootloaders**: firmware update

### Jetson Edge Runtime

- [Shelf Controller](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/local_server/main.py): Python entry point · Coordinates local physical shelf operations. · `projects/local_server/main.py`
- [Local Web and API](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/local_server/app/webserver.py): Flask · Hosts local UI, APIs, webhooks, and WebSockets. · `projects/local_server/app/webserver.py`
- [Device Signal Processing](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/local_server/app/modules/update_loadcell_quantity.py): Python modules · Reconciles load-cell, RFID, camera, tracking, sensor, and voice signals. · `projects/local_server/app/modules/update_loadcell_quantity.py`
- **Local Shelf Store**: JSON persistence · Offline shelf, product, RFID, and payment state.

### Cloud Backend

- [Cloud API Server](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/cloud_server/smart-shelf-server-backend/app.js): Node.js / Express · Cloud API and MQTT integration entry point. · `projects/cloud_server/smart-shelf-server-backend/app.js`
- **HTTP Routes**: Express routes
- **Domain Controllers**: Express controllers
- **Domain Models**: MongoDB models

### Staff Clients

- [Management Dashboard](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/cloud_server/smart-shelf-server-frontend/src/main.jsx): Vite / React · Manages shelves, products, orders, staff, and configuration. · `projects/cloud_server/smart-shelf-server-frontend/src/main.jsx`
- [Dashboard Realtime Client](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/cloud_server/smart-shelf-server-frontend/src/lib/mqttClient.ts): MQTT client · `projects/cloud_server/smart-shelf-server-frontend/src/lib/mqttClient.ts`
- [Android Staff App](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/mobile_app/Android.IOT_Mobile_App/app/src/main/java/com/example/iot_employee_android/MainActivity.java): native Android · Staff monitoring and operational access. · `projects/mobile_app/Android.IOT_Mobile_App/app/src/main/java/com/example/iot_employee_android/MainActivity.java`
- [Android Bluetooth and Socket](https://github.com/duokhang1676/smart-shelf-cs17iuh/blob/main/projects/mobile_app/Android.IOT_Mobile_App/app/src/main/java/com/example/iot_employee_android/bluetooth/BluetoothManager.java): mobile local I/O · `projects/mobile_app/Android.IOT_Mobile_App/app/src/main/java/com/example/iot_employee_android/bluetooth/BluetoothManager.java`

### Other components

- **MongoDB Atlas**: cloud database
- **MQTT Broker**: event broker · Live shelf and operational events.
- **SEPAY and Cloudinary**: external services · Payment webhooks and media uploads.

## Connections

- BGM220 Load-Cell Firmware → Device Signal Processing: BLE load-cell updates
- XG26 Sensor Firmware → Device Signal Processing: BLE sensor data
- XG26 Audio Classifier → Device Signal Processing: UART commands
- Device Bootloaders → BGM220 Load-Cell Firmware: updates
- Device Bootloaders → XG26 Sensor Firmware: updates
- Shelf Controller → Local Web and API: starts
- Shelf Controller → Device Signal Processing: coordinates
- Device Signal Processing → Local Shelf Store: persists shelf state
- Local Web and API → Local Shelf Store: reads and writes
- Device Signal Processing → MQTT Broker: publishes events
- Local Web and API → SEPAY and Cloudinary: payment webhooks
- Cloud API Server → HTTP Routes: serves
- HTTP Routes → Domain Controllers: dispatches
- Domain Controllers → Domain Models: uses
- Domain Models → MongoDB Atlas: persists
- Cloud API Server → MQTT Broker: publishes and subscribes
- Cloud API Server → SEPAY and Cloudinary: integrates
- Management Dashboard → Cloud API Server: authenticated REST API
- Dashboard Realtime Client → MQTT Broker: live operational data
- Management Dashboard → Dashboard Realtime Client: uses
- Android Staff App → Cloud API Server: auth and shelf APIs
- Android Staff App → Android Bluetooth and Socket: uses
