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.
- 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.
- Python 3.8+
- PostgreSQL
- A virtual environment (recommended)
git clone <repository-url>
cd mimeng_leafcloud_server_v2
pip install -r requirements.txtCopy the template and fill in your local database credentials:
cp .env.example .envUpdate your PostgreSQL database to the latest schema:
export PYTHONPATH=$PYTHONPATH:.
alembic upgrade head- 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
uvicorn app.main:app --reloadThe API will be available at http://localhost:8000 and the interactive docs at http://localhost:8000/docs.
For detailed guides, please refer to our documentation pages:
- Authentication System - Details on JWT and Login logic.
- Database Setup - Guide on PostgreSQL configuration.
- Migrations (Alembic) - How to manage schema changes.
- Network Discovery - Details on Zeroconf/mDNS implementation.
- Developer Guide - Start here for architecture and contribution workflows.
- Daily Readings Model - Details on the sensor data schema.
- Raw Daily Readings - Details on the raw sensor data collection.
- Experiments Model - Details on the experimental configuration schema.
- Image Crops - Details on the segmented plant images used for AI.
- NPK Predictions - Details on the numerical AI estimation outputs.
- Image Crop Progress - Task tracking for image processing.
- Image Processing Logic - Details on segmentation and greenness filtering.
- Tank Configuration - Dynamic system settings and fertilizer profiles.
- Mobile API Integration - How to connect your mobile app to the config API.
- IoT Pi Integration - How to upload data from a Raspberry Pi.
- Monitoring Dashboard - The data aggregation API for the farmer's UI.
- Static Image Serving - How uploaded plant images are served statically.
- History API - Accessing historical sensor and reading data.
- Alert Polling - Real-time client polling for system status alerts.
- Multi-task AI Model - Deep learning architecture details for nutrient predictions.
- Full-stack AI Integration - Pipeline integrating sensor reading and inference.
- Message Definitions - Dynamic alert and system notification definitions.
- Sensor Calibration - Device calibration settings and workflows.
- EC Calibration Math - Underlying mathematical models for EC calibration.
- Calibration API - Endpoint schema and controllers for sensor calibration.
- How Estimation Works - Logic and algorithms behind soil/plant estimation.
- Nutrient Classifier Training - Training procedures and summary of the ML classifier.
- Camera Streaming & Terminal Visualization - How to stream video and view it in a terminal or GUI.
- Upload Interval Configuration - Dynamic upload cooldown configuration and API schemas.
- Dashboard Code Explanation - Line-by-line code explanation for the monitoring dashboard endpoint.
- Model Evaluation (V3 vs V4) - Comparative analysis of V3 and V4 machine learning model performance.
- Database Schema - Details on the tables, columns, and relationships in the PostgreSQL database.
- Authentication Gaps - Analysis of missing authentication and authorization features in the current V2 server.
- Role-Based Access Control (RBAC) - Details on the implemented role-based authorization system.
- Token Lifecycle Management - Details on the access/refresh token dual lifecycle and logout blacklist.
- Account Lifecycle Management - Details on the account verification, password updates, and forgot/reset password flows.
- Model V6 Evaluation & V7 Plan - Detailed analysis of V6 performance under continuous targets and the V7 architecture plan.
- Model V7 Evaluation & V8 Plan - Detailed analysis of V7 performance under time targets, backpropagation leaks, and the V8 architecture plan.
- Model V8 Evaluation & V9 Plan - Detailed analysis of V8 performance under time targets, custom serialization, and the V9 architecture plan.
- Model V9 Evaluation & V10 Plan - Detailed analysis of V9 performance, shared feature contamination, and the V10 architecture plan.
- Model V10 Evaluation & V11 Plan - Detailed analysis of V10 performance, feature capacity bottleneck, and the V11 architecture plan.
- Model V11 Evaluation - Detailed analysis of V11 Independent Dual-Fusion performance.
- Capstone Project Document Updates - Guidelines and tables to update the thesis document with V11 model results.
- Model Evolution History (V1 to V11) - Comprehensive history of the AI model design iterations, technical bottlenecks, and architectural resolutions.
- 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.
- Manual Zeroconf Testing - Reference guide for manually registering, browsing, and troubleshooting local mDNS service records using the
dns-sdcommand-line tool.
- 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;"