How dheerajok/cropadvisor works
1. Overall shape
Agro-Insight is organized as a Next.js App Router application. The repository contains both the user-facing pages and the server-side API routes inside the same app, so the main architectural boundary is between React pages/components and **app/api/* route handlers**.
2. User-facing modules
The top-level pages are split into feature areas: dashboard, crop recommendation, disease detection, fertilizer, weather, farming guide, and learn more. These are mostly presentation and interaction layers that collect user input, show results, and navigate between tools.
3. API surface
The backend logic exposed by this repo lives under app/api/:
- weather/current
- soil/analyze
- crop/recommend
- fertilizer/recommend
- disease/detect
- disease/history
Each route is a server-side entry point for a single domain operation, which makes these the key integration boundaries for the UI.
4. Domain decomposition
The application is split into clear agricultural domains:
- Weather: current conditions and likely forecast support
- Soil analysis: soil measurements and derived interpretation
- Crop recommendation: recommendation engine based on soil/climate/location inputs
- Fertilizer recommendation: nutrient and crop-specific guidance
- Disease detection: image-based diagnosis plus history tracking
- Guides/content: static knowledge and best-practice information
This separation is important for diagramming because each feature is independently invoked but semantically related through farming workflows.
5. Data flow from UI to server
The typical flow is: user interacts with a feature page → page calls a matching API route → route performs analysis/recommendation → response is rendered back in the page. The repo’s structure suggests the pages are thin clients over domain-specific server endpoints, rather than embedding all logic in the browser.
6. Persistence layer
There is a dedicated database helper in app/db/mongodb.js and model files for:
- CropRecommendation
- DiseaseDetection
- FertilizerRecommendation
That indicates a MongoDB-backed persistence layer used at least for storing recommendation/detection records and retrieving disease history. For an architecture diagram, this is the main stateful subsystem outside the Next.js runtime.
7. Disease detection pipeline
app/api/disease/detect/route.js plus app/utils/diseaseParser.js and the DiseaseDetection model imply a two-step backend path: accept an image or detection payload, normalize/parse the result, then persist or return structured diagnosis data. The separate history route is the read-side of that same subsystem.
8. Weather integration
The README references OpenWeatherMap, and the weather/current API route is the obvious integration point. This route likely acts as a server-side adapter that hides the external weather API from the UI and returns app-specific weather data.
9. Machine-learning / inference boundary
The README describes AI-based crop and disease features, and the file layout keeps those operations behind API routes rather than in pages. Architecturally, this means model inference happens on the server side, with the frontend only handling inputs like soil values or leaf images and rendering the predicted output.
10. Shared presentation shell
app/layout.js, app/globals.css, and the dashboard page provide the application shell and shared styling. This is the common UI layer that wraps all feature pages, while the actual business logic remains in the feature routes.
11. Static and informational content
farming-guide, learn-more, and the root page.js are mostly informational/navigation surfaces. They support onboarding and education rather than core data processing, so they sit at the edge of the architecture.
12. Important repo note
The README mentions a separate Python/Flask or FastAPI backend, but this tree does not include a backend/ directory. In the code present here, the Next.js app itself appears to host the API layer, so a diagram should reflect the repository as a self-contained web app with serverless-style routes, not a split frontend/backend codebase.
13. Key boundaries to draw
The most useful diagram boundaries are:
- Browser/UI pages
- Next.js API routes
- MongoDB persistence
- External services/model inference inputs
That separation captures how farmers’ inputs move from pages into server-side recommendation/detection logic and then into stored history or returned results.
Main entry points: layout.js App shell · dashboard/page.js Dashboard · mongodb.js MongoDB · crop-recommendation/page.js Crop rec
Components 21
UI shell
App Router pages and shared presentation layer
- Home · Entry point and primary navigation surface
app/page.js - Dashboard · Main application overview and feature launcher
app/dashboard/page.js - Crop rec · Crop recommendation input and results UI
app/crop-recommendation/page.js - Disease detect · Leaf image diagnosis interface
app/disease-detection/page.js - Fertilizer · Fertilizer guidance interface
app/fertilizer/page.js - Weather · Weather lookup and display screen
app/weather/page.js - Farming guide · Educational farming guidance content
app/farming-guide/page.js - Learn more · Onboarding and project information page
app/learn-more/page.js
API routes
Server-side domain endpoints under app/api
- Weather current · Server-side weather data adapter
app/api/weather/current/route.js - Soil analyze · Server-side soil analysis endpoint
app/api/soil/analyze/route.js - Crop recommend · Server-side crop recommendation endpoint
app/api/crop/recommend/route.js - Fertilizer recommend · Server-side fertilizer recommendation endpoint
app/api/fertilizer/recommend/route.js - Disease detect · Server-side disease detection endpoint
app/api/disease/detect/route.js - Disease history · Read-side disease detection history endpoint
app/api/disease/history/route.js
Data layer
MongoDB helper and persisted models
- MongoDB · Shared database connection helper
app/db/mongodb.js - Crop model · Stored crop recommendation records
app/model/CropRecommendation.js - Disease model · Stored disease detection records
app/model/DiseaseDetection.js - Fertilizer model · Stored fertilizer recommendation records
app/model/FertilizerRecommendation.js
Shared code
Cross-cutting utilities and global app files
- App shell · Shared Next.js layout and framing
app/layout.js - Global styles · Application-wide styling
app/globals.css - Disease parser · Normalizes disease detection output
app/utils/diseaseParser.js
Connections 28
- Home → App shell: wrapped by · Home page uses the shared app shell
- Dashboard → App shell: wrapped by · Dashboard renders inside the shared shell
- Crop rec → App shell: wrapped by · Feature page uses shared layout
- Disease detect → App shell: wrapped by · Feature page uses shared layout
- Fertilizer → App shell: wrapped by · Feature page uses shared layout
- Weather → App shell: wrapped by · Feature page uses shared layout
- Farming guide → App shell: wrapped by · Content page uses shared layout
- Learn more → App shell: wrapped by · Content page uses shared layout
- App shell → Global styles: loads · Layout applies the global stylesheet
- Dashboard → Crop rec: navigates to · Dashboard links into crop recommendation
- Dashboard → Disease detect: navigates to · Dashboard links into disease detection
- Dashboard → Fertilizer: navigates to · Dashboard links into fertilizer guidance
- Dashboard → Weather: navigates to · Dashboard links into weather lookup
- Crop rec → Crop recommend: calls · Crop UI submits inputs to the recommendation endpoint
- Crop rec → Soil analyze: calls · Crop UI can request soil analysis as part of recommendation
- Fertilizer → Fertilizer recommend: calls · Fertilizer UI requests recommendations from the server
- Weather → Weather current: calls · Weather UI fetches current conditions
- Disease detect → Disease detect: calls · Disease UI submits image or diagnosis payload
- Disease detect → Disease history: calls · Disease UI reads past detections
- Crop recommend → MongoDB: persists · Crop recommendations can be stored through MongoDB helper
- Fertilizer recommend → MongoDB: persists · Fertilizer recommendations can be stored through MongoDB helper
- Disease detect → Disease parser: normalizes · Detection output is parsed into structured data
- Disease detect → MongoDB: persists · Detection results are stored in MongoDB
- Disease history → MongoDB: reads · History endpoint queries stored detection records
- Crop recommend → Crop model: uses · Crop route works with crop recommendation records
- Fertilizer recommend → Fertilizer model: uses · Fertilizer route works with fertilizer recommendation records
- Disease detect → Disease model: uses · Detection route works with disease records
- Weather current → MongoDB: optional state · Weather route may use shared persistence or caching