How rakesh-18112006/smarthome works
1. This repository is a multi-part smart home system with three main layers: a Node.js backend API/orchestrator, a React/Vite frontend dashboard, and a separate “stair case” edge subsystem with firmware and a small Python web service.
2. The backend is the central control plane. It exposes feature routes for homes, rooms, devices, sensors, automations, and Google Smart Home integration, and it likely acts as the place where user actions are translated into device commands and persisted configuration.
3. MongoDB is the main persistence boundary. backend/src/infrastructure/mongodb/db.js sits below the feature modules, and the entity files (Device, Room, Sensor, Automation) suggest the backend stores the home model, device metadata, sensor records, and automation definitions there.
4. Real-time updates are handled separately from REST-style routes. backend/src/core/websocket/socketService.js indicates a websocket channel used to push live device/state changes to the UI instead of relying only on polling.
5. MQTT is the primary device messaging bus. The backend has a dedicated MQTT integration (mqtt.js, mqttManager.js), and the included PDF about firmware/MQTT topics suggests physical devices publish telemetry and subscribe to control topics through this broker-oriented path.
6. Home Assistant is treated as an external interoperability layer. The homeassistant integration includes client, discovery, and mapping modules, which implies the backend can register entities with Home Assistant, translate between internal device models and HA entities, and keep discovery/state in sync.
7. Google Smart Home is exposed as a separate integration route. googleSmartHome.routes.js suggests the backend also supports cloud voice-assistant style control, likely translating Google requests into the same internal device/automation actions used elsewhere.
8. Automations are a first-class subsystem. automationEngine.js, schedulerService.js, and the automation routes indicate the backend can evaluate rules and time-based schedules, then trigger device actions or scene-like behaviors automatically.
9. The frontend is a single-page React app built with Vite. Its component set is centered on home management and control surfaces: devices, rooms, sensors, scenes, staircase control, audio/music, and several modals for adding/configuring entities and provisioning devices.
10. The UI is likely organized around a dashboard with a sidebar and entity cards. Components like DeviceCard, SensorCard, DeviceStatus, Scenes, and the add/configure modals imply the frontend is the operator console for viewing state and issuing commands back to the backend.
11. The “stair case” folder is a separate embedded/local-control subsystem. It contains Arduino firmware (stair_case.ino, motion_sensors.ino) plus a Python led_web_server with templates and static assets, which suggests local motion-sensor input and LED control are handled outside the main Node app, then integrated into the broader smart home system.
12. Data flow is therefore split by responsibility: user interactions go from React to backend routes, backend writes/reads MongoDB, backend emits live updates over websockets, and backend sends commands or consumes telemetry over MQTT and Home Assistant/Google integration boundaries.
13. The most important architectural boundaries to draw are: frontend vs backend API, backend vs persistent database, backend vs external messaging/integration systems (MQTT, Home Assistant, Google Smart Home), and backend vs edge firmware/web server for staircase automation.
14. Overall, this is not just a UI plus API; it is a home-automation hub that normalizes device/room/sensor/automation state in MongoDB, coordinates event-driven device control via MQTT and websockets, and bridges to third-party ecosystems and embedded staircase hardware.
Main entry points: App.jsx UI Shell · smarthome.routes.js Homes · app.js API Host · Device.js Domain
Components 20
Frontend
React/Vite operator dashboard and controls
- UI Shell · Main single-page dashboard entry and layout
frontend/src/App.jsx - Sidebar · Primary app navigation and section switching
frontend/src/components/Sidebar.jsx - Devices · Device cards and status controls
frontend/src/components/DeviceCard.jsx - Rooms · Room management and add-room flow
frontend/src/components/AddRoomModal.jsx - Sensors · Sensor cards and add-sensor flow
frontend/src/components/SensorCard.jsx - Scenes · Scene and automation-facing controls
frontend/src/components/Scenes.jsx - Staircase · Staircase control surface and visualization
frontend/src/components/Staircase.jsx - Music Deck · Audio control and follow-me music interface
frontend/src/components/MusicDeck.jsx
Backend
Node.js API, orchestration, and domain modules
- API Host · Backend entrypoint and application composition
backend/src/app.js - Homes · Home-level controller and routes
backend/src/modules/homes/smarthome.routes.js - Domain · Room, device, sensor, and automation modules
backend/src/modules/devices/Device.js - Automations · Automation rules, scheduler, and triggers
backend/src/modules/automations/automationEngine.js - WebSocket · Live state updates to connected clients
backend/src/core/websocket/socketService.js - MongoDB · Database access and storage boundary
backend/src/infrastructure/mongodb/db.js
Integrations
External messaging and ecosystem bridges
- MQTT · Broker integration for telemetry and commands
backend/src/integrations/mqtt/mqttManager.js - Home Assistant · Client, discovery, and entity mapping bridge
backend/src/integrations/homeassistant/ha-mapper.js - Google Smart Home · Cloud smart-home request route
backend/src/integrations/google/googleSmartHome.routes.js
Staircase Edge
Embedded firmware and local Python control service
- Firmware · Staircase firmware for motion and LED control
stair case/stair_case.ino - Motion Sensors · Local motion sensor firmware module
stair case/motion_sensors/motion_sensors.ino - LED Web Server · Local web UI and control service for staircase LEDs
stair case/led_web_server/app.py
Connections 28
- UI Shell → Sidebar: uses · App shell renders navigation
- UI Shell → Devices: shows · Dashboard includes device controls
- UI Shell → Rooms: shows · Dashboard includes room management
- UI Shell → Sensors: shows · Dashboard includes sensor views
- UI Shell → Scenes: shows · Dashboard includes scene controls
- UI Shell → Staircase: shows · Dashboard includes staircase controls
- UI Shell → Music Deck: shows · Dashboard includes audio controls
- Devices → Homes: api · Device actions and state flow through backend routes
- Rooms → Homes: api · Room management calls backend routes
- Sensors → Homes: api · Sensor management calls backend routes
- Scenes → Automations: api · Scene and automation UI drive backend rules
- Staircase → LED Web Server: local control · Staircase UI may coordinate with the local web service
- API Host → Homes: routes · Application mounts home-level API
- API Host → Domain: modules · Application composes core domain modules
- API Host → Automations: modules · Application composes automation subsystem
- API Host → WebSocket: push · Application exposes websocket updates
- API Host → MongoDB: persistence · Application uses MongoDB boundary
- Domain → MongoDB: read/write · Domain state is persisted in MongoDB
- Automations → Domain: triggers · Automation engine acts on devices, rooms, and sensors
- WebSocket → UI Shell: updates · Live state changes are pushed to the UI
- Homes → MQTT: commands · Home actions can be translated to MQTT device commands
- Domain → MQTT: telemetry · Device state and sensor updates flow over MQTT
- Domain → Home Assistant: sync · Internal entities are mapped to Home Assistant
- Homes → Google Smart Home: voice · Smart-home requests arrive through Google integration
- Automations → MQTT: actuate · Automations can emit device commands on MQTT
- Firmware → Motion Sensors: reads · Firmware consumes motion sensing input
- Motion Sensors → LED Web Server: signals · Local sensor events can be surfaced to the Python service
- LED Web Server → MQTT: bridge · Edge service can bridge staircase events into the main device bus