How youssefjbeniani/drinksafe works
DrinkSafe lets users configure a sensor-backed device, then monitor live water-quality readings, historical trends, and threshold alerts, with optional persisted history and CSV export. The React dashboard polls the Node API; the API authorizes device access and retrieves data through ThingSpeak, optionally persisting it in PostgreSQL. The graph follows documented routes and sampled calls; some storage, UI, and middleware links rely on the SOURCE INDEX, while broader product capabilities are included where documented.
Main entry points: App.jsx Dashboard app · readings.routes.js Reading routes · app.js Express API · alerts.routes.js Alert routes
Components 30
Dashboard
- Dashboard app
frontend/src/App.jsx - Authentication UI
frontend/src/components/AuthPage.jsx - Device setup UI
frontend/src/components/DeviceSetup.jsx - Dashboard polling
frontend/src/hooks/useDashboardData.js - API client
frontend/src/services/api.js - Reading cards
frontend/src/components/MetricCard.jsx - History charts
frontend/src/components/AnalyticsCharts.jsx - Alerts feed
frontend/src/components/AlertsFeed.jsx - Live status
frontend/src/components/LiveStatus.jsx
API and monitoring
- Express API
backend/src/app.js - API server
backend/src/server.js - Reading routes
backend/src/routes/readings.routes.js - Alert routes
backend/src/routes/alerts.routes.js - Quality classification
backend/src/services/classification.service.js - Sensor data service
backend/src/services/thingspeak.service.js - CSV formatter
backend/src/services/csv.service.js
Identity and devices
- Authentication routes
backend/src/routes/auth.routes.js - Authentication service
backend/src/services/auth.service.js - Session middleware
backend/src/middleware/auth.middleware.js - Device routes
backend/src/routes/devices.routes.js - Device authorization
backend/src/middleware/device.middleware.js - Device repository
backend/src/repositories/device.repository.js - User repository
backend/src/repositories/user.repository.js
Persistence
- Persistence service
backend/src/services/persistence.service.js - Reading repository
backend/src/repositories/reading.repository.js - PostgreSQL pool
backend/src/db/pool.js - PostgreSQL
backend/migrations/001_initial.sql
Other components
- Dashboard user
- ESP32 / Wokwi
- ThingSpeak
Connections 38
- Dashboard user → Dashboard app: uses
README.md - ESP32 / Wokwi → ThingSpeak: publishes readings
README.md - ThingSpeak → Sensor data service: provides feed
README.md - Dashboard app → Authentication UI: renders
frontend/src/App.jsx - Dashboard app → Device setup UI: renders
frontend/src/App.jsx - Dashboard app → Dashboard polling: loads data
frontend/src/App.jsx - Dashboard app → API client: requests devices and export
frontend/src/App.jsx - Dashboard app → Reading cards: renders
frontend/src/App.jsx - Dashboard app → History charts: renders
frontend/src/App.jsx - Dashboard app → Alerts feed: renders
frontend/src/App.jsx - Dashboard app → Live status: renders
frontend/src/App.jsx - Dashboard polling → API client: fetches dashboard data
frontend/src/hooks/useDashboardData.js - API client → Express API: sends API requests
README.md - API server → Express API: starts
backend/src/server.js - Express API → Reading routes: routes readings
backend/src/app.js - Express API → Alert routes: routes alerts
backend/src/app.js - Express API → Authentication routes: routes auth
backend/src/app.js - Express API → Device routes: routes devices
backend/src/app.js - Reading routes → Device authorization: authorizes device
backend/src/routes/readings.routes.js - Alert routes → Device authorization: authorizes device
backend/src/routes/alerts.routes.js - Reading routes → Sensor data service: fetches readings
backend/src/routes/readings.routes.js - Alert routes → Sensor data service: fetches history
backend/src/routes/alerts.routes.js - Reading routes → Quality classification: classifies readings
backend/src/routes/readings.routes.js - Alert routes → Quality classification: uses thresholds
backend/src/routes/alerts.routes.js - Reading routes → Reading repository: loads export data
backend/src/routes/readings.routes.js - Reading routes → CSV formatter: formats CSV
backend/src/routes/readings.routes.js - Sensor data service → Persistence service: persists readings
backend/src/services/thingspeak.service.js - Authentication routes → Authentication service: authenticates users
backend/src/routes/auth.routes.js - Session middleware → Authentication service: verifies session
backend/src/middleware/auth.middleware.js - Authentication routes → Session middleware: checks session
backend/src/routes/auth.routes.js - Device authorization → Device repository: checks ownership
backend/src/middleware/device.middleware.js - Device routes → Device repository: manages devices
backend/src/routes/devices.routes.js - Authentication service → User repository: reads and creates users
backend/src/services/auth.service.js - Persistence service → Reading repository: upserts readings
backend/src/services/persistence.service.js - Device repository → PostgreSQL pool: queries
backend/src/repositories/device.repository.js - Reading repository → PostgreSQL pool: queries
backend/src/repositories/reading.repository.js - User repository → PostgreSQL pool: queries
backend/src/repositories/user.repository.js - PostgreSQL pool → PostgreSQL: connects when enabled
README.md