Skip to content

About

leafcloud_server is a Python-based backend service built with FastAPI, PostgreSQL, and SQLAlchemy for the LEAFCLOUD IoT hydroponic monitoring system.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

LeafCloud Server V2

LeafCloud Server V2 is a robust, scalable backend built with FastAPI, PostgreSQL, and SQLAlchemy. It features a secure JWT-based authentication system and automated network discovery using Zeroconf (mDNS).

The project is architected following SOLID principles and modular layered patterns to ensure high maintainability and developer productivity.

🚀 Key Features

  • Modular Architecture: Layered separation of concerns (Core, API, Models, Schemas, Services).
  • Secure Authentication: JWT-based auth with Bcrypt password hashing.
  • Service Discovery: Automatic mDNS broadcasting for easy local network discovery.
  • Database Migrations: Systematic schema management using Alembic.
  • Environment Management: Type-safe configuration via pydantic-settings.

🛠 Quick Start

1. Prerequisites

  • Python 3.8+
  • PostgreSQL
  • A virtual environment (recommended)

2. Installation

git clone <repository-url>
cd mimeng_leafcloud_server_v2
pip install -r requirements.txt

3. Environment Setup

Copy the template and fill in your local database credentials:

cp .env.example .env

4. Database Migration

Update your PostgreSQL database to the latest schema:

export PYTHONPATH=$PYTHONPATH:.
alembic upgrade head

Common Migration Commands:

  • Apply migrations: export PYTHONPATH=$PYTHONPATH:. && alembic upgrade head
  • Create new migration: export PYTHONPATH=$PYTHONPATH:. && alembic revision --autogenerate -m "description"
  • Check current version: export PYTHONPATH=$PYTHONPATH:. && alembic current
  • View history: export PYTHONPATH=$PYTHONPATH:. && alembic history

5. Start the Server

uvicorn app.main:app --reload

The API will be available at http://localhost:8000 and the interactive docs at http://localhost:8000/docs.


📖 Documentation Index

For detailed guides, please refer to our documentation pages:

  1. Authentication System - Details on JWT and Login logic.
  2. Database Setup - Guide on PostgreSQL configuration.
  3. Migrations (Alembic) - How to manage schema changes.
  4. Network Discovery - Details on Zeroconf/mDNS implementation.
  5. Developer Guide - Start here for architecture and contribution workflows.
  6. Daily Readings Model - Details on the sensor data schema.
  7. Raw Daily Readings - Details on the raw sensor data collection.
  8. Experiments Model - Details on the experimental configuration schema.
  9. Image Crops - Details on the segmented plant images used for AI.
  10. NPK Predictions - Details on the numerical AI estimation outputs.
  11. Image Crop Progress - Task tracking for image processing.
  12. Image Processing Logic - Details on segmentation and greenness filtering.
  13. Tank Configuration - Dynamic system settings and fertilizer profiles.
  14. Mobile API Integration - How to connect your mobile app to the config API.
  15. IoT Pi Integration - How to upload data from a Raspberry Pi.
  16. Monitoring Dashboard - The data aggregation API for the farmer's UI.
  17. Static Image Serving - How uploaded plant images are served statically.
  18. History API - Accessing historical sensor and reading data.
  19. Alert Polling - Real-time client polling for system status alerts.
  20. Multi-task AI Model - Deep learning architecture details for nutrient predictions.
  21. Full-stack AI Integration - Pipeline integrating sensor reading and inference.
  22. Message Definitions - Dynamic alert and system notification definitions.
  23. Sensor Calibration - Device calibration settings and workflows.
  24. EC Calibration Math - Underlying mathematical models for EC calibration.
  25. Calibration API - Endpoint schema and controllers for sensor calibration.
  26. How Estimation Works - Logic and algorithms behind soil/plant estimation.
  27. Nutrient Classifier Training - Training procedures and summary of the ML classifier.
  28. Camera Streaming & Terminal Visualization - How to stream video and view it in a terminal or GUI.
  29. Upload Interval Configuration - Dynamic upload cooldown configuration and API schemas.
  30. Dashboard Code Explanation - Line-by-line code explanation for the monitoring dashboard endpoint.
  31. Model Evaluation (V3 vs V4) - Comparative analysis of V3 and V4 machine learning model performance.
  32. Database Schema - Details on the tables, columns, and relationships in the PostgreSQL database.
  33. Authentication Gaps - Analysis of missing authentication and authorization features in the current V2 server.
  34. Role-Based Access Control (RBAC) - Details on the implemented role-based authorization system.
  35. Token Lifecycle Management - Details on the access/refresh token dual lifecycle and logout blacklist.
  36. Account Lifecycle Management - Details on the account verification, password updates, and forgot/reset password flows.
  37. Model V6 Evaluation & V7 Plan - Detailed analysis of V6 performance under continuous targets and the V7 architecture plan.
  38. Model V7 Evaluation & V8 Plan - Detailed analysis of V7 performance under time targets, backpropagation leaks, and the V8 architecture plan.
  39. Model V8 Evaluation & V9 Plan - Detailed analysis of V8 performance under time targets, custom serialization, and the V9 architecture plan.
  40. Model V9 Evaluation & V10 Plan - Detailed analysis of V9 performance, shared feature contamination, and the V10 architecture plan.
  41. Model V10 Evaluation & V11 Plan - Detailed analysis of V10 performance, feature capacity bottleneck, and the V11 architecture plan.
  42. Model V11 Evaluation - Detailed analysis of V11 Independent Dual-Fusion performance.
  43. Capstone Project Document Updates - Guidelines and tables to update the thesis document with V11 model results.
  44. Model Evolution History (V1 to V11) - Comprehensive history of the AI model design iterations, technical bottlenecks, and architectural resolutions.
  45. Conceptual Framework Guide (V11) - Guide to update Section 3.2 (Conceptual Framework) of the Capstone thesis matching the V11 model's Input-Process-Output flow.
  46. Manual Zeroconf Testing - Reference guide for manually registering, browsing, and troubleshooting local mDNS service records using the dns-sd command-line tool.

🧪 Verification Tools

  • Verify Discovery: python scripts/verify-zeroconf.py
  • Verify RBAC: python scripts/verify_rbac.py
  • Verify Token Lifecycle: python scripts/verify_token_lifecycle.py
  • Verify Account Lifecycle: python scripts/verify_account_lifecycle.py
  • Process Images: python scripts/image_processor.py
  • Seed Predictions: python scripts/seed_predictions.py
  • Run SQL Queries: ./scripts/run-query.sh "SELECT * FROM users;"

About

leafcloud_server is a Python-based backend service built with FastAPI, PostgreSQL, and SQLAlchemy for the LEAFCLOUD IoT hydroponic monitoring system.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages