The brain behind the Smart Roots ecosystem. A robust C#/.NET backend that connects IoT hardware, MQTT, databases, cloud storage, and the Smart Roots App — with a laser focus on security, performance, and extensibility.
- Project Overview
- Features & External Integrations
- High-Level Architecture & Technology Stack
- Repository & Code Structure
- How to Contribute
- How to Run (Dev & Production)
- Room for Expansion
- License
- Reference Links
Smart Roots Server is a modern, microservices-inspired backend system for smart agriculture and hydroponics automation.
It orchestrates sensor data, image uploads, secure device toggling, real-time event streams, and tent/user management for the broader Smart Roots ecosystem.
It acts as the main API for the Smart Roots App, with an architecture built for IoT scale-out, cloud reliability, and strong data protection.
| Category | Details |
|---|---|
| Tent API | Create, update, delete, fetch, or publicly list tents with full metadata & hashed passwords. |
| Sensor API | Real-time streaming (SSE) from hardware via MQTT; all sensor state changes and control actions exposed as structured endpoints. |
| Device Control | Toggle pumps, fans, lights, extractor fans, EC/pH actuators, etc. through MQTT JSON publishing; validated schemas for actuator state. |
| Image Handling | Accepts Base64 image upload, stores securely in Supabase Storage, exposes public URLs, and provides "latest image" query for tents/devices. |
| Auth/Roles | Uses Supabase JWT and custom logic for login, registration, claims validation, and RBAC (role-based access control). |
| Cloud Storage | All non-relational logs (sensor stream) in MongoDB; tent, image, and config data in Supabase/Postgres/Storage buckets. |
| Extensibility | Fully modular — add more endpoints/controllers/repos/devices without codebase refactor. |
| DevOps Ready | Ship and scale with Docker; robust .dockerignore. Strong, cloud-agnostic configuration. |
- /api/tents
- GET: List all tents (public) or fetch by MAC address.
- POST: Create tent (
TentCreateDto) — secure MAC, password hash, type, etc. - PUT: Update tent info or type (with validation, protected by RBAC).
- DELETE: Remove tent by MAC (secure, role-protected).
- POST
/verify-password: Auth check for tent access.
- /api/sensors
- GET: Live stream sensor reading events (SSE) — tent-filtered or broadcast.
- POST
/toggle: Change state of tent actuators, published via MQTT.
- /api/images
- POST: Upload image (Base64 JPEG); stores in Supabase, returns URL.
- GET: Fetch latest image for a given tent/MAC.
- All tent data is normalized (unique MAC required, validated with regex).
- Password validation/hashing on entry; stored hashed (never plaintext).
- Metadata fields: Name, Location, Country, Organization (for multi-client support), TentType ("veg" or "fodder", for app logic).
- MQTT events for low-latency device reads/toggles.
- SSE for reliable client push (app always sees latest tent/device state).
- Device schema (see
SensorStates.cs) supports all actuator types; new ones easy to extend.
- Images POSTed as Base64, stripped and checked, converted to bytes, and uploaded to Supabase Storage with tent/MAC-based path.
- Public image URLs generated for later use by client apps.
- Always fetches the latest per-tent image.
- Multi-token auth with Supabase: supports both AccessToken and RefreshToken flows, including role extraction for private/protected endpoints.
- Custom RBAC wrappers for each method group to pin allowed roles (future extensibility for finer permissions).
- All passwords hashed server-side using
PasswordHasher.
- Supabase/Postgres: tent metadata, images, configuration.
- Supabase Storage: image blobs — organized per tent/MAC address.
- MongoDB (via official driver): event/sensor logs, analyzable at scale.
- Cloud MQTT (EMQX Cloud): device/control event backbone.
- Ship as container via multi-stage
Dockerfile(builds, publishes, deploys). - Strong configuration:
appsettings.Development.jsonfor all connection strings, cloud endpoints, MQTT broker, etc.- CLI/env overrides supported.
C#/.NET Packages:
MQTTnet(for device integration, MQTT streaming)Supabase.Client,Supabase.Storage,Supabase.Postgrest(typed Postgres/cloud wrappers)MongoDB.Driver(native event/log storage)FluentValidation(robust, declarative DTO and schema validation)Microsoft.AspNetCore& minimal APIs approach (blazing fast endpoint composition)System.Text.Json/System.Text.Encodings.Web(modern, high-performance JSON)ILogger(built-in, structured logging for cloud scale)- and more via NuGet — see csproj for detail.
External Cloud Services:
- Supabase (storage, authentication, Postgres)
- EMQX Cloud (global MQTT broker & provisioning)
- MongoDB Atlas (fully managed sensor/event DB)
| Folder/File | Purpose |
|---|---|
/Routes | API endpoint (Minimal API groupings, e.g., TentRoutes, SensorRoutes, ImageRoutes) |
/Controller.cs | REST controllers for input validation, business orchestration (e.g., SensorController.cs, ImageController.cs) |
/Services | Core cloud connectors, MQTT subscriber/publisher logic, and SupabaseAuthService |
/Infrastructure/Models | Entity/event schemas (sensor logs, tent, actuator states, etc.) |
/Data | Repositories (TentRepository, SupabaseSQLClient, SupabaseStorageContext) |
/Infrastructure/Validation | DTO and input validators leveraging FluentValidation |
appsettings.Development.json | Cloud credentials, secrets, connection strings |
Dockerfile | Dev/prod container build published in multiple stages |
.dockerignore | Ignores build/system settings to speed up Docker context |
- Fork the Repository
- Clone Locally:
git clone https://github.com/Code-Syndicate-SH/Smart-Roots-Server.git - Branch:
git checkout -b <feature-name> - Configure Env/Settings:
- Duplicate
appsettings.Development.jsonand fill in your cloud connection secrets (see example in repo). - Register/test with your own Supabase and MongoDB Atlas projects.
- (Optionally) Use your own MQTT cloud endpoint.
- Duplicate
- Install Dependencies:
- Use .NET 8 SDK:
dotnet restore - NuGet packages: auto-restored from
.csproj
- Use .NET 8 SDK:
- Run Locally:
- Via CLI:
dotnet run - Or via Docker:
docker build -t smart-roots-server .docker run -d -p 8080:8080 smart-roots-server- Pass env vars for cloud credentials or mount updated settings file as needed.
- Via CLI:
- Write & Run Tests
- Add new tests under
/Tests
- Add new tests under
- Open a Pull Request and document your change!
Contributing Guidelines:
- Always validate new DTOs and endpoints with FluentValidation.
- Add appropriate log statements with
ILogger. - Ping @Code-Syndicate-SH for architectural or DB/schema changes.
- Security: Never hardcode/outsource secrets in PRs.
- Pre-Req: .NET 8, Docker (for prod), Supabase, MongoDB, and EMQX accounts (dev keys in
appsettings.*.json). - Dev:
dotnet run - Prod Container Build:
docker build -t smart-roots-server .docker run -d -p 8080:8080 smart-roots-server
- API Docs: Minimal API, well-documented endpoints (see
/Routesor online API docs if available).
- 🧠 AI Inference endpoints (disease, nutrient deficiency)
- 📈 Analytics API (historical logs, event queries)
- 🛡️ Per-tent/per-field RBAC (fine-grained controls)
- 🔔 Webhooks for notifications/3rd party integration
- 💬 Localization for API outputs/errors
This repository is not yet officially open-source licensed.
Contact Code-Syndicate-SH for enterprise partnership, research, or custom cloud deployment.
- Smart-Roots-Server code on GitHub
- See more endpoints/controllers/services (search)
- Supabase Docs
- EMQX Cloud
- MongoDB Atlas
Built with ❤️ by Code-Syndicate-SH for the future of sustainable food.