How amit2003dh/kisan-setu works
Purpose and deployable surfaces
KisanSetu is a multi-role agricultural marketplace: farmers list crops, sellers manage products, buyers purchase, delivery partners fulfill orders, and admins oversee the platform. It has two React single-page clients and one Node/Express backend:
• Customer/role application: frontend/src/index.js, frontend/src/App.js
• Separate admin application: admin/src/index.js, admin/src/App.js
• API and realtime server: backend/server.js, backend/crop-analysis-server.js
Client application and role routing
The main React app owns role-specific dashboards and transactional workflows, using API access and route protection as its client boundary. Its pages cover crop/product listing, carts, orders, payment, delivery, crop analysis, and messaging.
• Application composition: frontend/src/App.js
• Shared authenticated access: frontend/src/components/ProtectedRoute.js
• API client boundary: frontend/src/api/api.js
• Client state for shopping: frontend/src/context/CartContext.js
Marketplace catalog and order lifecycle
The backend exposes resource routes for users, crops, products, carts/orders, tracking, and delivery. MongoDB models represent persistent marketplace state; orders bridge buyer checkout, seller/farmer fulfillment, and delivery assignment/tracking.
• Route layer: backend/routes/cropRoutes.js, backend/routes/productRoutes.js, backend/routes/orderRoutes.js
• Core persisted entities: backend/models/Crop.js, backend/models/Product.js, backend/models/Order.js
• Delivery/tracking domain: backend/routes/deliveryRoutes.js, backend/routes/trackerRoutes.js, backend/models/Delivery.js
Identity, authorization, and administration
JWT-backed authentication protects user and administrative operations. The main UI distinguishes operational roles, while the independently deployed admin app handles user, order, production, delivery-partner verification, and analytics oversight.
• User/auth endpoints: backend/routes/userRoutes.js, backend/models/User.js
• Authorization middleware: backend/middleware/auth.js, backend/middleware/adminAuth.js, backend/middleware/admin.js
• Admin application boundaries: admin/src/api/api.js, admin/src/components/ProtectedRoute.js, admin/src/pages/AdminDashboard.js
• Admin API/domain: backend/routes/adminRoutes.js, backend/models/Admin.js
Realtime communications and location
Socket.io support in the backend enables live negotiation/chat and delivery updates. The customer UI has dedicated buyer/seller/order chat components and a delivery socket hook; map views consume location-oriented delivery state.
• Server realtime entry point: backend/server.js
• Conversation APIs and persistence: backend/routes/chatRoutes.js, backend/models/CustomerChat.js, backend/models/Message.js
• Client realtime/location surfaces: frontend/src/hooks/useDeliverySocket.js, frontend/src/components/LiveMap.js, frontend/src/components/OrderChat.js
AI crop analysis and uploads
Crop disease analysis is a distinct backend capability: image input is accepted from crop-analysis UI flows, handled by analysis routes/services, and integrates Google Gemini. Python model files indicate a parallel/local ML prediction path.
• Gemini and AI routes: backend/routes/geminiRoutes.js, backend/routes/aiRoutes.js
• Alternate analysis implementation: backend/routes/cropAnalysisSimple.js, backend/crop-analysis-server.js
• Python ML assets: backend/ai/cropModel.py, backend/ai/predict.py
• UI entry points: frontend/src/pages/CropDoctor.js, frontend/src/pages/PlantAnalysis.js
Payments, persistence, and external infrastructure
Express runs against MongoDB through its database configuration and Mongoose-style model layer. Razorpay order creation/verification is isolated behind payment routes/configuration. Deployments target Vercel for both React clients and Render/Heroku-compatible hosting for the backend; environment variables supply MongoDB, JWT, Gemini, Razorpay, and Google Maps credentials.
• Database connection: backend/config/db.js, backend/models/index.js
• Payment boundary: backend/routes/paymentRoutes.js, backend/config/razorpay.js
• Checkout UI: frontend/src/pages/Payment.js, frontend/src/pages/payment-status-helper.js
Main entry points: server.js Express and Socket.io server · Order.js Marketplace models · App.js Role-based React app · geminiRoutes.js Gemini crop analysis
Components 21
Customer Application
- Role-based React app · Farmer, seller, buyer, and delivery workflows.
frontend/src/App.js - Protected routes
frontend/src/components/ProtectedRoute.js - Marketplace API client
frontend/src/api/api.js - Cart state
frontend/src/context/CartContext.js - Delivery socket and map · Shows live delivery location and order updates.
frontend/src/hooks/useDeliverySocket.js - Crop analysis UI
frontend/src/pages/CropDoctor.js
Admin Application
- Admin dashboard · Independent administration deployment.
admin/src/pages/AdminDashboard.js - Admin API client
admin/src/api/api.js
Backend Platform
- Express and Socket.io server · Hosts HTTP APIs and realtime connections.
backend/server.js - JWT authorization · Protects role and administrative operations.
backend/middleware/auth.js - Identity and admin routes · Users, authentication, and platform oversight.
backend/routes/userRoutes.js - Catalog and order routes · Crop, product, cart, and order lifecycle APIs.
backend/routes/orderRoutes.js - Delivery and tracking routes
backend/routes/deliveryRoutes.js - Chat routes and messages · Persists conversations and messages.
backend/routes/chatRoutes.js - Razorpay payment routes · Creates and verifies checkout payments.
backend/routes/paymentRoutes.js - Gemini crop analysis · Accepts plant imagery for disease analysis.
backend/routes/geminiRoutes.js - Alternate ML analysis server · Supports the local prediction path.
backend/crop-analysis-server.js - Marketplace models · Crop, product, order, delivery, user, and chat state.
backend/models/Order.js
External Services
- MongoDB
- Razorpay
- Google Gemini
Connections 24
- Role-based React app → Protected routes: guards role routes
- Role-based React app → Marketplace API client: uses
- Role-based React app → Cart state: manages checkout cart
- Role-based React app → Delivery socket and map: delivery views
- Crop analysis UI → Marketplace API client: submits images
- Admin dashboard → Admin API client: uses
- Marketplace API client → Express and Socket.io server: HTTP API
- Admin API client → Express and Socket.io server: admin API
- Delivery socket and map → Express and Socket.io server: Socket.io updates
- Express and Socket.io server → JWT authorization: applies
- Express and Socket.io server → Identity and admin routes: mounts
- Express and Socket.io server → Catalog and order routes: mounts
- Express and Socket.io server → Delivery and tracking routes: mounts
- Express and Socket.io server → Chat routes and messages: mounts
- Express and Socket.io server → Razorpay payment routes: mounts
- Express and Socket.io server → Gemini crop analysis: mounts
- Identity and admin routes → Marketplace models: users and admins
- Catalog and order routes → Marketplace models: catalog and orders
- Delivery and tracking routes → Marketplace models: delivery state
- Chat routes and messages → Marketplace models: conversations
- Marketplace models → MongoDB: persists
- Razorpay payment routes → Razorpay: creates and verifies
- Gemini crop analysis → Google Gemini: analyzes images
- Gemini crop analysis → Alternate ML analysis server: alternate path