Skip to main content

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.

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.

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

LayerTechnology
BackendPHP 8.4 + Laravel 13
AuthenticationLaravel Sanctum (API Tokens)
DatabaseMySQL 8.x
Cache / QueuesRedis 7.x
InfrastructureDocker + Laravel Sail

Branch Strategy

BranchPurpose
mainProduction — 100 % stable code
stagingQA / Pre-production validation
developContinuous integration base
feature/*New feature development
bugfix/*Non-critical bug fixes
hotfix/*Urgent production fixes
All work flows through developstagingmain to ensure every change is integration-tested and QA-validated before reaching production.

Code Quality

ToolPurpose
Laravel PintAutomatic code formatting — enforces consistent style across the codebase.
PHPStan (Larastan)Static type analysis — catches structural errors and type mismatches without running the app.
PestAutomated API tests — covers feature and unit scenarios before any pull request is merged.
Running Pint and the Pest suite before opening a pull request is strongly recommended.

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.

Build docs developers (and LLMs) love