AI-powered plant disease detection web application with React frontend and Flask backend.
- Python 3.10+
- Node.js 18+ (for frontend)
- Supabase account (https://app.supabase.com)
git clone https://github.com/appyjuss/PlantView.git
cd PlantViewBackend:
python -m venv venv
.\venv\Scripts\Activate.ps1
pip install -r backend/requirements.txtFrontend:
cd plantViewFrontend
npm install
cd ..- Create a Supabase project at https://app.supabase.com
- Copy your project credentials (
SUPABASE_URL,SUPABASE_ANON_KEY,SUPABASE_SERVICE_ROLE_KEY) - Create
backend/.envwith:
DATABASE_URL=postgresql://[user]:[password]@[host]:5432/[database]
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=your_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
JWT_SECRET=your_secret_key_herecd backend
python -m flask --app main db upgradeTerminal 1 - Backend:
# From backend directory (with venv activated)
python -m flask --app main run
# Runs on http://localhost:5000Terminal 2 - Frontend:
cd plantViewFrontend
npm run dev
# Runs on http://localhost:5173PlantView/
├── backend/ # Flask backend
│ ├── core/ # Core logic (auth, models, storage, schemas)
│ │ ├── auth.py # JWT authentication
│ │ ├── models.py # SQLAlchemy models (User, Detection, Upload)
│ │ ├── storage.py # Supabase file operations
│ │ ├── schemas.py # Pydantic request/response schemas
│ │ └── utils.py # Helper utilities
│ ├── routes/ # API route blueprints
│ │ ├── auth_routes.py # /api/auth/* endpoints
│ │ ├── detect_routes.py # /api/detect endpoint (inference)
│ │ └── upload_routes.py # /api/upload/* endpoints
│ ├── tests/ # Pytest test suite
│ │ ├── conftest.py # Test fixtures and mocks
│ │ ├── test_auth_db.py # Auth & database tests
│ │ ├── test_auth_flow.py # Full auth flow tests
│ │ ├── test_upload.py # Upload endpoint tests
│ │ └── test_upload_upsert.py# Upload/upsert logic tests
│ ├── app.py # Flask application factory
│ ├── main.py # Entry point
│ ├── prediction.py # ML model inference
│ ├── requirements.txt # Python dependencies
│ └── run-flask.ps1 # PowerShell run script
├── plantViewFrontend/ # React frontend
│ ├── src/
│ │ ├── pages/ # Page components
│ │ │ ├── Landing.tsx # Public landing page
│ │ │ ├── Dashboard.tsx # Main app (protected)
│ │ │ ├── Login.tsx # Login page
│ │ │ └── SignUp.tsx # Registration page
│ │ ├── components/ # Reusable components
│ │ │ ├── dashboard/ # Dashboard sub-components
│ │ │ ├── landing/ # Landing page sections
│ │ │ └── ui/ # UI library (button, card)
│ │ ├── context/ # React context
│ │ │ └── AuthContext.tsx # Auth state management
│ │ ├── lib/ # Libraries & utilities
│ │ │ ├── api.ts # Axios client with JWT injection
│ │ │ ├── detections.ts # Detection helpers
│ │ │ └── utils.ts # General utilities
│ │ ├── App.tsx # Main router (BrowserRouter)
│ │ └── main.tsx # Entry point
│ ├── vite.config.ts
│ ├── tailwind.config.js
│ └── tsconfig.json
├── migrations/ # Alembic database migrations
│ ├── alembic.ini
│ ├── env.py
│ └── versions/
│ └── 33615b6b0d60_initial_schema.py
├── models/ # ML model artifacts
│ ├── resnet50_model.pth # Fine-tuned ResNet50 weights
│ └── labels_mapping.json # Disease class labels (38 classes)
├── .env.example # Environment template
├── package.json # Root-level scripts
└── pytest.ini # Pytest configuration
POST /api/auth/signup- Register new userPOST /api/auth/login- Login and get JWT tokenPOST /api/auth/refresh- Refresh expired JWTGET /api/auth/verify- Verify token validityPOST /api/auth/logout- Logout user
POST /api/detect- Send image for disease detection (requires auth)- Returns:
{confidence: float, disease_class: string, disease_label: string, timestamp: string}
- Returns:
POST /api/upload- Upload image and get signed URL (requires auth)GET /api/upload/history- Get user's upload history (requires auth)
All protected endpoints require header:
Authorization: Bearer <JWT_TOKEN>
Database Engine: Supabase (Managed PostgreSQL)
Initialization:
python -m flask --app main db upgradeTables:
users- User accounts with hashed passwordsuploads- Image metadata and signed URLsdetections- ML inference results linked to uploads
Verify Connection: Use Supabase dashboard SQL editor or psql CLI to test connection.
Run All Tests:
pytest backend/tests -vRun Specific Test File:
pytest backend/tests/test_auth_db.py -vRun with Coverage:
pytest backend/tests --cov=backend --cov-report=htmlTest Categories:
test_auth_db.py- User registration, login, token refreshtest_auth_flow.py- Full authentication flow with protected routestest_upload.py- Image upload to Supabasetest_upload_upsert.py- Upload metadata persistence and updates
Note: Tests use mocked Supabase interactions; actual file uploads are not tested against real storage.
Run Development Server:
cd backend
python -m flask --app main run
# Runs on http://localhost:5000Run with Auto-reload:
python -m flask --app main run --reloadDatabase Migration (if schema changed):
# Create new migration
python -m flask --app main db migrate -m "your message"
# Apply migration
python -m flask --app main db upgradeRun Development Server:
cd plantViewFrontend
npm run dev
# Runs on http://localhost:5173Build for Production:
npm run buildPreview Production Build:
npm run preview# Ensure venv is activated
.\venv\Scripts\Activate.ps1
# Install missing dependencies
pip install -r backend/requirements.txt
# Check for port conflicts (port 5000)
netstat -ano | findstr :5000- Verify
DATABASE_URLinbackend/.envis correct - Check Supabase project is active and running
- Ensure
.envfile has correct credentials from Supabase dashboard
cd plantViewFrontend
rm -r node_modules package-lock.json
npm install
npm run dev# Find process using port
netstat -ano | findstr :5000
# Kill process (replace <PID> with actual process ID)
Stop-Process -Id <PID> -Force
# Or use different port
python -m flask --app main run --port 5001Backend
- Flask 3.1.2 - Web framework
- SQLAlchemy - ORM
- Alembic - Database migrations
- PyJWT - JWT token handling
- Bcrypt - Password hashing
- Supabase Client - PostgreSQL & object storage
- Python 3.10+
Frontend
- React 18 - UI framework
- TypeScript - Type safety
- Vite - Build tool
- React Router - Navigation (multi-page routing)
- Axios - HTTP client
- Tailwind CSS - Styling
- Node.js 18+
ML Model
- ResNet50 (transfer learning) - Disease classification backbone
- 38 plant disease classes
Infrastructure
- Supabase - PostgreSQL database + object storage
- Pytest - Testing framework
- Apply AI to agriculture for practical crop health monitoring
- Help farmers and researchers identify plant diseases early
- Demonstrate CNN effectiveness in agricultural image classification
- Expand model to support more plant species and disease variants
- Add real-time prediction confidence visualization
- Implement batch detection API for bulk image analysis
- Deploy to production with cloud infrastructure
- Mobile app support (React Native)
MIT