# minhkhang2222/smartbox-lastmiledelivery architecture

> Architecture diagram of the GitHub repository minhkhang2222/smartbox-lastmiledelivery, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/minhkhang2222/smartbox-lastmiledelivery
- Repository: https://github.com/minhkhang2222/smartbox-lastmiledelivery

## Overview

SmartLocker provides parcel drop-off and pickup through a React client, Spring Boot business API, persisted order/locker state, MQTT-controlled hardware, and face recognition. The principal workflow is order creation and locker assignment, device unlock/deposit confirmation, then recipient pickup by face authentication or OTP. The README documents PostgreSQL, MQTT, Raspberry Pi, and FastAPI integrations; sampled sources confirm key order, enrollment, and face-unlock behavior. Several controllers, schedulers, and hardware details are represented at their exact tree paths but were not sampled, so undocumented links are omitted.

Main entry points: [`frontend/src/App.jsx`](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/frontend/src/App.jsx) (React application), [`src/main/java/smartlocker/smartlocker/controller`](https://github.com/minhkhang2222/smartbox-lastmiledelivery/tree/main/src/main/java/smartlocker/smartlocker/controller) (REST controllers), [`src/main/java/smartlocker/smartlocker/repository`](https://github.com/minhkhang2222/smartbox-lastmiledelivery/tree/main/src/main/java/smartlocker/smartlocker/repository) (Persistence repositories), [`src/main/java/smartlocker/smartlocker/service/FaceAuthenticationService.java`](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/FaceAuthenticationService.java) (Face unlock orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_web["React application<br/>[App.jsx]"]
  node_orders_ui["Orders and dashboard"]
  node_enroll_ui["Face enrollment UI<br/>[FaceEnrollment.jsx]"]
  node_admin_ui["Administration UI<br/>[Admin.jsx]"]
end

subgraph group_core["Business backend"]
  node_auth["Login and JWT"]
  node_api["REST controllers"]
  node_order_service["Order lifecycle<br/>[OrderService.java]"]
  node_pickup["OTP pickup"]
  node_face_auth["Face unlock orchestration"]
  node_face_enrollment["Embedding registration"]
  node_mqtt_pub["MQTT command publisher"]
  node_mqtt_events["MQTT event handling"]
  node_schedulers["Order timeout schedulers"]
  node_domain["Order and locker state<br/>[Order.java]"]
  node_repositories["Persistence repositories"]
end

subgraph group_hardware["Locker hardware"]
  node_pi["Raspberry Pi gateway<br/>[app.py]"]
  node_pi_camera["Camera and face client<br/>[camera.py]"]
end

subgraph group_vision["Face recognition"]
  node_ai["Embedding service<br/>[app.py]"]
end

node_user(("Locker user"))
node_postgres[("PostgreSQL")]
node_broker["MQTT broker"]
node_device["ESP32 locker device"]

node_user -->|"uses"| node_web
node_web -->|"HTTP requests"| node_api
node_web -->|"logs in"| node_auth
node_web -->|"routes to"| node_orders_ui
node_web -->|"routes to"| node_enroll_ui
node_web -->|"routes to"| node_admin_ui
node_api -.->|"handles orders"| node_order_service
node_order_service -->|"reads and writes"| node_repositories
node_order_service -->|"publishes commands"| node_mqtt_pub
node_mqtt_pub -->|"publishes MQTT"| node_broker
node_broker -->|"dispatches commands"| node_device
node_device -->|"reports events"| node_broker
node_mqtt_events -.->|"updates state"| node_repositories
node_schedulers -->|"checks timeouts"| node_repositories
node_repositories -->|"persists entities"| node_postgres
node_api -.->|"handles OTP pickup"| node_pickup
node_pickup -->|"publishes unlock"| node_mqtt_pub
node_pi -->|"uses camera"| node_pi_camera
node_pi -->|"sends embedding"| node_face_auth
node_api -.->|"handles face auth"| node_face_auth
node_face_auth -->|"publishes unlock"| node_mqtt_pub
node_face_auth -->|"loads orders"| node_repositories
node_enroll_ui -.->|"submits enrollment"| node_api
node_api -.->|"registers faces"| node_face_enrollment
node_face_enrollment -.->|"requests embeddings"| node_ai
node_face_enrollment -->|"stores vectors"| node_repositories
node_face_auth -.->|"matches vectors"| node_ai

click node_web "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/frontend/src/App.jsx"
click node_auth "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/controller/AuthController.java"
click node_orders_ui "https://github.com/minhkhang2222/smartbox-lastmiledelivery/tree/main/frontend/src/components"
click node_enroll_ui "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/frontend/src/components/FaceEnrollment.jsx"
click node_admin_ui "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/frontend/src/components/Admin.jsx"
click node_api "https://github.com/minhkhang2222/smartbox-lastmiledelivery/tree/main/src/main/java/smartlocker/smartlocker/controller"
click node_order_service "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/OrderService.java"
click node_pickup "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/PickupOtpService.java"
click node_face_auth "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/FaceAuthenticationService.java"
click node_face_enrollment "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/FaceAuthRegService.java"
click node_mqtt_pub "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/MqttCommandPublisher.java"
click node_mqtt_events "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/MqttEventListener.java"
click node_schedulers "https://github.com/minhkhang2222/smartbox-lastmiledelivery/tree/main/src/main/java/smartlocker/smartlocker/schedule"
click node_domain "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/model/Order.java"
click node_repositories "https://github.com/minhkhang2222/smartbox-lastmiledelivery/tree/main/src/main/java/smartlocker/smartlocker/repository"
click node_ai "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/microservice/ApiLayer/app.py"
click node_pi "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/HardwareCode/raspberry_gateway/app.py"
click node_pi_camera "https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/HardwareCode/raspberry_gateway/camera.py"

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_web,node_orders_ui,node_enroll_ui,node_admin_ui,node_user toneBlue
class node_auth,node_api,node_order_service,node_pickup,node_face_auth,node_face_enrollment,node_mqtt_pub,node_mqtt_events,node_schedulers,node_domain,node_repositories,node_postgres toneAmber
class node_pi,node_pi_camera toneMint
class node_ai toneRose
class node_broker,node_device toneIndigo
```

## Components

### Web client

- [React application](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Orders and dashboard](https://github.com/minhkhang2222/smartbox-lastmiledelivery/tree/main/frontend/src/components): `frontend/src/components`
- [Face enrollment UI](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/frontend/src/components/FaceEnrollment.jsx): `frontend/src/components/FaceEnrollment.jsx`
- [Administration UI](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/frontend/src/components/Admin.jsx): `frontend/src/components/Admin.jsx`

### Business backend

- [Login and JWT](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/controller/AuthController.java): `src/main/java/smartlocker/smartlocker/controller/AuthController.java`
- [REST controllers](https://github.com/minhkhang2222/smartbox-lastmiledelivery/tree/main/src/main/java/smartlocker/smartlocker/controller): `src/main/java/smartlocker/smartlocker/controller`
- [Order lifecycle](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/OrderService.java): `src/main/java/smartlocker/smartlocker/service/OrderService.java`
- [OTP pickup](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/PickupOtpService.java): `src/main/java/smartlocker/smartlocker/service/PickupOtpService.java`
- [Face unlock orchestration](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/FaceAuthenticationService.java): `src/main/java/smartlocker/smartlocker/service/FaceAuthenticationService.java`
- [Embedding registration](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/FaceAuthRegService.java): `src/main/java/smartlocker/smartlocker/service/FaceAuthRegService.java`
- [MQTT command publisher](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/MqttCommandPublisher.java): `src/main/java/smartlocker/smartlocker/service/MqttCommandPublisher.java`
- [MQTT event handling](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/service/MqttEventListener.java): `src/main/java/smartlocker/smartlocker/service/MqttEventListener.java`
- [Order timeout schedulers](https://github.com/minhkhang2222/smartbox-lastmiledelivery/tree/main/src/main/java/smartlocker/smartlocker/schedule): `src/main/java/smartlocker/smartlocker/schedule`
- [Order and locker state](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/src/main/java/smartlocker/smartlocker/model/Order.java): `src/main/java/smartlocker/smartlocker/model/Order.java`
- [Persistence repositories](https://github.com/minhkhang2222/smartbox-lastmiledelivery/tree/main/src/main/java/smartlocker/smartlocker/repository): `src/main/java/smartlocker/smartlocker/repository`

### Locker hardware

- [Raspberry Pi gateway](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/HardwareCode/raspberry_gateway/app.py): `HardwareCode/raspberry_gateway/app.py`
- [Camera and face client](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/HardwareCode/raspberry_gateway/camera.py): `HardwareCode/raspberry_gateway/camera.py`

### Face recognition

- [Embedding service](https://github.com/minhkhang2222/smartbox-lastmiledelivery/blob/main/microservice/ApiLayer/app.py): `microservice/ApiLayer/app.py`

### Other components

- **Locker user**
- **PostgreSQL**
- **MQTT broker**
- **ESP32 locker device**

## Connections

- Locker user → React application: uses (evidence: `README.md`)
- React application → REST controllers: HTTP requests (evidence: `README.md`)
- React application → Login and JWT: logs in (evidence: `frontend/src/App.jsx`)
- React application → Orders and dashboard: routes to (evidence: `frontend/src/App.jsx`)
- React application → Face enrollment UI: routes to (evidence: `frontend/src/App.jsx`)
- React application → Administration UI: routes to (evidence: `frontend/src/App.jsx`)
- REST controllers → Order lifecycle: handles orders
- Order lifecycle → Persistence repositories: reads and writes (evidence: `src/main/java/smartlocker/smartlocker/service/OrderService.java`)
- Order lifecycle → MQTT command publisher: publishes commands (evidence: `src/main/java/smartlocker/smartlocker/service/OrderService.java`)
- MQTT command publisher → MQTT broker: publishes MQTT (evidence: `README.md`)
- MQTT broker → ESP32 locker device: dispatches commands (evidence: `README.md`)
- ESP32 locker device → MQTT broker: reports events (evidence: `README.md`)
- MQTT event handling → Persistence repositories: updates state
- Order timeout schedulers → Persistence repositories: checks timeouts (evidence: `src/main/java/smartlocker/smartlocker/repository/OrderLockerRepository.java`)
- Persistence repositories → PostgreSQL: persists entities (evidence: `README.md`)
- REST controllers → OTP pickup: handles OTP pickup
- OTP pickup → MQTT command publisher: publishes unlock (evidence: `src/main/java/smartlocker/smartlocker/service/PickupOtpService.java`)
- Raspberry Pi gateway → Camera and face client: uses camera (evidence: `HardwareCode/raspberry_gateway/app.py`)
- Raspberry Pi gateway → Face unlock orchestration: sends embedding (evidence: `README.md`)
- REST controllers → Face unlock orchestration: handles face auth
- Face unlock orchestration → MQTT command publisher: publishes unlock (evidence: `src/main/java/smartlocker/smartlocker/service/FaceAuthenticationService.java`)
- Face unlock orchestration → Persistence repositories: loads orders (evidence: `src/main/java/smartlocker/smartlocker/service/FaceAuthenticationService.java`)
- Face enrollment UI → REST controllers: submits enrollment
- REST controllers → Embedding registration: registers faces
- Embedding registration → Embedding service: requests embeddings (evidence: `README.md`)
- Embedding registration → Persistence repositories: stores vectors (evidence: `src/main/java/smartlocker/smartlocker/service/FaceAuthRegService.java`)
- Face unlock orchestration → Embedding service: matches vectors
