Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌾 AgriSmart - Farmers Marketplace Platform

MERN Stack Status License

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).

πŸ“Š Project Stats

  • Lines of Code: 4,386+
  • Files: 50+
  • Components: 16
  • API Endpoints: 20+
  • Database Models: 3

🌟 Features

For Farmers

  • 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

For Buyers

  • 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

Core Technology

  • 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

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v14 or higher)
  • npm or yarn
  • MongoDB (local or MongoDB Atlas account)

πŸš€ Quick Start

Automated Setup (Recommended)

# Make setup script executable and run
chmod +x setup.sh
./setup.sh

Manual Setup

1. Backend Setup

cd 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:5000

2. Frontend Setup

cd frontend
npm install
npm start    # Starts on http://localhost:3000

3. Initial Data Setup

# Trigger market price update
curl -X POST http://localhost:5000/api/admin/update-prices

Test Accounts

Create 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"
}

πŸ—„οΈ Database Setup

Local MongoDB

  1. Install MongoDB on your system
  2. Start MongoDB service:
    sudo systemctl start mongod
  3. Update MONGO_URI in .env to:
    MONGO_URI=mongodb://localhost:27017/agrismart
    

MongoDB Atlas (Cloud)

  1. Create an account at MongoDB Atlas
  2. Create a new cluster
  3. Get your connection string
  4. Update MONGO_URI in .env with your Atlas connection string

πŸ“ Project Structure

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

πŸ”‘ API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - Login user
  • GET /api/auth/me - Get current user

Products

  • GET /api/products - Get all products (public)
  • GET /api/products/:id - Get product by ID
  • POST /api/products - Create product (Farmer only)
  • PUT /api/products/:id - Update product (Farmer only)
  • DELETE /api/products/:id - Delete product (Farmer only)

Farmer Routes

  • GET /api/farmer/inventory - Get farmer's products
  • GET /api/farmer/sales - Get sales history
  • GET /api/farmer/dashboard-stats - Get dashboard statistics

Orders

  • POST /api/orders - Create order (Buyer only)
  • GET /api/orders - Get user's orders
  • GET /api/orders/:id - Get order by ID
  • PUT /api/orders/:id/status - Update order status

Admin/Price Updates

  • POST /api/admin/update-prices - Trigger price update
  • GET /api/admin/transparency-stats - Get transparency stats
  • GET /api/admin/price-comparison/:productId - Compare prices

🎨 User Roles

Farmer

  • Create and manage product listings
  • View inventory and sales
  • Track revenue and orders
  • Set competitive prices

Buyer

  • Browse marketplace
  • Compare prices with market rates
  • Place orders directly
  • Track order history

πŸ”„ Price Transparency Engine

The platform includes an automated price transparency system:

  1. Mock Market Prices: Simulated commodity exchange data for common agricultural products
  2. Scheduled Updates: Daily updates at 2:00 AM via node-cron
  3. Transparency Metrics: Percentage comparison showing price differences
  4. Visual Indicators: Clear display of savings vs. market prices

How It Works

  • 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

πŸ§ͺ Testing the Application

1. Register a Farmer Account

  • Go to Register page
  • Choose "Farmer" role
  • Provide farm name
  • Complete registration

2. Create Product Listings

  • Navigate to Farmer Dashboard
  • Click "Add New Product"
  • Fill in product details
  • Submit listing

3. Register a Buyer Account

  • Use a different browser/incognito window
  • Register as "Buyer"
  • Browse marketplace
  • View products and price comparisons

4. Test Price Transparency

  • After products are created, trigger price update:
    curl -X POST http://localhost:5000/api/admin/update-prices
  • Refresh marketplace to see updated transparency metrics

πŸ› οΈ Development Scripts

Backend

npm start        # Start production server
npm run dev      # Start development server with nodemon

Frontend

npm start        # Start development server
npm run build    # Create production build
npm test         # Run tests

🌍 Contributing to SDGs

This 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

πŸ“ Future Enhancements

  • 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

🀝 Support

For issues, questions, or contributions, please create an issue in the repository.

πŸ“„ License

MIT License


Built with ❀️ for farmers and sustainable agriculture

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages