FarmBid is a full-stack application for agricultural reverse auctions with blockchain integration. The application has been fully segregated into a standalone Node.js/Express backend and a Next.js frontend.
FarmBid/
├── frontend/ # Next.js Frontend
│ ├── app/
│ │ ├── layout.js
│ │ ├── page.js # Main application page
│ │ └── globals.css
│ ├── components/ui/ # UI component library
│ ├── lib/
│ ├── .env # Frontend configuration
│ ├── package.json
│ └── next.config.js
│
└── backend/ # Node.js/Express Backend
├── server.js # Main Express server
├── seed.js # Database seeder
├── test.js # API test suite
├── package.json
├── .env.example
├── config/
│ └── database.js # MongoDB connection
├── models/ # Mongoose schemas
│ ├── Farmer.js
│ ├── Buyer.js
│ ├── Listing.js
│ ├── Bid.js
│ ├── Auction.js
│ ├── BlockchainEvent.js
│ ├── Dispute.js
│ ├── Delivery.js
│ ├── Wallet.js
│ └── WalletTransaction.js
├── routes/ # API route handlers
│ ├── listings.js
│ ├── bids.js
│ ├── farmers.js
│ ├── buyers.js
│ ├── auctions.js
│ ├── blockchain.js
│ ├── disputes.js
│ ├── deliveries.js
│ ├── admin.js
│ ├── quality.js
│ ├── wallet.js
│ └── orders.js
├── middleware/
│ └── validation.js
└── utils/
├── auctionTimer.js
└── blockchain.js
- Reverse Auction System: Farmers set the base price, buyers bid upwards
- Real-time Auction Timer: Dynamic countdown with status updates
- Quality Analysis: AI-powered produce quality scoring (simulated)
- Blockchain Anchoring: All critical events anchored to Polygon Mainnet (simulated for MVP)
- Wallet Management: Buyer wallet with escrow and settlement
- Dispute Resolution: Weight mismatch, quality discrepancy handling
- Delivery Tracking: Photo verification, geotagging, weight reconciliation
- Admin Dashboard: KPIs, fraud detection, platform health monitoring
- Multi-language Support: English, Hindi, Kannada (WhatsApp-style chat demo)
GET /api/listings- Get all active listings (with status-based filtering)GET /api/listings/:id- Get specific listing with bidsPOST /api/listings- Create new listing (anchored to blockchain)
POST /api/bids- Place a bid (must be higher than current)GET /api/bids- Get bids (filter by listingId)GET /api/bids/buyer/:buyerId- Get buyer's bid history
GET /api/farmers- Get all farmersGET /api/farmers/:id- Get farmer profile with listingsGET /api/farmers/stats/summary- Get farmer statistics
GET /api/buyers- Get all buyersGET /api/buyers/:id- Get buyer profile with bids and won auctionsGET /api/buyers/stats/summary- Get buyer statistics
GET /api/auctions/completed- Get completed auctions with delivery info
GET /api/blockchain/events- Get blockchain events (filterable by type/entityId)GET /api/blockchain/events/tx/:txHash- Get specific transactionGET /api/blockchain/stats- Get blockchain statistics
GET /api/disputes- Get all disputesPOST /api/disputes- File new disputePUT /api/disputes/:id- Update dispute status (admin)GET /api/disputes/auction/:auctionId- Get dispute for auction
GET /api/deliveries- Get all deliveries (filterable)POST /api/deliveries- Schedule deliveryPUT /api/deliveries/:id- Update delivery statusGET /api/deliveries/auction/:auctionId- Get delivery for auction
GET /api/admin/kpis- Platform key performance indicatorsGET /api/admin/districts- District-wise statisticsGET /api/admin/fraud-alerts- Suspicious activity alertsGET /api/admin/platform-health- 24-hour platform health metrics
POST /api/quality/analyze- AI quality analysis (simulated)POST /api/quality/manual-score- Manual quality scoring (admin)
GET /api/wallet/balance?buyerId=:buyerId- Get wallet balancePOST /api/wallet/topup- Top up walletGET /api/wallet/transactions/:userId- Transaction historyGET /api/wallet/:userId- Full wallet info
GET /api/orders- Get orders for buyer/completed auctionsGET /api/orders/:id- Get order details
- Node.js (v18 or higher)
- MongoDB (v6.0 or higher) - running locally or accessible remotely
- npm or yarn package manager
# Navigate to project directory
cd E:/Hackthon/BGSCET/BGSCET/FarmBid
# Install frontend dependencies
cd frontend
npm install
cd ..
# Install backend dependencies
cd backend
npm install
cd ..The frontend uses .env:
NEXT_PUBLIC_BASE_URL=http://localhost:3000
NEXT_PUBLIC_API_URL=http://localhost:3001/apiThe backend uses backend/.env (copy from .env.example):
MONGO_URL=mongodb://localhost:27017
DB_NAME=farmbid_db
PORT=3001
CORS_ORIGINS=http://localhost:3000Make sure MongoDB is running:
# On Windows (if MongoDB is in PATH)
mongod
# Or using Docker
docker run -d -p 27017:27017 --name mongodb mongo:latestnpm run backend:seedThis will populate the database with sample farmers, buyers, listings, bids, and blockchain events.
# Development mode (with auto-reload)
npm run backend:dev
# Or production mode
npm run backend:startThe backend API will be available at http://localhost:3001/api
npm run devThe frontend will be available at http://localhost:3000
# Make sure backend server is running on port 3001
npm run backend:start
# In another terminal, run the test suite
npm run backend:testOr run directly:
cd backend
node test.jsThe backend provides a comprehensive health check endpoint:
curl http://localhost:3001/api/healthThe Next.js frontend is a single-page application with:
frontend/app/page.js: Main component with full UI logicfrontend/app/layout.js: Root layout with theme providerfrontend/components/ui/: Radix UI based component library- All UI in one file for rapid development
Enterprise-grade Node.js/Express backend:
- MongoDB + Mongoose: Persistent data storage with relationships
- CORS Enabled: Allows requests from frontend origin
- Validation: Request validation via express-validator
- Security: Helmet.js security headers, rate limiting
- Logging: Morgan HTTP request logging
- Blockchain: Simulated anchoring (ready for real Web3 integration)
- RESTful API: All endpoints follow REST conventions
- Farmer: Farmer profiles with verification status, crops, location
- Buyer: Buyer profiles with wallet, trust score, type
- Listing: Auction listings with quality metrics, timer
- Bid: Individual bids placed by buyers
- Auction: Completed auction/settlement records
- BlockchainEvent: All blockchain transaction records
- Dispute: Dispute cases with resolution tracking
- Delivery: Delivery records with photos, geotags
- Wallet: Wallet balances and KYC status
- WalletTransaction: Transaction history
All API responses follow this structure:
{
"success": true,
"data": "...",
"error": "Error message if any"
}Exceptions include list endpoints which directly contain the array with a count field.
If you modify any model in /backend/models, you should:
- Update the seed data in
backend/seed.jsif needed - Re-run seeding if structural changes require new data
- Create/update route handler in corresponding file in
/backend/routes/ - Add validation rules in
backend/middleware/validation.jsif needed - Update the
backend/seed.jsif new data is needed - Update frontend
app/page.jsto call the new endpoint
The blockchain integration is currently simulated in backend/utils/blockchain.js. To integrate with real Polygon/Ethereum:
- Install Web3 provider:
npm install ethersorviem - Update
anchorToBlockchain()function to make actual contract calls - Add smart contract ABIs to
/backend/contracts/ - Configure network provider URL in
.env
cd backend
npm install --production
NODE_ENV=production npm startnpm install
npm run build
npm startEnsure production .env files have correct values:
- MongoDB connection string
- CORS origins for production domain
- Blockchain provider URL (when integrating)
- Ensure MongoDB is running:
mongodor Docker container - Check connection string in
backend/.env - Verify port 27017 is available
- Check
CORS_ORIGINSsetting inbackend/.env - Frontend must use
NEXT_PUBLIC_API_URLmatching CORS origin
- Backend default: 3001
- Frontend default: 3000
- Change ports in
.envfiles if needed
- Ensure database is seeded:
npm run backend:seed - Check MongoDB is connected (backend console shows "MongoDB Connected")
MIT License - FarmBid Platform
For issues or questions, please refer to the project repository or contact the development team.