Proposal: New Feature Enhancements for AgriTech
Overview
- Purpose: Add four major features to AgriTech to increase farmer adoption and provide actionable, expert-backed guidance.
- Features:
- AI Fertilizer Recommendation System
- Weather Forecast Dashboard Integration
- Expert Q&A Forum (Community Upgrade)
- Farm Progress Tracker
Scope & Goals
- Deliver production-ready backend APIs, minimal frontend components, and integration points for ML and third-party APIs.
- Keep changes incremental and backward-compatible with existing
crop_recommendationmodule anddashboard.html.
- AI Fertilizer Recommendation System
- Goal: Suggest fertilizer types and application rates based on soil pH, crop type, and weather conditions.
- Inputs: soil_pH, crop_type, growth_stage (optional), recent_weather (temp, rainfall).
- Output: fertilizer recommendation object {fertilizer_name, NPK_ratio, application_rate, notes}
- Implementation approach:
- Train a lightweight ML model (scikit-learn or TensorFlow/Keras) using historical fertilizer-response datasets.
- Integrate model inference into
crop_recommendationmodule (e.g., new functionrecommend_fertilizer()). - Expose API route:
GET /api/recommend/fertilizer(query params or POST JSON payload). - Validate inputs and return confidence score.
- Model storage: add
/models/fertilizer_model.*and versioning metadata inipm_config.jsonorml-model-versioning-implementation.md.
- Testing: unit tests for inference wrapper, integration tests for API route.
- Weather Forecast Dashboard Integration
- Goal: Provide real-time weather updates on dashboard using OpenWeatherMap API.
- Backend:
- New API route:
GET /api/weather?lat={lat}&lon={lon}— server fetches OpenWeatherMap 5-day/3-hour forecast and caches for short TTL (e.g., 10 minutes). - Config: use env var
OPENWEATHER_API_KEYandWEATHER_CACHE_TTL. - Rate limiting & error handling for API failures.
- New API route:
- Frontend:
- Add a weather widget to
dashboard.html(ordashboardcomponent) showing current conditions, 3-day summary, and an icon set. - Use existing
index.js/dashboard.jspattern. Minimal UI with optional Chart.js sparkline for temp/precip.
- Add a weather widget to
- Expert Q&A Forum (Community Upgrade)
- Goal: Allow verified experts to answer farmer queries, with role-based access control.
- Auth & Roles:
- Add roles:
admin,farmer,expert. - Use JWT-based authentication. Extend current
auth_utils.pyto support roles in token claims and role-check decorators. - Endpoints:
POST /api/questions— create question (farmer)GET /api/questions/:id— view question and answersPOST /api/questions/:id/answers— add answer (expert only)GET /api/questions— list (paginated)
- Verification flow: admin can mark a user as
expertviaPUT /api/users/:id/roleor via DB flag.
- Add roles:
- DB changes:
questionstable: id, user_id, title, body, tags, created_at, statusanswerstable: id, question_id, user_id, body, created_at, upvotes
- Frontend:
- Update forum UI pages (
community_forum.htmlorforum.js) to show expert answers with badge and allow filtering byexpert.
- Update forum UI pages (
- Farm Progress Tracker
- Goal: Farmers log crop activities and view visual progress insights.
- Data model:
activitiestable: id, user_id, farm_id, crop_id, activity_type (sowing, irrigation, fertilizing, harvesting), date, notes, attachmentscrop_progressaggregated view/table to compute GDDs, days since sowing, expected harvest window.
- API:
POST /api/activities— log activityGET /api/activities?user_id=&farm_id=&crop_id=— list activitiesGET /api/activities/summary— summarized metrics for charts
- Frontend:
- New
farm_progress.htmlor widget fordashboard.htmlwith charts (Chart.js) showing activity timeline, irrigation frequency, and expected harvest.
- New
Security & Auth
- Extend JWT tokens to include
roleclaim. - Use
auth_utils.pyto implement@requires_role('expert')and@requires_role('admin')decorators. - Store sensitive keys in environment variables; do not commit API keys.
Data & Schema Migration
- Add migration scripts (SQL or a small migration helper) to create
roles,questions,answers,activitiestables. - Backward-compatible migrations: add new columns with defaults where possible.
Integration Points & Files to Modify
- Backend:
app.py— register new blueprints/routes for/api/recommend/fertilizer,/api/weather,/api/questions,/api/activities.auth_utils.py— JWT role support and decorators.agri_utils.pyorcrop_recommendationmodule — addrecommend_fertilizer()wrapper and model loader.
- Frontend:
dashboard.htmlanddashboard.js(orfarm_dashboard.html/farm_dashboard.js) — add weather and progress widgets.community_forum.htmlandforum.js— expert Q&A UI updates.- Add Chart.js to
index.htmlor per-page scripts (use CDN in prototype).
ML Model Notes
- Prototype with scikit-learn (RandomForest) or a small neural net with Keras depending on dataset size.
- Provide training notebook in
/ml/with dataset preprocessing steps, reproducible training and eval. - Maintain model metadata: version, training_date, metrics.
Timeline & Milestones (Suggested)
- Week 1: Design data model, auth roles, and API contracts; create migrations.
- Week 2: Implement JWT roles and forum endpoints; basic frontend for Q&A.
- Week 3: Implement activities API and farm progress UI; basic charts.
- Week 4: Integrate OpenWeatherMap API; add weather widget and caching.
- Week 5: Train POC fertilizer model, integrate into
crop_recommendationand expose API; testing and polish.
Testing & QA
- Unit tests for new API routes and auth decorators.
- Integration tests for end-to-end flows (question->answer, activity->chart)
- ML model CI: add smoke test ensuring model loads and returns expected output format.
Deliverables
PROPOSAL_FEATURE_ENHANCEMENTS.md(this file)- New API routes registered in
app.pyand helper modules - Minimal frontend components wired into existing pages
- Migration scripts and sample data
- ML training notebook and model artifact
Open Questions / Decisions
- Choice of ML framework (scikit-learn vs TensorFlow) — dataset dependent.
- Whether to persist cached weather in DB or memory cache (Redis recommended for scale).
- Expert verification workflow (manual admin vs third-party verification).
Next Steps
- Review proposal and approve scope.
- I can scaffold the API routes, add DB migrations, and scaffold frontend widgets next — which would you like me to start with?