Skip to content

Repository files navigation

🌱 ARDHI

Smart Agricultural Intelligence Platform

P.O.T.S – People Of The Soil
Esprit School of Engineering – Class 4DS9 | Academic Year 2025–2026


📖 Project Overview

ARDHI is an AI-powered agricultural management platform developed by P.O.T.S (People Of The Soil) as part of the Data Science Project at Esprit School of Engineering – Tunisia (4th Year Data Science Engineering Program, Academic Year 2025–2026).

The platform is built as a cooperative three-tier architecture:

  • 🎯 Node.js backend for authentication, farm management, and request orchestration
  • 🤖 Python FastAPI AI service for model inference and agronomy recommendations
  • 📱 Flutter mobile app for farmers to interact with the system on mobile devices

The project follows the Team Data Science Process (TDSP) methodology to ensure a structured, reproducible, and scalable AI lifecycle within the AGRISMART initiative.


🏗️ High-Level Architecture

flowchart TD
  Mobile[📱 Flutter Mobile App]
  Backend[🎯 Node.js / Express Backend]
  AI[🤖 Python FastAPI AI Service]
  Storage[(📄 postgresql + model files)]

  Mobile -->|HTTP / JWT| Backend
  Mobile -->|HTTP fallback| AI
  Backend -->|AI proxy calls| AI
  Backend -->|JSON file storage| Storage
  AI -->|model inference| Storage
Loading

Architecture Flow: The mobile app communicates primarily with the Node.js backend, which forwards AI-heavy requests to the Python service. Some flows include direct fallback calls from mobile to AI service for resilience.


🎯 Business & Data Science Objectives

Business Objectives (BOs)

ID Objective Status Implementation
BO1 Fertilizer Optimization – Reduce excessive usage while improving productivity Implemented Nutrient-based recommendation engine
BO2 Irrigation Scheduling – Optimize water usage based on soil, weather, crop stages Implemented Tabular neural model for planning
BO3 Crop Disease Detection – Early detection from leaf images Implemented EfficientNet-B0 + PyTorch classifier
BO4 Livestock Health Monitoring – Multi-species behavior and health tracking Implemented Real-time WebSocket + MJPEG streaming

Data Science Objectives (DSOs)

  • DSO1: Fertilizer dose prediction using soil features (N, P, K, pH, EC) via tabular ML models
  • DSO2: Irrigation need estimation using neural networks trained on region, crop, and climate data
  • DSO3: Multi-class crop disease classification using EfficientNet-B0 fine-tuned with PyTorch
  • DSO4: Multi-species livestock monitoring pipeline combining detection, confidence scoring, and real-time tracking

⚙️ Tech Stack

🤖 AI & Data Science

  • Python – Core language for AI service
  • FastAPI – REST API framework for model serving
  • PyTorch – Deep learning framework (EfficientNet-B0 for disease detection)
  • Scikit-learn / Joblib – Model serialization and tabular ML pipelines
  • Custom tabular neural models – Irrigation planning architecture
  • WebSocket + MJPEG – Real-time livestock monitoring and video streaming

🎯 Backend

  • Node.js / Express – REST API, authentication, farm management, AI proxy
  • JWT (JSON Web Tokens) – Stateless authentication
  • Multer – Image upload handling and temporary storage
  • Axios + FormData – Multipart request forwarding to AI service
  • bcryptjs – Secure password hashing

📱 Mobile

  • Flutter – Cross-platform mobile application (iOS / Android)
  • SharedPreferences – Token and locale persistence
  • Provider pattern – Centralized state management
  • Multi-language support – Arabic (Tunisia), French, English

💾 Storage

  • JSON flat file (backend/data/users.json) – User profiles and farm data
  • Serialized model artifacts – Joblib and PyTorch files under ai_service/

📂 Repository Structure

