How hypfer/valetudo works
Project type and purpose
• This is a full-stack, on-premises “cloud replacement” for vacuum robots called Valetudo.
• It consists of:
• A Node.js backend that handles communication with the robot (via Miio), exposes a REST-Swagger API, an MQTT interface (Homie + Home Assistant autodiscovery), a webserver (HTTP + SSE), an updater, scheduler, SSDP/NTP clients, etc.
• A React/TypeScript single-page application (SPA) frontend served by that backend.
• Integration points: the physical robot (LAN), an MQTT broker of your choice, NTP servers, and GitHub for update checks.
Top-level components and directory structure
• frontend/ – React SPA, calls REST/SSE endpoints and MQTT indirectly via backend
• backend/ – Node.js monolith, subdivided into:
– lib/webserver/ – HTTP server, routers for every capability, SSE middleware
– lib/miio/ – Miio protocol adapter (UDP sockets) to send/receive robot commands
– lib/mqtt/ – MQTT controller/adapters for Homie/HASS, publishes state + accepts commands
– lib/core/ + lib/entities/ – Domain model (robots, capabilities, events)
– lib/scheduler/ – Local task scheduler for timers
– lib/updater/ – Firmware‐update logic + GitHub provider
– lib/utils/ + lib/valetudo_events/ – Logging, caching, event handling, SSDP/NTP support
• util/ – Build scripts, code generators (OpenAPI, MQTT docs, release manifests)
Architectural style & patterns
• The backend uses a modular/hexagonal approach:
• Adapters for protocols (Miio, MQTT, HTTP, SSDP, NTP)
• Ports/services in lib/core, lib/entities, and valetudo_events
• Separation of concerns: routers ➔ controllers ➔ capability handlers ➔ domain model
• The SPA is a containerized React app that interacts via REST/SSE; no direct Miio/MQTT calls.
Main components & interactions
A. Frontend (React SPA in user’s browser)
• Served over HTTP by the backend’s WebServer module
• Fetches REST API endpoints (CapabilitiesRouter, RobotRouter, etc.)
• Subscribes to Server-Sent Events for live state updates
B. Backend (Node.js service running on the vacuum or gateway)
1. WebServer – HTTP(S) + SSE endpoint
2. MQTTController – connects to external MQTT broker, publishes state, subscribes to commands
3. MiioAdapter – UDP socket to talk to the robot’s firmware
4. Scheduler – Timer engine triggering actions via core capabilities
5. Updater – Checks GitHub, downloads/releases firmware updates
6. NTPClient – Synchronizes clock to NTP servers
7. SSDPServer – Broadcasts service availability on LAN
8. Core Domain – ValetudoRobotFactory, Capability implementations, Entities, EventStore
C. External services
• Vacuum Robot – accepts Miio packets (commands) and sends status/map data
• MQTT Broker – receives Homie/HA-autodiscovery announcements + telemetry
• NTP Server – time synchronization
• GitHub Update Provider – firmware metadata & binaries