A modern backend API built with Express.js and Sequelize, designed for collecting, analyzing, and retrieving sensor data from IoT devices like ESP32 units.
🚀 Live API: https://backend-belz.onrender.com
📘 Swagger Docs: https://backend-belz.onrender.com/api-docs
📄 Swagger JSON:
https://backend-belz.onrender.com/swagger.json
[ Hardware Device(s) ]
|
Sends JSON via HTTP / MQTT
|
v
[ Express.js API Server ]
|
┌─────────────┴──────────────┐
| |
[ Middleware Layer ] [ Route Handlers ]
(Auth, Validation, etc.) (auth, data, stats)
|
┌────────┴────────┐
| |
[ Controllers Services ]
| |
└───[ Sequelize ORM ]────┐
|
[ PostgreSQL ]
|
Sensor Data, Users, Stats Tables
|
|
v
┌──────────────────────────┐
| JWT |
└──────────────────────────┘
|
Serves to Frontends
┌────────Consumes API ( Fetch )────┐
| |
[ Web Frontend ] [ Mobile App ]
(React) (React Native)****
Clone the repo and install dependencies:
git clone https://github.com/chas-challenge-code-6/backend
cd backend
npm install
npm run devcd backend
npm install
npm run devBackend will be available at: http://localhost:3000
POST /auth/register{
"username": "testuser",
"password": "test1234",
"email": "test@example.com"
}POST /auth/loginReturns a JWT token.
GET /auth/me- View profilePATCH /auth/me- Update profileDELETE /auth/me- Delete accountPOST /auth/logout- Logout (handled client-side)
POST /auth/forgot-password– Send reset emailPOST /auth/reset-password– Reset using token
All routes require a valid JWT token.
POST /api/data{
"device_id": "ESP32-001",
"sensors": {
"gas": { "ppm": 400 },
"temperature": 22.5,
"humidity": 45,
"fall_detected": false,
"heart_rate": 75,
"noise_level": 80,
"steps": 1000,
"device_battery": 85,
"strap_battery": 100
}
}GET /api/data/latestGET /api/data/:device_id?from=...&to=...GET /api/alertsDetects gas > 1000 ppm, fall detection, noise > 100 dB
GET /stats/summaryReturns:
- Total entries
- Device count
- Averages for temperature, humidity, etc.
⚠️ .envfile is public in this repo intentionally for educational purposes.
⚠️ Production apps should never expose secrets or config like this. Uses Render PostgreSQL as the cloud database.
You can explore and test the API using the following tools:
- 🔗 Swagger UI – Interactive API documentation
- 📄 Swagger JSON – Raw OpenAPI spec
- 🧪 Use tools like Thunder Client or Postman to make authenticated requests
- 🧼 Automated tests are available via Jest
npm test