How nam077/smart-home works
Core System Components
• NestJS Backend Server
• MQTT Broker (Aedes)
• PostgreSQL Database
• Authentication System (JWT)
• WebSocket Server
• IoT Devices Layer
Module Organization
• Auth Module
• Device Module
• Room Module
• User Module
• MQTT Module
• Controller Module
• Voice Controller Module
Communication Flows
Distinct communication patterns:
• REST API calls (HTTP/HTTPS)
• MQTT message flows
• WebSocket connections
• Database interactions
Top Level (Client Layer)
• ┌─────────────────────────────────────────┐
• Client Applications │
• (Web Browsers, Mobile Apps, IoT Devices)│
• ┘
Communication Layer
• ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
• REST API │ │ MQTT │ │ WebSocket │
• (Port 3000)│ │ (Port 1883) │ │ (Port 8883) │
• ┘ └─────────────┘ └─────────────┘
Core Application Layer
• ┌─────────────────────────────────────────────────┐
• NestJS Application │
• ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌───────┐ │
• Auth │ │ Device │ │ Room │ │ User │ │
• Module │ │ Module │ │ Module │ │Module │ │
• ┘ └─────────┘ └─────────┘ └───────┘ │
• ┌─────────┐ ┌─────────┐ ┌─────────────────┐ │
• MQTT │ │ Voice │ │ Controller │ │
• Module │ │ Control │ │ Module │ │
• ┘ └─────────┘ └─────────────────┘ │
• ┘
Service Layer
• ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
• Device │ │ MQTT │ │ Auth │
• Services │ │ Services │ │ Services │
• ┘ └─────────────┘ └─────────────┘
Data Layer
• ┌─────────────────────────────────────────┐
• PostgreSQL Database │
• Users | Devices | Rooms | Controllers │
• ┘
• Blue: Client-facing components
• Green: Core application modules
• Yellow: Communication layers
• Purple: Database and storage
• Red: Security components
Important Elements to Highlight:
MQTT Flow
• Topic structure: home/{roomId}/{deviceId}/{type}
• Message types (status/control/data/error)
• Heartbeat monitoring flow
Security Layer
• JWT authentication flow
• MQTT authentication
• API security middleware
Device Management
• Device discovery process
• Status monitoring
• Command routing
Database Relationships
• User-Device relationships
• Room-Device associations
• Controller hierarchies
• Component types
• Security boundaries