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.

This guide walks you through cloning the repository, spinning up MySQL 8 and Redis via Laravel Sail (Docker Compose), running database migrations, and making your first authenticated API call. No local PHP or Composer installation is required — everything runs inside containers managed by Sail.
Windows users: Clone the repository and run all commands from inside the WSL2 (Ubuntu) filesystem (e.g. ~/smart_enviro_backend), not from a Windows-mounted path such as /mnt/c/.... Running from a Windows filesystem causes file permission errors that break Laravel’s storage and cache layers.

Prerequisites

1

Docker Desktop

Install Docker Desktop and make sure it is running. Windows users must also enable the WSL2 integration in Docker Desktop → Settings → Resources → WSL Integration.
2

Git

Install Git so you can clone the repository.
3

WSL2 with Ubuntu (Windows only)

Install Ubuntu from the Microsoft Store and configure it as your default WSL2 distribution. Open all subsequent terminal sessions from the Ubuntu shell.

Setup

1

Clone the repository

git clone https://github.com/GaelCeballos/Smart_Enviro_Backend.git && cd Smart_Enviro_Backend
2

Install Composer dependencies

The vendor/ directory is not committed to source control. Use Docker to run Composer without a local PHP installation:
docker run --rm \
  -u "$(id -u):$(id -g)" \
  -v "$(pwd):/var/www/html" \
  -w /var/www/html \
  laravelsail/php84-composer:latest \
  composer install --ignore-platform-reqs
This populates vendor/ and makes the ./vendor/bin/sail command available for all subsequent steps.
3

Copy the environment file

cp .env.example .env
Open .env in your editor and fill in the database credentials before starting containers:
DB_DATABASE=smart_enviro
DB_USERNAME=sail
DB_PASSWORD=password
The DB_CONNECTION defaults to sqlite in .env.example. Change it to mysql and uncomment the DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD lines when using Sail.
4

Start Sail (Docker)

./vendor/bin/sail up -d
This command builds the Sail image and starts three containers in the background:
ServiceDefault port
Laravel application80
MySQL 8.43306
Redis (Alpine)6379
Wait until all containers report a healthy status before proceeding. You can check with ./vendor/bin/sail ps.
5

Generate the application key

./vendor/bin/sail artisan key:generate
This writes a fresh APP_KEY value into your .env file. Laravel uses it to encrypt sessions, cookies, and other signed data.
6

Run database migrations

./vendor/bin/sail artisan migrate
This creates all required tables — users, devices, sensor readings, Sanctum tokens, sessions, and cache — inside the MySQL container.
7

(Optional) Run the test suite

./vendor/bin/sail artisan test
Pest runs the full Feature and Unit test suite against a dedicated testing database. All tests should pass on a clean install.

First API Call

With the stack running, you can register a user and obtain an API token in two requests. Register a new user:
curl -X POST http://localhost/api/register \
  -H "Content-Type: application/json" \
  -d '{"name": "Test User", "email": "[email protected]", "password": "password123", "password_confirmation": "password123"}'
Log in and retrieve a token:
curl -X POST http://localhost/api/login \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]", "password": "password123"}'
A successful login returns a JSON envelope containing the authenticated user and a Sanctum plain-text token:
{
  "status": "success",
  "message": "Inicio de sesión exitoso",
  "data": {
    "user": {
      "id": 1,
      "name": "Test User",
      "email": "[email protected]"
    },
    "token": "1|abc123..."
  }
}
Pass this token in the Authorization header for all subsequent requests to protected endpoints:
curl http://localhost/api/my-devices \
  -H "Authorization: Bearer 1|abc123..."

Next Steps

Authentication

Learn how Sanctum token issuance, single-session enforcement, and logout work.

Devices Overview

Discover how to claim devices, toggle actuator states, and update device properties.

Login Endpoint

Full reference for the /api/login endpoint — request body, responses, and error codes.

Store Sensor Data

Reference for posting ESP32 telemetry to /api/sensor-data using a device token.

Build docs developers (and LLMs) love