HomePulse Backend is the core of the smart-home platform.
It provides REST API endpoints, MQTT real-time processing, database storage, authentication, device management, and full Swagger documentation.
This backend communicates with ESP32 devices via MQTT and serves the frontend through REST API.
- Real-time IoT device monitoring (MQTT)
- ESP32 sensor data (temperature, humidity, motion, relay, etc.) from MQTT topics
- Full CRUD for Homes, Rooms, Devices
- JWT authentication
- MongoDB + Mongoose models
- REST API with validation
- Swagger API documentation
- Clean modular file structure
backend/
βββ src/
βββ config/
βββ controllers/
βββ middlewares/
βββ models/
βββ routes/
βββ utils/
βββ validators/
βββ db.ts
βββ seed.ts
βββ server.ts
βββ swagger.config.ts
Each folder is responsible for a clean separation of business logic:
- controllers β API logic
- routes β endpoints
- models β Mongoose schemas
- middlewares β validation/auth
- validators β request validation
- utils β helpers
- config β server configuration
After authentication, each user can:
- Create/manage Homes
- Create/manage Rooms
- Add devices to any room
- View real-time device data
Users may create any number of homes.
Home actions:
- β Add Home
- β Delete Home Each home contains multiple rooms.
A room belongs to a home. Users can create unlimited rooms.
Room actions:
- β Add Room
- Upload 3D splat file
- β Delete Room
Rooms act as containers for devices and 3D positioning.
Devices are assigned directly to rooms.
Each device includes:
- Name
- Type
- Assigned room
- Online/offline state
- Live MQTT data
HomePulse uses MQTT as the real-time backbone.
- Device connects to MQTT
- Publishes sensor data
- Backend receives it via MQTT client
- Backend updates MongoDB + broadcasts to frontend
IoT Device β MQTT Broker β Backend β MongoDB β Frontend (3D view)
- Login
- Registration
- Protected routes
- JWT stored securely
- Node.js
- Express
- MongoDB + Mongoose
- MQTT (Mosquitto / EMQX)
- JWT
- Swagger
Extra:
- MongoDB (local or cloud)
- MQTT broker
git clone https://github.com/Home-Pulse-App/backend.git
cd backendnpm install
npm run devYour .env file must include:
PORT=3000
MONGO_URI=mongodb://localhost:27017/homepulse
MQTT_BROKER_URL=mqtt://localhost:1883
MQTT_USERNAME=
MQTT_PASSWORD=
JWT_SECRET=your-secret-key
JWT_EXPIRES_IN=7d
The backend uses Mongoose to handle:
- Users
- Houses
- Rooms
- Devices
- Sensor readings (optional depending on your model)
The backend connects to the broker defined in .env and subscribes to:
homepulse/{deviceId}/data homepulse/{deviceId}/status
The backend provides full Swagger documentation describing all API endpoints:
Whatβs included:
- Full endpoint list
- Request/response schemas
- Validation rules
- JWT authentication documentation
- Error codes
- Example inputs/outputs
Access Swagger UI:
/api/docs
Full list π : http://localhost:3000/api-docs
You can test APIs directly in the browser, explore descriptions, and validate integrations.
npm run test- Jest or Vitest
- Supertest for API routes
The seed script populates the database with mock data.
The mock data is stored in the mockData directory.
The seed script will create:
- 1 user
- 1 house
- 1 room
- 1 splatFile
- 1 device
- 30050 sensor readings
To login use the following credentials:
email: user@email.com password: Secret123!
npm run seed- Docker (recommended)
- PM2 + Node
- Railway / Render / Fly.io
- Raspberry Pi (local server)