Farm2City #3
Conversation
There was a problem hiding this comment.
Pull request overview
This PR turns the repository into a Vite + React application with a FastAPI backend that exposes ML-powered endpoints for price prediction, crop recommendations, and a simple chatbot, and wires those features into the farmer dashboard and a floating AI chatbot UI.
Changes:
- Added a React (Vite) frontend with marketplace, product details, cart, login, profile, farmer dashboard, and chat pages.
- Added a FastAPI backend exposing
/predict-price,/recommend-crop, and/chat, plus utilities/training code for sklearn models. - Added mock data, styling, and static assets to support the UI.
Reviewed changes
Copilot reviewed 30 out of 52 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| vite.config.js | Adds Vite configuration with React plugin. |
| teams/.gitkeep | Keeps teams/ directory in git. |
| SUB.md | Removes the prior submission guide documentation. |
| .gitignore | Adds ignores for Node/Vite artifacts (missing Python/ML artifacts ignores). |
| package.json | Defines frontend dependencies (React, router, axios, lucide) and scripts. |
| eslint.config.js | Adds ESLint flat config for React + hooks + refresh. |
| index.html | Adds Vite entry HTML for the React app. |
| public/icons.svg | Adds SVG symbol sprite used by the app/site. |
| public/favicon.svg | Adds favicon asset. |
| src/main.jsx | Boots the React app with BrowserRouter. |
| src/App.jsx | Defines routes, top-level cart/user state, and mounts AIChatbot. |
| src/index.css | Adds global styling, glassmorphism utilities, and animations. |
| src/data/mockData.js | Provides mock product catalog and hero image used by UI pages. |
| src/components/Navbar.jsx | Adds primary navigation with role-aware dashboard link and cart badge. |
| src/components/ProductCard.jsx | Adds product card component used by the marketplace grid. |
| src/components/AIChatbot.jsx | Adds floating chatbot UI that calls backend /chat. |
| src/pages/Home.jsx | Adds landing page hero + feature cards. |
| src/pages/Login.jsx | Adds mock role-based login flow (buyer vs farmer) and redirects. |
| src/pages/Marketplace.jsx | Adds marketplace search/filter UI over mock product data. |
| src/pages/ProductDetails.jsx | Adds product detail view and add-to-cart interaction. |
| src/pages/Cart.jsx | Adds cart UI, quantity updates, and mock checkout success state. |
| src/pages/Profile.jsx | Adds profile page with mock order history. |
| src/pages/Chat.jsx | Adds mock buyer–farmer negotiation chat UI. |
| src/pages/Dashboard.jsx | Adds farmer dashboard with AI price prediction + crop recommendation calls. |
| backend/requirements.txt | Adds Python dependencies for FastAPI + sklearn pipeline (has a leading blank line). |
| backend/main.py | Implements FastAPI app with CORS, ML endpoints, and chatbot endpoint. |
| backend/pycache/main.cpython-314.pyc | Adds compiled Python bytecode (should not be committed). |
| backend/ml/init.py | Declares the ml package. |
| backend/ml/model.py | Implements singleton model loader + prediction/recommendation + chatbot intent logic. |
| backend/ml/utils.py | Generates synthetic datasets for training (price + recommendation). |
| backend/ml/train.py | Trains and writes sklearn models/encoders to disk via joblib. |
| backend/ml/price_data.csv | Adds generated synthetic training dataset (large). |
| backend/ml/rec_data.csv | Adds generated synthetic training dataset. |
| backend/ml/models/rec_model.joblib | Adds serialized sklearn model artifact. |
| backend/ml/models/le_crop.joblib | Adds serialized label encoder artifact. |
| backend/ml/models/le_rec.joblib | Adds serialized label encoder artifact. |
| backend/ml/models/le_season.joblib | Adds serialized label encoder artifact. |
| backend/ml/models/le_soil.joblib | Adds serialized label encoder artifact. |
| backend/ml/pycache/init.cpython-314.pyc | Adds compiled Python bytecode (should not be committed). |
| backend/ml/pycache/model.cpython-314.pyc | Adds compiled Python bytecode (should not be committed). |
| backend/ml/pycache/train.cpython-314.pyc | Adds compiled Python bytecode (should not be committed). |
| backend/ml/pycache/utils.cpython-314.pyc | Adds compiled Python bytecode (should not be committed). |
| README.md | Replaces repository README with the default Vite template content. |
| readme2.md | Adds a project README-style document for Farm2City (currently mismatched with repo layout/endpoints). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| app.add_middleware( | ||
| CORSMiddleware, | ||
| allow_origins=["*"], | ||
| allow_credentials=True, | ||
| allow_methods=["*"], | ||
| allow_headers=["*"], | ||
| ) |
There was a problem hiding this comment.
CORS is configured with allow_origins=["*"] while allow_credentials=true. This effectively allows any origin to send credentialed requests and is unsafe for anything beyond local dev (and can also cause CORS header issues). Consider restricting allow_origins to the known frontend origin(s) (e.g., from an env var) and/or setting allow_credentials=false for wildcard origins.
| @@ -0,0 +1,96 @@ | |||
| import { User, MapPin, Phone, Package, Calendar, LogOut } from 'lucide-react' | |||
There was a problem hiding this comment.
LogOut is imported but never used, which will fail the configured ESLint no-unused-vars rule. Remove the unused import (or use it in the UI).
| <div style={{ padding: '1rem', borderBottom: '1px solid var(--glass-border)', background: 'rgba(255,255,255,0.05)', cursor: 'pointer' }}> | ||
| <div style={{ fontWeight: 600, marginBottom: '0.25rem' }}>Green Valley Farm</div> | ||
| <div style={{ fontSize: '0.85rem', color: 'var(--text-secondary)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}> | ||
| Sure, I can do $22 for 10 lbs... | ||
| </div> |
There was a problem hiding this comment.
The contact preview text uses "$" and "lbs" while the rest of the chat uses "₹" and "kg". This inconsistency will look like a pricing/unit bug in the UI—use the same currency and units throughout (or derive them from locale settings).
| import axios from 'axios' | ||
| import { products } from '../data/mockData' | ||
|
|
||
| const API = 'http://localhost:8000' |
There was a problem hiding this comment.
The backend base URL is hardcoded to http://localhost:8000, which will break in preview/production deployments. Use a Vite env var (e.g., import.meta.env.VITE_API_URL) with a sensible default and document it.
| import { MessageCircle, X, Send, Bot } from 'lucide-react' | ||
| import axios from 'axios' | ||
|
|
||
| const API = 'http://localhost:8000' |
There was a problem hiding this comment.
The backend base URL is hardcoded to http://localhost:8000, which will break in preview/production deployments. Use a Vite env var (e.g., import.meta.env.VITE_API_URL) with a sensible default and document it.
| soil,season,recommended_crop | ||
| laterite,summer,Cashew | ||
| laterite,monsoon,Rubber |
There was a problem hiding this comment.
This looks like generated synthetic training data. Since generate_rec_data() can recreate it, consider removing this file from version control and generating it during training/build (or store it externally if it must be versioned).
|
|
||
| fastapi |
There was a problem hiding this comment.
There is a leading blank line in requirements.txt which can confuse tooling and makes diffs noisy. Remove the empty first line so the file starts with the first dependency.
| # React + Vite | ||
|
|
||
| This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
|
||
| **[Register Here →](https://forms.gle/yrQVjSU84b2Wk47Q8)** | ||
| Currently, two official plugins are available: | ||
|
|
There was a problem hiding this comment.
README.md still contains the default Vite template text and doesn't describe Farm2City or how to run the frontend/backend together. Consider replacing it with the project documentation (or moving the current readme2.md content into README.md and linking to the ML API setup/env vars).
| ## 📁 Project Structure | ||
|
|
||
| ``` | ||
| farm2city/ | ||
| │ | ||
| ├── frontend/ (React) | ||
| │ ├── src/ | ||
| │ ├── components/ | ||
| │ ├── pages/ | ||
| │ └── App.js | ||
| │ | ||
| ├── backend/ (FastAPI) | ||
| │ ├── main.py | ||
| │ ├── routes/ | ||
| │ ├── models/ | ||
| │ ├── ml/ | ||
| │ │ ├── train.py | ||
| │ │ ├── model.pkl | ||
| │ │ └── utils.py | ||
| │ | ||
| └── README.md | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## ⚙️ Installation & Setup | ||
|
|
||
| ### 🔹 Backend (FastAPI) | ||
|
|
||
| ```bash | ||
| cd backend | ||
| pip install -r requirements.txt | ||
| uvicorn main:app --reload | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### 🔹 Frontend (React) | ||
|
|
||
| ```bash | ||
| cd frontend | ||
| npm install | ||
| npm start | ||
| ``` |
There was a problem hiding this comment.
The documented project structure and frontend run steps don't match the current repo layout: there is no frontend/ directory, and the scripts are Vite-based (npm run dev, npm run build, etc.). Update this section to reflect the actual paths and commands.
| ## 🔗 API Endpoints | ||
|
|
||
| ### Auth | ||
|
|
||
| * `POST /signup` | ||
| * `POST /login` | ||
|
|
||
| ### Products | ||
|
|
||
| * `GET /products` | ||
| * `POST /products` | ||
| * `PUT /products/{id}` | ||
| * `DELETE /products/{id}` | ||
|
|
||
| ### ML APIs | ||
|
|
||
| * `GET /predict-price` | ||
| * `GET /recommend-crop` | ||
|
|
||
| ### Orders | ||
|
|
||
| * `POST /orders` | ||
| * `GET /orders` | ||
|
|
||
| ### Chatbot | ||
|
|
||
| * `POST /chat` | ||
|
|
There was a problem hiding this comment.
This API endpoint list documents auth/products/orders routes that aren't implemented in backend/main.py (currently only /, /predict-price, /recommend-crop, /chat). Please remove or update the endpoints section to avoid misleading users.
Added Routing, Functionality to Create Story button, Redesigned Footer
This PR enhances the Farm2City – Direct Farmer Marketplace by integrating Machine Learning features and improving overall functionality using FastAPI and React.
The goal is to transform the platform from a basic marketplace into an AI-powered intelligent system that provides data-driven insights and better user experience.