BhuSetu is a lightweight full-stack application that helps farmers get tailored crop recommendations by analyzing soil images and local weather using generative AI. The project includes a React + Vite TypeScript frontend and a Node.js + Express backend (MongoDB) that integrates with Google Generative AI.
Key features
- Soil analysis from a base64 image
- Weather summary for a geographic location
- JSON-formatted crop recommendations with suitability scores
- User accounts with JWT authentication and history of past suggestions
Tech stack
- Frontend: React, TypeScript, Vite, TailwindCSS
- Backend: Node.js, Express, Mongoose (MongoDB)
- AI: Google Generative AI (Gemini)
Repository layout
client/— React + Vite frontendserver/— Express API, controllers, routes, services
Prerequisites
- Node.js (16+ recommended)
- npm or yarn
- A MongoDB instance (Atlas or local)
- Google Generative AI API key
Environment variables (server)
Create a .env file in server/ with:
MONGODB_URI=your_mongodb_connection_string
PORT=5000
FRONTEND_URL=http://localhost:5173
JWT_SECRET=your_jwt_secret
API_KEY=your_google_generative_api_key
Defaults used by the app:
- Frontend dev server:
http://localhost:5173(Vite default) - Backend default port:
5000
Getting started (development)
- Start the backend
cd server
npm install
# create .env as above
npm run dev # uses nodemon, or `npm start` to run node index.js- Start the frontend
cd client
npm install
npm run devOpen the frontend at the Vite URL (usually http://localhost:5173). The frontend communicates with the backend at the FRONTEND_URL/CORS origin set in the server .env.
API overview
-
POST
/api/user/register— register a new user- Body:
{ "username": "...", "email": "...", "password": "..." } - Returns:
{ message, token, user }
- Body:
-
POST
/api/user/login— authenticate- Body:
{ "email": "...", "password": "..." } - Returns:
{ message, token, user }
- Body:
-
GET
/api/user/profile— get profile (uses token)- Header:
Authorization: Bearer <token>
- Header:
-
POST
/api/crop— generate reports & recommendations- Body (JSON):
soilImage: base64 image string (required)lat,long(coordinates)area,areaType(e.g., hectares, acres)additionalDetails(optional)
- Header optional:
Authorization: Bearer <token>(if present, suggestion saved to user history) - Returns:
{ weatherReport, soilReport, cropRec, message }
- Body (JSON):
Example curl (register):
curl -X POST http://localhost:5000/api/user/register \
-H "Content-Type: application/json" \
-d '{"username":"Farmer","email":"farmer@example.com","password":"password"}'Notes & tips
- The backend increases JSON payload limits to support large base64 images — be mindful of very large uploads.
API_KEYmust be a valid Google Generative AI key; the server code uses@google/generative-aiand thegemini-2.5-flashmodel.- Crop recommendations are expected to be returned as strict JSON from the AI; the server parses and transforms that JSON into an array of crop objects.
- Authentication uses JWT stored client-side (e.g., localStorage) and sent as
Authorization: Bearer <token>.
Production
- Build frontend: from
client/runnpm run buildand serve the produceddistfrom a static server or integrate into the backend. - For production, ensure
JWT_SECRETandAPI_KEYare strong secrets andMONGODB_URIpoints to a secure production database.
Contributing
- Open issues or PRs for bugs and features.
- Keep changes focused and add docs for new endpoints or env variables.
License
This repository does not include an explicit license file. Add one (e.g., MIT) if you plan to open-source the project.