Smart Enviro Backend is a Laravel REST API purpose-built for IoT smart environmental monitoring. It acts as the central hub between ESP32 microcontrollers deployed in the field and the mobile or web clients that observe and control them. On every sync cycle the ESP32 devices POST their sensor readings to the API, which persists the telemetry in MySQL and immediately returns any queued actuator commands — keeping physical hardware in sync with user intent without requiring a persistent connection. Laravel Sanctum secures all user-facing endpoints with single-session API tokens, while a separate device-token mechanism allows embedded firmware to authenticate without a full user identity.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/GaelCeballos/Smart_Enviro_Backend/llms.txt
Use this file to discover all available pages before exploring further.
Key Features
Authentication
Laravel Sanctum issues single-session API tokens for user accounts. Only one active token is maintained per user; logging in revokes all previous tokens.
Device Sync
ESP32 devices call a public
/api/device/sync endpoint to deliver the latest sensor readings and receive actuator commands in a single bidirectional exchange.Sensor Telemetry
Sensor readings are ingested through the
sensor-data resource routes and authenticated via device token, decoupling hardware identity from user accounts.Actuator Control
Each device exposes an ON / OFF / STANDBY state. Mobile clients toggle state via
/api/my-devices/{id}/toggle; the new state is delivered to firmware on the next sync.Device Discovery
Users browse unclaimed devices through
/api/devices/available and claim ownership via /api/devices/{id}/add, enabling a zero-configuration onboarding workflow.Historical Data
The
/api/sensor-data/history endpoint returns aggregated telemetry that can be bucketed by hour, day, or month for trend analysis in dashboards.Tech Stack
| Layer | Technology |
|---|---|
| Backend | PHP 8.4 + Laravel 13 |
| Authentication | Laravel Sanctum (API Tokens) |
| Database | MySQL 8.x |
| Cache / Queues | Redis 7.x |
| Infrastructure | Docker + Laravel Sail |
Branch Strategy
| Branch | Purpose |
|---|---|
main | Production — 100 % stable code |
staging | QA / Pre-production validation |
develop | Continuous integration base |
feature/* | New feature development |
bugfix/* | Non-critical bug fixes |
hotfix/* | Urgent production fixes |
develop → staging → main to ensure every change is integration-tested and QA-validated before reaching production.
Code Quality
| Tool | Purpose |
|---|---|
| Laravel Pint | Automatic code formatting — enforces consistent style across the codebase. |
| PHPStan (Larastan) | Static type analysis — catches structural errors and type mismatches without running the app. |
| Pest | Automated API tests — covers feature and unit scenarios before any pull request is merged. |
Where to Go Next
Quickstart
Clone the repo, spin up Docker, run migrations, and make your first authenticated API call in under 10 minutes.
Architecture
Understand how requests flow from ESP32 firmware through the API to the database and back to mobile clients.