How rajan-git908/smart-crop-recommendation works
1. Overall shape
- AgriCrop is a Flask-based monolith with a server-rendered UI and JSON API endpoints.
- The repo is split into three main boundaries: backend/ for business logic and routes, frontend/ for templates and static assets, and data/ for persisted feedback data.
2. Entry point and request handling
- backend/app.py is the application entry point and the central composition layer.
- It likely wires together the Flask routes for both HTML pages (/, dashboard, login, profile, etc.) and API endpoints such as /api/recommend, /api/feedback, /api/crops, and /api/crop/<name>.
3. Recommendation pipeline
- The core data flow starts with user input of soil and weather parameters: N, P, K, pH, temperature, humidity, rainfall.
- Requests are then passed through preprocessing, inference, and classification before a recommendation is returned to the UI or API caller.
4. Knowledge and rules layer
- backend/modules/knowledge_base.py holds the crop domain model: ideal growing conditions for the supported crops.
- This is the static expert-system boundary that the inference engine uses to compare input conditions against crop requirements.
5. Preprocessing boundary
- backend/modules/data_preprocessor.py is the input sanitation layer.
- Its role is to validate, normalize, and convert units before any reasoning or classification happens, preventing the inference and ML layers from receiving inconsistent data.
6. Reasoning and ML subsystems
- backend/modules/inference_engine.py implements the forward-chaining expert-system logic and confidence scoring.
- backend/modules/classifier.py adds the machine-learning path, described in the README as an ensemble of Naive Bayes and Decision Tree models.
- These two subsystems appear to complement each other: rule-based reasoning for explainability and ML for statistical recommendation support.
7. Feedback and learning loop
- backend/modules/feedback_manager.py handles user feedback submission and analysis.
- The repository includes data/feedback.json, which strongly suggests feedback is persisted outside the main app code and used as a lightweight improvement loop.
8. User identity and session management
- backend/modules/auth_manager.py is the authentication boundary for login, registration, and session handling.
- backend/modules/history_manager.py tracks past recommendations per user, which feeds the profile/history screens and likely supports account-based review of results.
9. Frontend structure
- frontend/templates/ contains the server-rendered pages: landing page, dashboard, output, login/register, profile, and about.
- frontend/static/css/style.css and the JavaScript files in frontend/static/js/ provide interactivity and presentation, especially for input handling and results rendering.
10. Persistence and setup
- backend/setup_db.py and backend/migrate_db.py indicate there is a database-backed subsystem for user/profile/history data, separate from the JSON feedback store.
- The exact DB engine is not visible in the tree, but the presence of setup and migration scripts means schema management is part of the architecture.
11. Configuration and environment
- .env.example and the README’s environment section show the app expects runtime configuration such as SECRET_KEY, debug mode, and Flask environment settings.
- This keeps deployment-specific values out of code and is important for session security and local/production differences.
12. Testing boundary
- tests/test_system.py provides a system-level test layer rather than isolated unit tests only.
- That suggests the repo validates end-to-end behavior across the recommendation pipeline and possibly the exposed API contract.
13. How a diagram should group it
- A useful architecture diagram would place the Flask app in the center, with inbound paths from browser pages and API clients.
- From there, show branching into preprocessing, inference/ML, auth/history, and feedback persistence, with the knowledge base as a read-only domain source and the database/JSON files as the persistence layer.
Main entry points: app.py Flask app · data_preprocessor.py Preprocess · inference_engine.py Inference · classifier.py Classifier
Components 17
Backend
Flask app, business logic, and persistence plumbing
- Flask app · Central composition layer and request router
backend/app.py - Auth · Login, registration, and session handling
backend/modules/auth_manager.py - History · Stores and retrieves past recommendations
backend/modules/history_manager.py - Preprocess · Validates and normalizes crop inputs
backend/modules/data_preprocessor.py - Inference · Forward-chaining reasoning and confidence scoring
backend/modules/inference_engine.py - Classifier · Naive Bayes and decision-tree crop model
backend/modules/classifier.py - Knowledge base · Static crop conditions and domain facts
backend/modules/knowledge_base.py - Feedback · Feedback submission and analysis
backend/modules/feedback_manager.py - DB setup · Initial database creation and bootstrap
backend/setup_db.py - DB migrate · Database migration script
backend/migrate_db.py
Frontend
Server-rendered pages and static assets
- Landing · Home page and user entry point
frontend/templates/index.html - Dashboard · Main recommendation UI
frontend/templates/dashboard.html - Results · Recommendation output view
frontend/templates/output.html - Login · Authentication page
frontend/templates/login.html - Profile · User profile and history view
frontend/templates/profile.html
Connections 17
- Landing → Flask app: HTTP · Landing requests enter the Flask app
- Dashboard → Flask app: HTTP · Recommendation form submits to the app
- Results → Flask app: HTTP · Result and feedback actions reach the app
- Login → Auth: uses · Authentication pages delegate to auth logic
- Profile → History: reads · Profile view loads past recommendations
- Flask app → Preprocess: pipeline · App sends user inputs through preprocessing
- Preprocess → Inference: clean input · Normalized values feed the reasoning engine
- Preprocess → Classifier: clean input · Normalized values feed the ML model
- Inference → Knowledge base: consults · Rules engine compares inputs against crop facts
- Classifier → Knowledge base: trained with · Knowledge boundary informs crop support
- Flask app → Auth: auth · App coordinates login and session flows
- Flask app → History: stores · App records recommendation history
- Flask app → Feedback: submits · Feedback endpoints hand off to feedback manager
- Feedback → Feedback data: persists · Feedback is written to JSON storage
- DB setup → DB migrate: schema · Database lifecycle scripts manage persistence
- Flask app → DB setup: init · App environment relies on DB bootstrap
- Flask app → System test: validated by · System tests exercise the end-to-end app