๐พ FarmMate is a comprehensive prototype of a decentralized precision agriculture marketplace that connects farmers, buyers, and AI-powered insights for sustainable farming practices.
Want to see the system running in 5 minutes? Use the automated script:
./quick-start.shOr manually follow these 3 steps:
-
Start Database:
docker run -d --name farmmate-postgres -e POSTGRES_DB=farmmate -e POSTGRES_USER=farmmate -e POSTGRES_PASSWORD=farmmate123 -p 5432:5432 postgres:15-alpine -
Start Backend:
cd backend && node simple-server.js -
Start Frontend:
cd frontend && npm start -
Open Browser: Go to http://localhost:3000
That's it! The system will be running with sample data. You can browse the marketplace and create new produce batches.
For detailed setup instructions, see the Step-by-Step Setup Guide below.
- Blockchain-Backed Marketplace: Fair pricing, traceability, and escrow payments
- AI-Powered Analysis: On-device disease detection and quality scoring
- Provenance Tracking: Immutable supply chain from farm to table
- Federated Learning: Privacy-preserving model training across farms
- Token Incentives: Rewards for verified data and sustainable practices
- Smart Contracts: Solidity + Hardhat (Polygon testnet/local dev)
- Backend: Node.js + Express + PostgreSQL
- Frontend: React.js with wallet integration
- AI Models: TFLite/ONNX for on-device inference
- Storage: IPFS for images and large files
- Blockchain: Ethereum-compatible (MetaMask integration)
farmmate-prototype/
โโโ contract/ # Smart contracts (Solidity + Hardhat)
โโโ backend/ # Node.js API server
โโโ frontend/ # React web application
โโโ ai/ # AI inference and federated learning
โโโ scripts/ # Deployment and test scripts
โโโ docker-compose.yml # Container orchestration
Required Software:
- Docker (version 20.10+) and Docker Compose (version 2.0+)
- Node.js (version 18.19.1 or higher)
- Git (for cloning the repository)
- Web Browser with MetaMask extension (for wallet functionality)
System Requirements:
- RAM: Minimum 8GB (16GB recommended)
- Storage: At least 5GB free space
- OS: Linux, macOS, or Windows with WSL2
Check Docker Installation:
docker --version
docker-compose --versionExpected output: Docker version 20.10+ and Docker Compose version 2.0+
Check Node.js Installation:
node --version
npm --versionExpected output: Node.js v18.19.1+ and npm 9.0+
# Clone the repository (replace with actual repository URL)
git clone <repository-url>
cd farmmate-prototype
# Verify you're in the correct directory
pwd
ls -laYou should see directories: backend/, frontend/, contract/, ai/, scripts/
Start PostgreSQL using Docker:
# Start PostgreSQL container
docker run -d --name farmmate-postgres \
-e POSTGRES_DB=farmmate \
-e POSTGRES_USER=farmmate \
-e POSTGRES_PASSWORD=farmmate123 \
-p 5432:5432 \
postgres:15-alpine
# Verify PostgreSQL is running
docker ps | grep postgresExpected output: Container farmmate-postgres should be running
# Navigate to backend directory
cd backend
# Install dependencies (if not already installed)
npm install
# Start the simplified backend server
node simple-server.jsExpected Output:
FarmMate backend server running on port 3001
Health check: http://localhost:3001/health
Running in simplified mode with mock data
Keep this terminal open - the backend server needs to stay running.
Open a new terminal window/tab:
# Navigate to project root
cd /path/to/farmmate-prototype
# Navigate to frontend directory
cd frontend
# Install dependencies (if not already installed)
npm install
# Start the React development server
npm startExpected Output:
Compiled successfully!
You can now view farmmate-frontend in the browser.
Local: http://localhost:3000
On Your Network: http://192.168.x.x:3000
Note that the development build is not optimized.
To create a production build, use npm run build.
Keep this terminal open - the frontend server needs to stay running.
Open a new terminal window/tab and run these verification commands:
# Check backend health
curl -s http://localhost:3001/health | jq .
# Check frontend is accessible
curl -s http://localhost:3000 | grep -o "FarmMate"
# Check marketplace API
curl -s http://localhost:3001/api/marketplace/batches | jq '.data | length'Expected Results:
- Backend health:
{"status":"healthy","timestamp":"...","services":{"database":"simulated",...}} - Frontend: Should return
FarmMate - Marketplace API: Should return
2(number of sample batches)
Open your web browser and navigate to:
- Main Application: http://localhost:3000
- Backend API Health: http://localhost:3001/health
1. Connect Wallet (Simulated):
- Click the wallet button in the top-right corner
- The system will simulate a wallet connection
2. Browse Marketplace:
- Navigate to the Marketplace section
- You should see 2 sample produce batches (Tomatoes and Lettuce)
3. Create a New Batch (Farmer Feature):
- Click the "Create Batch" button
- Fill out the form with sample data:
- Crop Type: Select "Carrots"
- Variety: Enter "Nantes"
- Quantity: Enter "30"
- Price: Enter "0.5"
- Harvest Date: Select today's date
- Quality Score: Enter "88"
- Farm Name: Enter "Test Farm"
- Farmer Name: Enter "Test Farmer"
- Click "Create Batch"
- The new batch should appear in the marketplace
4. View Batch Details:
- Click "View" on any batch card
- This will navigate to the Provenance page
If Backend Won't Start:
# Check if port 3001 is already in use
lsof -i :3001
# Kill any process using port 3001
sudo kill -9 $(lsof -t -i:3001)
# Restart backend
cd backend && node simple-server.jsIf Frontend Won't Start:
# Check if port 3000 is already in use
lsof -i :3000
# Kill any process using port 3000
sudo kill -9 $(lsof -t -i:3000)
# Restart frontend
cd frontend && npm startIf PostgreSQL Won't Start:
# Check if port 5432 is already in use
lsof -i :5432
# Remove existing container and restart
docker rm -f farmmate-postgres
docker run -d --name farmmate-postgres \
-e POSTGRES_DB=farmmate \
-e POSTGRES_USER=farmmate \
-e POSTGRES_PASSWORD=farmmate123 \
-p 5432:5432 \
postgres:15-alpineTo stop all services:
# Stop frontend (Ctrl+C in frontend terminal)
# Stop backend (Ctrl+C in backend terminal)
# Stop PostgreSQL
docker stop farmmate-postgres
docker rm farmmate-postgres- Docker is installed and running
- Node.js 18+ is installed
- PostgreSQL container is running
- Backend server is running on port 3001
- Frontend server is running on port 3000
- Application loads at http://localhost:3000
- Marketplace shows sample batches
- "Create Batch" button is visible
- New batches can be created successfully
If you encounter any issues:
- Check that all prerequisites are installed correctly
- Verify all services are running on the correct ports
- Check the terminal output for error messages
- Ensure no firewall is blocking the ports (3000, 3001, 5432)
- Try restarting the services in the correct order
Service URLs:
- Frontend: http://localhost:3000
- Backend API: http://localhost:3001
- PostgreSQL: localhost:5432
- Frontend Application: Complete React UI with modern design
- Backend API: RESTful API with mock data storage
- Marketplace: Browse and filter produce batches
- Batch Creation: Farmers can create and list new produce batches
- Wallet Integration: Simulated wallet connection for testing
- Provenance Tracking: View batch details and supply chain information
- Real-time Updates: New batches appear immediately in marketplace
- Form Validation: Comprehensive validation for batch creation
- Responsive Design: Works on desktop and mobile devices
- Blockchain Integration: Currently simulated (no real smart contracts)
- AI Analysis: Mock AI responses (no real ML models running)
- IPFS Storage: Simulated file storage
- Database: In-memory storage (data resets on restart)
- Wallet Transactions: Simulated (no real cryptocurrency transactions)
- Real Blockchain: Hardhat integration has dependency issues
- AI Models: TensorFlow Lite models not integrated
- File Upload: Image upload functionality not fully implemented
- User Authentication: No real user management system
- Payment Processing: No real escrow or payment system
The system comes with sample data:
- 2 Sample Batches: Tomatoes (Cherry) and Lettuce (Romaine)
- Mock Farmer Info: Green Valley Farm and Sunny Acres
- Sample Prices: 1 ETH and 0.5 ETH respectively
- Quality Scores: 85 and 92 respectively
- Connect Wallet: Use MetaMask to connect your wallet
- Create Farm: Register your farm with location and details
- Add Produce: Create batches with AI-powered quality analysis
- List for Sale: Set prices and list batches on marketplace
- Track Provenance: Add notes throughout the supply chain
- Browse Marketplace: Search and filter available produce
- View Details: Check quality scores, provenance, and farmer info
- Purchase: Fund escrow for secure transactions
- Verify Delivery: Confirm receipt and release payments
- Verify Data: Check AI analysis and quality scores
- Add Certifications: Validate organic/sustainable practices
- Monitor Compliance: Track adherence to standards
- On-device image analysis using MobileNet
- Real-time crop health assessment
- Treatment recommendations
- Multi-factor quality analysis (color, size, defects, freshness)
- Letter grade system (A+ to F)
- Market suitability recommendations
- Weather and soil condition analysis
- Historical data integration
- Production optimization suggestions
- Market trend analysis
- Seasonal price predictions
- Demand-supply dynamics
- Privacy-preserving model training
- Cross-farm knowledge sharing
- Continuous model improvement
- Batch Management: Create, list, and track produce batches
- Escrow System: Secure buyer-farmer transactions
- Quality Updates: Record AI analysis results
- Provenance: Append-only supply chain notes
- Incentives: Token rewards for verified data
// Create a new produce batch
function createBatch(string metadataCID, uint256 priceWei)
// Fund escrow for purchase
function fundEscrow(uint256 batchId)
// Mark as delivered
function markDelivered(uint256 batchId)
// Release funds to farmer
function releaseToFarmer(uint256 batchId)
// Add provenance note
function addProvenance(uint256 batchId, string noteCID)- Wallet address, role, verification status
- Incentive points and profile information
- Farm details, location, certifications
- Soil type and size information
- Crop details, quality scores, AI analysis
- Blockchain state and provenance tracking
# Start individual services
docker-compose up postgres ipfs hardhat
docker-compose up backend
docker-compose up frontend
docker-compose up ai-servicecd contract
npm install
npx hardhat compile
npx hardhat test
npx hardhat run scripts/deploy.js --network localhostcd backend
npm install
npm run devcd frontend
npm install
npm startcd ai
pip install -r requirements.txt
python app.py./scripts/test-api.shcd contract
npx hardhat testcd frontend
npm testThe system includes comprehensive sample data:
- 4 sample users (farmers, buyers, auditors)
- 3 sample farms with different characteristics
- 4 sample produce batches in various states
- Complete provenance tracking examples
- AI model performance data
- Market trend information
- Wallet Integration: MetaMask for secure transactions
- Escrow System: Funds held in smart contract until delivery
- Data Integrity: IPFS for immutable file storage
- Privacy: Federated learning preserves data privacy
- Verification: Multi-layer data validation
- Carbon Footprint Tracking: Monitor environmental impact
- Sustainable Practices: Reward eco-friendly farming
- Local Sourcing: Reduce transportation emissions
- Waste Reduction: AI-optimized harvest timing
- Deploy contracts to Polygon mainnet
- Set up production IPFS cluster
- Configure production database
- Deploy services to cloud infrastructure
- Set up monitoring and logging
# Backend
DB_HOST=localhost
DB_PORT=5432
DB_NAME=farmmate
RPC_URL=http://localhost:8545
IPFS_URL=http://localhost:5001
# Frontend
REACT_APP_API_URL=http://localhost:3001
REACT_APP_CONTRACT_ADDRESS=0x...
REACT_APP_RPC_URL=http://localhost:8545- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Check the documentation
- Review the sample data and test scripts
- Mobile app (React Native)
- Advanced ML models
- Carbon credit trading
- Insurance integration
- Multi-language support
FarmMate - Empowering farmers with technology, ensuring food security through transparency. ๐พโจ