How shlokapol2005/soilsense works
1. High-level shape
SoilSense is a 3-tier application: a React/Vite frontend, a Node/Express backend, and a MongoDB database. In addition, there is a Python-based ML training pipeline that produces serialized models consumed by the app.
2. Frontend boundary
The frontend/ folder is the presentation layer. It uses React with Vite and is organized as a page-based UI with screens for welcome, login/signup, dashboard, soil analysis, weather, calculator, recommendations, and history. App.jsx and main.jsx are the entry points that wire the page flow and global styling.
3. Frontend responsibilities
The UI appears to handle user interaction, form capture, displaying weather/soil outputs, and presenting recommendation results and history. CSS is split per page, suggesting each route/screen is mostly self-contained rather than sharing a large component library.
4. Backend boundary
The backend/ folder is the API and data-access layer. The repo tree shows a Node.js service (server.js) with Express-style route modules under routes/, plus database models under models/. This is the main runtime boundary that the frontend talks to over HTTP.
5. Backend API domains
There are two explicit route domains: authRoutes.js for user authentication and weatherRoutes.js for weather-related operations. That suggests the backend is responsible for both account management and serving weather or prediction-adjacent data to the frontend.
6. Persistence layer
MongoDB is the durable store. The backend includes Mongoose-style models for User and weather, and the README describes a prediction_history collection as well. The data store likely keeps user records, fetched weather snapshots, and historical prediction/recommendation records for later display.
7. Machine learning subsystem
The ML assets live under backend/models_ml/, including serialized models for crop recommendation and nutrient-related predictions (model_N.pkl, model_P.pkl, model_K.pkl, crop_model.pkl) plus label encoders for district and soil type. This indicates inference is model-file-based rather than an online training service.
8. Training pipeline
backend/train_models.py and the CSV datasets show an offline training workflow. The training script likely reads the combined soil/fertilizer dataset, fits the random-forest-based models described in the README, and writes the .pkl artifacts used later by the backend.
9. External weather dependency
The system integrates OpenWeatherMap for real-time weather input. That external API is part of the data flow feeding recommendations, especially because temperature is listed as an input and the backend has a dedicated weather route.
10. Primary data flow
A typical request path is: user enters soil/district information in the React UI → frontend calls the backend API → backend fetches/uses weather data if needed → backend loads the ML model artifacts to generate crop/fertilizer recommendations → result is returned to the UI and optionally stored in MongoDB history.
11. Historical and user-centric flows
The presence of history pages and database collections implies a second flow: recommendation results are persisted and later queried for a user’s past analyses. Authentication likely gates access to personalized history and saved data.
12. Important architectural note
The README describes a Flask backend, but the repository tree shows a Node/Express backend as the active server implementation. For an architecture diagram, the safer interpretation is: React frontend → Node/Express API → MongoDB + local ML artifacts, with Python used for model training/offline generation rather than as the main serving runtime.
Main entry points: App.jsx App shell · server.js API server · weatherRoutes.js Weather API · train_models.py Training script
Components 21
Frontend
React/Vite presentation layer and page flow.
- App shell · Bootstraps the Vite/React UI and wires global app flow.
frontend/src/App.jsx - Main entry · Mounts the app into the DOM and applies global styling.
frontend/src/main.jsx - Welcome · Landing screen for first-time navigation.
frontend/src/pages/WelcomeScreen.jsx - Auth screens · Login and signup UI for account access.
frontend/src/pages/LoginPage.jsx - Dashboard · Main user view that summarizes app state.
frontend/src/pages/Dashboard.jsx - Soil analysis · Captures soil inputs and analysis context.
frontend/src/pages/SoilAnalysis.jsx - Weather page · Shows weather data used in recommendation flows.
frontend/src/pages/WeatherPage.jsx - Calculator · Supports fertilizer or crop-related calculations.
frontend/src/pages/CalculatorPage.jsx - Recommendations · Displays model outputs and suggested crops or inputs.
frontend/src/pages/Recommendations.jsx - History · Shows prior analyses and saved prediction results.
frontend/src/pages/HistoryPage.jsx
Backend
Node/Express API, persistence, and orchestration.
- API server · Express server that exposes HTTP endpoints.
backend/server.js - Auth API · Authentication endpoints for signup and login.
backend/routes/authRoutes.js - Weather API · Weather and weather-adjacent endpoints.
backend/routes/weatherRoutes.js - DB config · MongoDB connection setup for the backend.
backend/config/db.js - User model · User account schema and persistence logic.
backend/models/User.js - Weather model · Stored weather snapshot or forecast records.
backend/models/weather.js - MongoDB · Durable store for users, weather data, and history.
ML Assets
Offline training inputs and serialized prediction models.
- Model files · Pretrained crop and nutrient prediction artifacts.
backend/models_ml/crop_model.pkl - Training script · Offline workflow that fits and writes model artifacts.
backend/train_models.py - Training data · Source tables used to train the prediction models.
backend/Crop-and-fertilizer-dataset-combined.csv
Other components
- OpenWeatherMap · External weather provider used for live inputs.
Connections 25
- Main entry → App shell: mounts · Bootstraps the app shell into the page.
- App shell → Welcome: routes to · Initial user flow starts at the welcome screen.
- App shell → Auth screens: routes to · Provides login and signup entry points.
- App shell → Dashboard: routes to · Main navigation reaches the dashboard.
- App shell → Soil analysis: routes to · Surfaces soil input and analysis screens.
- App shell → Weather page: routes to · Shows weather-related views.
- App shell → Calculator: routes to · Includes calculator functionality.
- App shell → Recommendations: routes to · Displays recommendation results.
- App shell → History: routes to · Shows past analyses and saved records.
- App shell → API server: api calls · Frontend talks to the backend over HTTP.
- API server → Auth API: mounts · Registers authentication endpoints.
- API server → Weather API: mounts · Registers weather endpoints.
- API server → DB config: initializes · Connects the service to MongoDB.
- DB config → MongoDB: connects · Establishes the database connection.
- Auth API → User model: uses · Auth operations read and write user records.
- Weather API → Weather model: uses · Weather endpoints persist or retrieve weather records.
- Weather API → OpenWeatherMap: fetches · Pulls live weather data from the external provider.
- User model → MongoDB: stores in · User documents live in MongoDB.
- Weather model → MongoDB: stores in · Weather data lives in MongoDB.
- API server → Model files: loads · Backend reads serialized models for inference.
- Training script → Training data: trains on · Offline training consumes the CSV datasets.
- Training script → Model files: writes · Training produces the model artifacts used by the app.
- Soil analysis → API server: submits data · Soil inputs are sent to the API for processing.
- Recommendations → API server: requests results · Recommendation page retrieves predictions and history.
- History → API server: queries history · History page fetches stored past analyses.