-
Notifications
You must be signed in to change notification settings - Fork 0
Architecture
This page provides a full overview of the AgriScan architecture β how the mobile app, backend, database, and AI model work together to deliver instant, offline-friendly plant disease detection.
AgriScan is built as a mobile-first AI system that combines local inference, offline persistence, and cloud sync.
The design principles:
- β‘ Speed: Instant on-device predictions (no lag or server wait)
- π Offline-first: Farmers can still scan without internet
- π§© Modularity: Each layer (AI, API, App) can evolve independently
- π Security: Minimal data stored, secure sync via Supabase
ββββββββββββββββββββββββββββββ
β Flutter App β
β - Camera Capture β
β - Offline Hive DB β
β - History & Sync Queue β
β - Treatment UI (Planned) β
ββββββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββ
β FastAPI API β
β - /predict endpoint β
β - /sync (future) β
β - AI model inference β
ββββββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββ
β TensorFlow Model β
β - cassava.tflite β
β - 5 disease classes β
β - Confidence scoring β
ββββββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββ
β Supabase / Postgres β
β - Users, farms, scans β
β - Auth & analytics β
ββββββββββββββββββββββββββββββ
- Cross-platform (Android/iOS) built with Flutter 3.24
- Handles:
- Camera capture (
cameraplugin) - Local storage using Hive
- Offline queueing and sync
- Display of prediction results and history
- Camera capture (
- Planned upgrades:
- SMS alerts for offline notifications
- Multi-crop toggle
- Treatment recommender UI
- Lightweight backend for model inference and data sync
- Runs as a REST API with:
-
/api/v1/predict: Accepts base64 image β returns disease + confidence -
/api/v1/sync(planned): Push/pull logs between mobile and Supabase
-
- Includes:
- Model loading from
models/cassava.tflite - Pillow/OpenCV for preprocessing
- Automated tests via
pytest - Deployed with Docker + Uvicorn
- Model loading from
-
Based on TensorFlow MobileNetV2 architecture
-
Converted from
.h5β.tflitefor mobile performance -
Predicts five cassava leaf disease classes:
- Cassava Bacterial Blight (CBB)
- Cassava Brown Streak Disease (CBSD)
- Cassava Green Mottle (CGM)
- Cassava Mosaic Disease (CMD)
- Healthy Leaf
-
Model files:
models/cassava.tflitemodels/labels.txt
-
Approx. size: 12β15 MB
-
Runtime: TensorFlow Lite + NumPy + Pillow
- Supabase (PostgreSQL) for cloud sync and analytics
- Mobile app uses Hive as local satellite DB:
- Caches predictions, timestamps, and images
- Handles offline-first operations
- Syncs via API when network is available
| Database | Role | Location |
|---|---|---|
| Hive | Local cache | Device |
| Supabase | Cloud sync | Backend |
AgriScan follows an Offline-First architecture:
- Scan β Predict (locally using tflite)
- Store scan result in Hive DB
- Background sync when online
- API pushes scan data to Supabase
This ensures usability even in rural areas with weak connections.
Automated with GitHub Actions:
- Lint + test both
api/andapp/folders - Run unit tests with
pytestandflutter test - Build Docker container on
mainbranch - Tag + deploy (future step)
Example workflow file: .github/workflows/test.yml
- Minimal PII stored (no sensitive user data)
- Optional Supabase auth for farmer accounts
- Future plans:
- Encrypted sync tokens
- Role-based access (Admin / Field Agent)
| Step | Process | Layer |
|---|---|---|
| 1 | Farmer captures photo | Flutter Camera |
| 2 | Image sent to backend | FastAPI |
| 3 | Model predicts class | TensorFlow |
| 4 | Result sent to app | API Response |
| 5 | App stores to Hive + syncs | Local DB β Supabase |
| Tool | Version | Notes |
|---|---|---|
| Python | 3.10+ | Required for FastAPI |
| Flutter | 3.24+ | For app builds |
| TensorFlow | 2.13+ | Full version for model |
| tflite-runtime | Optional | For lightweight inference |
| Docker | Latest | API containerization |
| Hive | Latest | Local mobile database |
To reproduce locally:
# API
cd api
pip install -r requirements.txt
uvicorn app.main:app --reload
# Flutter app
cd app
flutter pub get
flutter run
AgriScan is designed for flexible deployment across different environments β from local testing to edge inference on mobile.
| Environment | Purpose | Tech Stack / Tools |
|---|---|---|
| π§βπ» Local | Development & testing | FastAPI + Uvicorn (hot reload) |
| βοΈ Cloud (Future) | Production deployment | Render, Railway, Supabase |
| π± Edge (Planned) | On-device farm use | TensorFlow Lite (mobile inference) |
Each deployment option is containerized via Docker, ensuring consistent behavior across environments.
Future plans include lightweight edge deployments for farm kits (solar-powered mobile devices).
AgriScan/
βββ api/
β βββ app/
β β βββ main.py
β β βββ routers/
β β βββ models/
β βββ tests/
β βββ requirements.txt
β
βββ app/
β βββ lib/
β β βββ main.dart
β β βββ models/
β β βββ screens/
β β βββ services/
β βββ pubspec.yaml
β
βββ models/
β βββ cassava.tflite
β βββ labels.txt
β βββ convert_to_tflite.py
β
βββ docs/
β βββ architecture.png
β βββ roadmap.md
β
βββ .github/
β βββ workflows/
β βββ test.yml
β
βββ LICENSE
βββ README.md
-
/api/β FastAPI backend and ML inference logic -
/app/β Flutter mobile app (offline-first) -
/models/β Trained models, conversion scripts, and labels -
/docs/β Diagrams, guides, and roadmap -
/.github/β CI/CD configuration -
LICENSEβ MIT open-source license -
README.mdβ Root documentation summary
- π§ TensorFlow Lite Models β TensorFlow Hub
- πΏ Cassava Dataset β Kaggle: Cassava Leaf Disease Classification
- πΎ Flutter Hive DB β Hive Documentation
- βοΈ FastAPI β Official Documentation
AgriScan merges AI + offline-first mobile tech to empower farmers with real-time crop health insights β
no internet dependency, no complex setup, just a smartphone and smart code.
This modular setup ensures scalability β from a single cassava model today, to a multi-crop ecosystem tomorrow.
Itβs designed for African contexts: lightweight, fast, and field-ready.
β‘ Fast. Lightweight. Built for the field.