A complete MERN stack marketplace connecting farmers directly with buyers, featuring automated price transparency to eliminate middlemen and ensure fair pricing for all parties.
AgriSmart is a direct-to-consumer/business marketplace that connects farmers with buyers, emphasizing price transparency to eliminate the loss of revenue to middlemen. This platform contributes to UN SDG 2 (Zero Hunger) and SDG 8 (Decent Work and Economic Growth).
- Lines of Code: 4,386+
- Files: 50+
- Components: 16
- API Endpoints: 20+
- Database Models: 3
- Product Listings: Create and manage product listings with ease
- Inventory Management: Track available products and quantities
- Sales Dashboard: View sales history and revenue statistics
- Price Transparency: Compare your prices against market rates
- Order Management: Track and manage incoming orders
- Marketplace: Browse fresh products directly from farmers
- Price Comparison: See farmer prices vs. official market prices
- Search & Filter: Find products by category, price, and more
- Direct Ordering: Purchase directly from farmers with no middlemen
- Order History: Track your purchases and deliveries
- Frontend: React.js with React Router
- Backend: Node.js + Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT-based authentication
- Price Engine: Automated market price updates with node-cron
Before you begin, ensure you have the following installed:
- Node.js (v14 or higher)
- npm or yarn
- MongoDB (local or MongoDB Atlas account)
# Make setup script executable and run
chmod +x setup.sh
./setup.shcd backend
npm install
# Configure .env file:
# MONGO_URI=mongodb://localhost:27017/agrismart
# JWT_SECRET=your_secure_secret_key
# PORT=5000
# NODE_ENV=development
npm run dev # Starts on http://localhost:5000cd frontend
npm install
npm start # Starts on http://localhost:3000# Trigger market price update
curl -X POST http://localhost:5000/api/admin/update-pricesCreate a Farmer:
POST /api/auth/register
{
"username": "farmerjohn",
"email": "farmer@example.com",
"password": "password123",
"role": "Farmer",
"farmName": "Green Valley Farm"
}Create a Buyer:
POST /api/auth/register
{
"username": "buyer1",
"email": "buyer@example.com",
"password": "password123",
"role": "Buyer"
}- Install MongoDB on your system
- Start MongoDB service:
sudo systemctl start mongod
- Update
MONGO_URIin.envto:MONGO_URI=mongodb://localhost:27017/agrismart
- Create an account at MongoDB Atlas
- Create a new cluster
- Get your connection string
- Update
MONGO_URIin.envwith your Atlas connection string
AgriSmart/
βββ backend/
β βββ config/
β β βββ db.js # Database connection
β βββ middleware/
β β βββ auth.js # Authentication middleware
β βββ models/
β β βββ User.js # User schema (Farmer/Buyer)
β β βββ Product.js # Product schema
β β βββ Order.js # Order schema
β βββ routes/
β β βββ auth.js # Authentication routes
β β βββ product.js # Product routes
β β βββ farmer.js # Farmer-specific routes
β β βββ order.js # Order routes
β β βββ admin.js # Admin/price update routes
β βββ services/
β β βββ priceService.js # Price transparency engine
β βββ .env # Environment variables
β βββ package.json
β βββ server.js # Main server file
βββ frontend/
β βββ public/
β β βββ index.html
β βββ src/
β β βββ components/
β β β βββ Header.js # Navigation header
β β β βββ ProductCard.js # Product display card
β β β βββ ProtectedRoute.js # Route protection
β β βββ context/
β β β βββ AuthContext.js # Authentication context
β β βββ pages/
β β β βββ Home.js # Landing page
β β β βββ Login.js # Login page
β β β βββ Register.js # Registration page
β β β βββ Marketplace.js # Product marketplace
β β β βββ FarmerDashboard.js # Farmer dashboard
β β β βββ NewListingForm.js # Add product form
β β β βββ InventoryTable.js # Inventory management
β β β βββ SalesHistory.js # Sales history
β β βββ utils/
β β β βββ api.js # Axios configuration
β β βββ App.js # Main app component
β β βββ App.css
β β βββ index.js
β β βββ index.css
β βββ package.json
βββ README.md
POST /api/auth/register- Register new userPOST /api/auth/login- Login userGET /api/auth/me- Get current user
GET /api/products- Get all products (public)GET /api/products/:id- Get product by IDPOST /api/products- Create product (Farmer only)PUT /api/products/:id- Update product (Farmer only)DELETE /api/products/:id- Delete product (Farmer only)
GET /api/farmer/inventory- Get farmer's productsGET /api/farmer/sales- Get sales historyGET /api/farmer/dashboard-stats- Get dashboard statistics
POST /api/orders- Create order (Buyer only)GET /api/orders- Get user's ordersGET /api/orders/:id- Get order by IDPUT /api/orders/:id/status- Update order status
POST /api/admin/update-prices- Trigger price updateGET /api/admin/transparency-stats- Get transparency statsGET /api/admin/price-comparison/:productId- Compare prices
- Create and manage product listings
- View inventory and sales
- Track revenue and orders
- Set competitive prices
- Browse marketplace
- Compare prices with market rates
- Place orders directly
- Track order history
The platform includes an automated price transparency system:
- Mock Market Prices: Simulated commodity exchange data for common agricultural products
- Scheduled Updates: Daily updates at 2:00 AM via node-cron
- Transparency Metrics: Percentage comparison showing price differences
- Visual Indicators: Clear display of savings vs. market prices
- Products are compared against official market prices
- Price transparency metric calculated:
((farmerPrice - marketPrice) / marketPrice) * 100 - Green indicators show below-market prices (savings for buyers)
- Orange indicators show above-market prices
- Go to Register page
- Choose "Farmer" role
- Provide farm name
- Complete registration
- Navigate to Farmer Dashboard
- Click "Add New Product"
- Fill in product details
- Submit listing
- Use a different browser/incognito window
- Register as "Buyer"
- Browse marketplace
- View products and price comparisons
- After products are created, trigger price update:
curl -X POST http://localhost:5000/api/admin/update-prices
- Refresh marketplace to see updated transparency metrics
npm start # Start production server
npm run dev # Start development server with nodemonnpm start # Start development server
npm run build # Create production build
npm test # Run testsThis platform directly contributes to:
- SDG 2 (Zero Hunger): Improving food supply chains and farmer livelihoods
- SDG 8 (Decent Work): Ensuring fair compensation for farmers and eliminating exploitative middlemen
- Real-time commodity exchange API integration
- Payment gateway integration
- Mobile app development
- Rating and review system
- Advanced analytics dashboard
- Multi-language support
- Image upload functionality
- Real-time chat between farmers and buyers
For issues, questions, or contributions, please create an issue in the repository.
MIT License
Built with β€οΈ for farmers and sustainable agriculture