How amarnathss/crop-and-fertilizer-recomendation-project works
Project Type & Purpose
• This is a full-stack web application (“Krisirava”) built with Flask (Python) that provides AI-driven crop and fertilizer recommendations.
• Purpose: Farmers input soil nutrients (N, P, K), climate parameters (temperature, humidity, pH, rainfall) and receive data-backed crop advisories and fertilizer schedules.
File Structure & Architectural Insights
Top-level:
• app.py – Flask application entry point (routes, request handling)
• config.py – Configuration (weather API key, settings)
• requirements.txt – Python dependencies (Flask, scikit-learn, pandas, etc.)
• Procfile & Runtime.txt – Deployment descriptors (Gunicorn, Heroku)
Directories:
• models/ – Persisted AI models: RandomForest.pkl (crop advisory), plant_disease_model.pth (unused in README?)
• utils/ – Core logic for fertilizer recommendation (fertilizer.py)
• Data/ – fertilizer.csv dataset (nutrient requirements)
• templates/ – Jinja2 HTML templates (layout, crop, fertilizer, results pages)
• static/ – Front-end assets (CSS, JS, images)
System Components
• User Interface Layer
– Browser clients
– HTML pages (templates/)
– CSS/JS assets (static/)
• Web Server Layer
– Flask app (app.py)
– Route handlers for “/crop”, “/fertilizer”, etc.
– Configuration loader (config.py)
• Business Logic & Model-Serving Layer
– Utils module (fertilizer.py)
– Model loader: scikit-learn RandomForest.pkl, PyTorch .pth
– Data processing: NumPy, Pandas
• External Service
– OpenWeatherMap API (optional real-time climate data)
• Data Storage & Assets
– fertilizer.csv (local CSV)
– Trained model files
• Deployment & Runtime
– Gunicorn as WSGI server
– Heroku cloud (Procfile, env vars like WEATHER_API_KEY)
Relationships & Data Flow
1. User → Browser UI
2. UI calls Flask endpoints (POST/GET)
3. Flask reads inputs and:
a. Loads fertilizer.csv or calls utils for recommendation
b. Loads ML models for crop advisory
c. Optionally fetches weather data via external API
4. Business logic processes data, returns results
5. Flask renders result templates → Browser
6. Deployment layer sits in front (Gunicorn → Heroku)
Architectural Patterns & Design Principles
• MVC-like separation:
– View: templates + static
– Controller: Flask route handlers
– Model: ML models + CSV data + utility functions
• Single codebase with layered responsibilities
• External configuration (config.py, env vars)
• Stateless web layer, heavy lifting in memory (no DB)