Welcome to Invernaderos API
The Invernaderos API is a production-ready IoT greenhouse monitoring system that enables real-time sensor data collection, storage, and analysis for agricultural operations. Built with modern technologies and designed for scalability, it provides a robust platform for monitoring environmental conditions across multiple greenhouses.Quick Start
Get your API running in under 5 minutes with Docker Compose
Architecture
Understand the system design and data flow
API Reference
Explore REST endpoints and authentication
WebSocket
Real-time sensor data streaming
What is Invernaderos API?
Invernaderos API is a multi-tenant IoT platform that receives sensor data from greenhouse devices via MQTT, stores time-series data in TimescaleDB, caches recent readings in Redis for fast access, and broadcasts real-time updates to connected clients via WebSocket/STOMP.Key Features
Multi-Tenant
Isolated Data by TenantComplete data isolation with UUID-based tenant identification. Each agricultural company gets their own secure data space.
MQTT Integration
Industry-Standard IoTBuilt on MQTT protocol with EMQX broker. Topics:
GREENHOUSE/{tenantId} for multi-tenant routing.Time-Series Database
Optimized for Sensor DataTimescaleDB with automatic compression, 2-year retention policy, and continuous aggregates for hourly/daily statistics.
Real-Time WebSocket
Instant UpdatesSTOMP over WebSocket pushes sensor readings to clients instantly. No polling required.
Redis Caching
Lightning FastLast 1000 messages cached in Redis Sorted Set. Response time in milliseconds for recent data queries.
JWT Authentication
Secure AccessBearer token authentication with role-based access control. Password reset via email.
Technology Stack
Spring Boot 3.5.7
Modern Java framework with Jakarta EE 10+
Kotlin 2.2.21
Concise, type-safe language with K2 compiler
Java 21 LTS
Latest LTS with virtual threads and pattern matching
TimescaleDB
PostgreSQL 16 + TimescaleDB for time-series
Redis 7
In-memory cache with Lettuce client
EMQX
Enterprise MQTT broker with WebSocket support
System Architecture Overview
Data Flow
Sensors Publish
Greenhouse IoT devices publish sensor readings to MQTT topic
GREENHOUSE/{tenantId} every 5-10 seconds.MQTT Listener
Spring Integration MQTT adapter receives messages and routes to
GreenhouseDataListener.Processing Pipeline
MqttMessageProcessor processes each message:- Parses JSON payload (22 fields: temperature, humidity, sectors, extractors)
- Caches in Redis Sorted Set (last 1000 messages)
- Transforms to 22
SensorReadingentities (one per field) - Batch inserts to TimescaleDB
- Publishes Spring
ApplicationEvent
WebSocket Broadcast
GreenhouseWebSocketHandler listens to event and broadcasts RealDataDto to all connected clients on /topic/greenhouse/messages.Real-World Sensor Data
The system handles real greenhouse sensor data with 22 fields per message:Data Transformation: One JSON payload (22 fields) → 22 database rows. Each numeric field becomes a separate
SensorReading entity for normalized time-series queries.Multi-Tenant Architecture
The system supports complete tenant isolation with UUID-based tenant IDs:MQTT Topic Structure
- Legacy Format (backward compatible):
GREENHOUSE→ maps totenantId = "DEFAULT" - Multi-Tenant Format:
GREENHOUSE/{tenantId}GREENHOUSE/SARA→ tenantId = “SARA” (Vivero Sara)GREENHOUSE/001→ tenantId = “001”GREENHOUSE/NARANJOS→ tenantId = “NARANJOS” (Los Naranjos farm)
Database Isolation
All tables includetenant_id UUID for filtering:
- PostgreSQL Metadata:
tenants,greenhouses,sensors,actuators,users,alerts - TimescaleDB:
sensor_readingswith indexedtenant_idcolumn - Redis Cache: Keys include tenant context:
greenhouse:messages:{tenantId}
Use Cases
Agricultural Companies
Monitor multiple greenhouses across different locations. Track temperature, humidity, and environmental factors in real-time.
Research Institutions
Collect long-term environmental data for agricultural research. Analyze trends and optimize growing conditions.
IoT Integrators
Build custom dashboards and mobile apps on top of the API. Connect various sensor types and actuators.
Smart Farming
Automate irrigation, ventilation, and climate control based on real-time sensor data and thresholds.
Production Features
Docker Ready
Multi-stage Dockerfile with optimized layers. Complete docker-compose.yaml for local development.
Kubernetes Deployment
Production K8s manifests with StatefulSets, PersistentVolumes, and health checks.
Health Monitoring
Spring Boot Actuator endpoints:
/actuator/health, /actuator/metrics, /actuator/prometheus.OpenAPI Documentation
Interactive Swagger UI at
/swagger-ui.html with try-it-out functionality.Database Migrations
Flyway-managed SQL migrations (V2-V11 executed). Versioned schema changes with checksum validation.
Connection Pooling
HikariCP pools: TimescaleDB (max 20), PostgreSQL (max 10), Redis Lettuce (max 100 connections).
Performance Characteristics
Throughput: Handles 1000+ messages/second with batch insertsLatency: Redis cache responses in 1-5ms, TimescaleDB queries in 10-50msStorage: TimescaleDB compression (7-day policy) reduces storage by ~90%Retention: 2-year data retention with automatic cleanupScaling: Horizontal scaling with multiple API instances behind load balancer
Next Steps
Quick Start
Deploy with Docker in 5 minutes
Architecture
Deep dive into system design
API Docs
Explore endpoints
Built with Spring Boot 3.5.7 • Kotlin 2.2.21 • Java 21 • TimescaleDB • Redis 7 • EMQX