ARDHI/
├── 🎯 backend/                    # Node.js / Express API
│   ├── server.js                  # Entry point & app configuration
│   ├── routes/                    # API routes (auth, farms, predict, irrigation, livestock)
│   │   ├── auth.js               # Authentication endpoints
│   │   ├── farms.js              # Farm management
│   │   ├── predict.js            # Disease prediction proxy
│   │   ├── irrigation.js         # Irrigation planning
│   │   └── livestock.js          # Livestock analysis
│   ├── controllers/              # Business logic per domain
│   ├── services/                 # AI proxy, farm intelligence, user store
│   ├── middleware/               # JWT auth, Multer upload
│   └── data/users.json           # Flat file storage (no database required)
│
├── 🤖 ai_service/                 # Python FastAPI AI service
│   ├── app.py                    # FastAPI entry point & route registration
│   ├── model_loader.py           # EfficientNet-B0 disease model loader
│   ├── disease_info.py           # Human-readable disease descriptions
│   ├── fertilizer_engine.py      # Fertilizer recommendation logic
│   ├── irrigation_engine.py      # Irrigation planning logic
│   ├── livestock_engine.py       # Multi-species livestock analysis
│   ├── realtime_engine.py        # WebSocket and MJPEG streaming
│   ├── fertelizer models/        # Serialized fertilizer model artifacts
│   ├── irrigation_model/         # Tabular neural model for irrigation
│   └── models/                   # Livestock detection model files
│
└── 📱 mobile/                     # Flutter application
    └── lib/
        ├── main.dart              # App entry point & configuration
        ├── state/app_state.dart   # Global state management
        ├── screens/               # UI screens (auth, dashboard, result, etc.)
        ├── services/              # API services (auth_service, api_service)
        ├── theme/app_theme.dart   # Visual identity & theming
        └── l10n/app_strings.dart  # Localization support

🚀 Features & Capabilities

🌿 Plant Disease Detection

  • Upload leaf images from mobile app
  • EfficientNet-B0 classifies diseases with confidence scores
  • Returns top predictions, localized descriptions, and treatment guidance
  • Supports multiple crop types with human-readable disease information

💧 Smart Irrigation Planning

  • Input: region, crop type, prediction date, farm size
  • Output: structured irrigation schedule with dosage and timing
  • Powered by tabular neural model with preprocessing artifacts
  • Region-aware recommendations with seasonal adjustments

🧪 Fertilizer Recommendation

  • Input: soil nutrient profile (N, P, K, pH, EC, and more)
  • Output: recommendation summary, nutrient deltas, dosage, and warnings
  • Multiple fertilizer options with regional metadata
  • Cost-effective optimization while maintaining crop health

🐄 Livestock Monitoring

  • Static analysis: Multi-species or single-species detection from images
  • Real-time monitoring: WebSocket streams with base64-encoded frames
  • MJPEG streaming: Browser-compatible video display
  • Outputs: Species count, comfort scoring, behavioral alerts, health recommendations

🌾 Farm Management

  • Create, update, and manage multiple farms
  • Automated soil profile analysis and crop intelligence
  • Farm catalog with templates and derived agricultural insights
  • Integration with all AI services for comprehensive farm optimization

📊 Main Data Flows

Plant Diagnostics Workflow

  1. 📱 User Upload: Farmer captures and uploads leaf image via Flutter app
  2. 🎯 Backend Processing: Node.js receives image, stores temporarily via Multer
  3. 🤖 AI Analysis: Backend forwards image to FastAPI disease endpoint
  4. 🧠 Model Inference: EfficientNet-B0 processes image, returns prediction + confidence
  5. 📱 Result Display: Flutter renders detailed result screen with treatments

Irrigation Planning Workflow

  1. 📝 Input Collection: User provides region, crop type, farm size via mobile
  2. 🎯 Request Processing: Backend or mobile sends request to AI service
  3. 🤖 Plan Generation: Tabular neural model generates irrigation schedule
  4. 📊 Result Rendering: UI displays schedule, dosage guidance, and warnings

Authentication Flow

  1. 🔐 Credentials: User signs up or logs in from mobile app
  2. ✅ Validation: Backend validates against users.json storage
  3. 🎫 Token Generation: Signed JWT returned and stored in SharedPreferences
  4. 🔒 Authorized Requests: All subsequent requests include token in Authorization header

🛠️ Getting Started

Prerequisites

  • Node.js ≥ 18.x
  • Python ≥ 3.9
  • Flutter SDK ≥ 3.x
  • Git

Installation Steps

1. Clone the Repository

git clone https://github.com/chamseddinedoulaEsprit/Esprit-PI-4DS9-2526-ARDHI.git
cd Esprit-PI-4DS9-2526-ARDHI

2. Start the AI Service (Port 8000)

cd ai_service
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn app:app --host 0.0.0.0 --port 8000 --reload

3. Start the Backend (Port 3000)

cd backend
npm install
cp .env.example .env  # Configure AI_SERVICE_URL and JWT_SECRET
node server.js

4. Run the Mobile App

cd mobile
flutter pub get
flutter run

Default Configuration

Service Port URL
Node.js Backend 3000 http://localhost:3000
FastAPI AI Service 8000 http://localhost:8000

📚 API Reference

Backend Endpoints (Node.js – Port 3000)

