How nishanthkj/agriculture works
Project type and purpose
• This is a full-stack web application focused on agriculture leveraging AI, IoT, and generative AI.
• Frontend is built with Next.js 15 (React) to deliver UI, pages, and client-side API routes.
• Backend is a Django REST API handling data models (crop prediction, soil fertility, yield, pest, monitoring, management) and serving ML models (RF, Naive Bayes, DL).
File structure
• Top level:
• agri_frontend/ → Next.js app with pages under app/, API routes under app/api/, UI components, Prisma ORM for user data, LLM integrations.
• agri_backend/ → Django project with multiple apps: Agri (core), CropRF, CropYield, SoilFertility, predictor (GPT engine), plus static ML model files, Dockerfile, manage.py.
• agri_backend/agri_backend/ → Django settings, URLs, WSGI/ASGI.
• Models, serializers, views, URLs in each app follow DRF (Django REST Framework) conventions.
• Staticfiles directory holds prebuilt static assets for deployment.
• Patterns:
• Frontend: MVC-like with pages (V), components (V), API routes (C).
• Backend: Modular “app per domain” micro-app pattern; REST API controllers (views) with serializers.
• Codegen/infra: Dockerfile, environment files for local vs containerized deployment.
Key insights from README
• Technologies: Next.js 15, Tailwind, Prisma, Django + DRF, PostgreSQL, Docker, jupyter notebooks for training, ML models serialized (.pkl, .h5).
• Features: Crop Prediction, Soil Health Monitoring, Pest Prediction, Real-Time Monitoring, Generative AI chat, Camera and inventory management.
• Deployment: Frontend on Vercel/Netlify, Backend on Docker/Render/AWS, PostgreSQL in cloud.
Main components
a. User / Web Browser (farmers, stakeholders)
b. Next.js Frontend
• Static/SSR pages
• Client-side API routes (e.g., /api/chat, /api/soil)
• Prisma ORM → PostgreSQL for user/auth data
c. Django Backend (REST API)
• Apps: CropRF, CropYield, SoilFertility, Predictor (GPT), Agri core, etc.
• ML Model Loader modules (load .pkl, .h5 files)
• Database layer (PostgreSQL)
d. ML Models Storage
• Static model files in each Django app
• Training notebooks (outside runtime)
e. External Services
• IoT sensor network → feeds telemetry to soil-health endpoints
• Generative AI (GPT) engine for chat (internal microservice or third-party API)
• External climate & price data providers
f. Infrastructure
• Vercel/Netlify for Frontend
• Docker / AWS / Render for Backend
• PostgreSQL hosted on RDS/Postgres cloud
• CDN / Static file hosting
Relationships & interactions
• Browser ↔ Next.js Frontend: HTTP(S) user requests; SSR or client-side navigation.
• Frontend fetch() → Next.js API routes OR directly to Django REST endpoints at NEXT_PUBLIC_API_BASE_URL.
• Next.js API route (/api/chat) → GPT Engine (internal microservice or OpenAI API).
• Django REST endpoints ← IoT devices push sensor data.
• Django retrieves/stores in PostgreSQL; loads ML models from staticfiles to compute predictions.
• Django → returns JSON responses to Frontend.
• Frontend displays charts, maps, alerts.
Architectural patterns & principles
• Separation of concerns: UI vs business logic vs data storage vs ML.
• Modular apps in Django for each domain.
• API-driven design: front and back decoupled, RESTful endpoints.
• Microservices / internal services for LLM and IoT ingestion.
• Infrastructure as code: Dockerfiles, env configs.
Final advice
• Be as granular as needed: annotate which Django app handles which endpoint.
• ML inference steps separately from CRUD operations.
• This will provide stakeholders and engineers a clear picture of UI, API, ML, DB, and external integrations.