Method Route Description Auth Required
GET /api/health Health check
POST /api/auth/signup Create new user account
POST /api/auth/login Login and receive JWT token
GET /api/auth/me Get authenticated user profile
PUT /api/auth/profile Update user profile fields
GET /api/farms List user's farms
POST /api/farms Create a new farm
PUT /api/farms/:farmId Update existing farm
POST /api/farms/:farmId/refresh Regenerate farm automation
POST /api/predict Disease prediction (image upload)
GET /api/irrigation/options Get irrigation input options
POST /api/irrigation/plan Generate irrigation plan

AI Service Endpoints (FastAPI – Port 8000)

Method Route Description
GET /health AI service health check
POST /predict Plant disease prediction from image
POST /fertilizer/recommend Soil-based fertilizer recommendation
POST /irrigation/plan Irrigation planning and scheduling
POST /livestock/analyze Multi-species livestock analysis
GET /livestock/realtime/status Real-time monitoring status
GET /livestock/realtime/{species}/summary Species-specific monitoring summary
POST /livestock/realtime/{species}/reset Reset tracking state
WS /livestock/realtime/{species}/{session_id} WebSocket real-time stream
GET /livestock/camera-stream/{species} MJPEG video stream

📈 TDSP Methodology Implementation

The project strictly follows the Team Data Science Process structured lifecycle:

1. Business Understanding

  • ✅ Defined clear BOs (BO1-BO4) aligned with AGRISMART initiative
  • ✅ Established measurable DSOs with specific technical targets
  • ✅ Identified stakeholder needs (farmers, agricultural advisors)

2. Data Acquisition & Understanding

  • ✅ Collected diverse datasets: soil profiles, weather data, crop images, livestock videos
  • ✅ Performed comprehensive EDA in Jupyter notebooks
  • ✅ Validated data quality and preprocessing pipelines

3. Modeling

  • ✅ Trained and evaluated multiple model architectures per business objective
  • ✅ Implemented EfficientNet-B0 for disease classification
  • ✅ Developed tabular neural networks for irrigation planning
  • ✅ Created multi-species detection pipelines for livestock monitoring

4. Deployment

  • ✅ Packaged models using Joblib and PyTorch serialization
  • ✅ Deployed via FastAPI microservice architecture
  • ✅ Integrated with Node.js backend and Flutter mobile application
  • ✅ Implemented real-time monitoring capabilities

👥 Team P.O.T.S – People Of The Soil

Class: 4DS9 | Academic Year: 2025–2026

Name Role Responsibilities
Adam Marghli Project Leader Overall project coordination, stakeholder management
Chamseddine Doula Project Manager TDSP implementation, timeline management, deliverables
Chaima Ben Farhat Solution Architect System architecture, technology stack decisions
Najd Rahmani Data Scientist ML/DL model development, irrigation & fertilizer engines
Jihed Hamila Data Scientist Disease detection, livestock monitoring, model optimization
Fatma Ezzahra Charfi Solution Architect Mobile app architecture, API design, integration

🏫 Academic Context

Institution: Esprit School of Engineering – Tunisia
Program: 4th Year Data Science Engineering (4DS9)
Academic Year: 2025–2026
Project Type: Data Science Project – AGRISMART Initiative
Methodology: Team Data Science Process (TDSP)


🔧 Technical Notes

Important Architecture Decisions:

  • No database server required: All user and farm data stored in backend/data/users.json for development agility
  • Lazy model loading: Heavy Python models loaded only when needed to optimize startup times
  • Fallback architecture: Mobile app can communicate directly with AI service if backend is unavailable
  • Multi-language support: Full localization for Arabic (Tunisia), French, and English
  • Real-time capabilities: WebSocket and MJPEG streaming for livestock monitoring

Development Environment:

  • Backend temporary uploads are automatically cleaned after processing
  • Mobile app configured with fallback URLs for various development scenarios
  • Cross-platform compatibility ensured for Android, iOS, and web deployment

📄 License

This project is developed for academic purposes at Esprit School of Engineering under the supervision of the Data Science faculty. All rights reserved to the academic institution and the P.O.T.S development team.


🙏 Acknowledgments

We extend our sincere gratitude to:

  • Esprit School of Engineering faculty for their continuous academic supervision
  • Data Science Department for providing the TDSP framework and methodology guidance
  • AGRISMART Initiative coordinators for the opportunity to contribute to agricultural innovation
  • Our academic supervisors for their invaluable feedback throughout the development lifecycle

🌱 ARDHI – Cultivating the Future of Smart Agriculture 🌱

Developed with ❤️ by P.O.T.S – People Of The Soil

About

This project was developed as part of the 4th Year Data Science Engineering Program at Esprit School of Engineering (Academic Year 2025–2026). It integrates Artificial Intelligence and Machine Learning models developed in Python, a Flutter-based mobile application, and a web platform built with Node.js and React.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages