Skip to content

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

ย 
ย 

Latest commit

ย 

History

8 Commits

Folders and files

Repository files navigation

Agroflow Logo

Agroflow ๐ŸŒพ

Smart Agriculture Platform with IoT Monitoring, Blockchain NFT Traceability & AI-Powered Insights

About โ€ข Features โ€ข Demo โ€ข Tech Stack โ€ข Setup โ€ข Blockchain โ€ข API

Next.js Polygon Supabase Gemini AI ESP32


๐Ÿ“‹ About

Agroflow is a comprehensive smart agriculture platform that bridges the gap between traditional farming and modern technology. It combines IoT sensor monitoring, blockchain-based traceability, and AI-powered recommendations to help farmers optimize their operations while providing consumers with transparent, verifiable information about their food's origin.

๐ŸŽฏ The Problem We Solve

  1. Lack of Transparency โ€“ Consumers have no way to verify if produce is truly organic or where it came from
  2. Manual Monitoring โ€“ Farmers manually check soil/weather conditions, leading to inefficiencies
  3. Food Fraud โ€“ Fake organic labels and untraceable supply chains erode consumer trust
  4. Data Silos โ€“ Farming data isn't leveraged for intelligent decision-making

๐Ÿ’ก Our Solution

Agroflow provides an end-to-end platform that:

  • ๐Ÿ“ก Monitors farms in real-time using ESP32 IoT sensors (temperature, humidity, soil moisture)
  • ๐Ÿ”— Creates immutable blockchain records for every harvest batch as NFTs on Polygon
  • ๐Ÿ“ฑ Enables consumer verification by scanning QR codes to see the complete journey of their food
  • ๐Ÿค– Delivers AI-powered insights via a multilingual chatbot (8+ Indian languages)
  • ๐Ÿ’ง Automates irrigation based on soil moisture thresholds

โœจ Features

๐ŸŒก๏ธ Real-Time IoT Monitoring

  • Live sensor data from ESP32 devices (DHT22 + Soil Moisture)
  • Beautiful dashboard with trend charts and analytics
  • Automatic data logging to Supabase every 30 seconds
  • Alert system for critical conditions (low moisture, high temperature)

๐Ÿ”— Blockchain Traceability (NFT Certificates)

  • Mint harvest batches as ERC-721 NFTs on Polygon Amoy
  • Each batch gets a unique QR code for product packaging
  • Consumers can scan QR codes to verify authenticity on-chain
  • Immutable record of: crop type, planting date, farm location, organic status
  • Real MetaMask integration for signing blockchain transactions

๐Ÿค– AI-Powered AgriBot

  • Smart farming assistant powered by Google Gemini 2.5 Flash
  • Supports 8+ Indian languages: Hindi, Tamil, Telugu, Kannada, Malayalam, Bengali, Marathi, Gujarati
  • Context-aware answers using real sensor data from your farm
  • Intelligent fallback responses when API is unavailable
  • Voice-like conversational interface

๐Ÿ’ง Smart Irrigation Control

  • Automatic pump activation when soil moisture drops below threshold
  • Manual override from the dashboard
  • Irrigation history and water usage logs
  • Configurable thresholds per zone

๐Ÿ“ฑ Additional Features

  • Weather Forecasting โ€“ 3-day forecast with farming recommendations
  • Crop Recommendations โ€“ AI-suggested crops based on current conditions
  • Multi-Zone Support โ€“ Manage different areas of your farm
  • Mobile-Responsive Design โ€“ Full functionality on all devices
  • Dark Mode โ€“ Easy on the eyes for night monitoring

๐Ÿ› ๏ธ Tech Stack

Category Technology
Frontend Next.js 15, React 19, TailwindCSS, Shadcn UI, Framer Motion
Backend Next.js API Routes, Supabase (PostgreSQL + RLS)
Blockchain Polygon Amoy Testnet, Solidity 0.8.20, ethers.js v6, MetaMask
Smart Contract ERC-721 (OpenZeppelin), Hardhat
AI/ML Google Gemini 2.5 Flash API
IoT ESP32 DevKit, DHT22 Sensor, Capacitive Soil Moisture Sensor
Charts Recharts
QR Codes qrcode (npm), browser-native scanning

๐Ÿš€ Getting Started

Prerequisites

  • Node.js 18+ and npm
  • Supabase account (free tier works)
  • Google Gemini API key (free tier: 15 RPM)
  • MetaMask wallet (for blockchain features)
  • ESP32 + Sensors (optional, for IoT features)

Quick Installation

# Clone the repository
git clone https://github.com/Devvaibhavpk/Agroflow.git
cd Agroflow

# Install dependencies
npm install

# Copy environment template
cp .env.local.example .env.local

# Start development server
npm run dev

Open http://localhost:3000 ๐ŸŽ‰

Environment Variables

Create .env.local with these values:

# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# REQUIRED
# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

# Supabase Database
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key_here

# Google Gemini AI (for chatbot)
GEMINI_API_KEY=your_gemini_api_key

# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# BLOCKCHAIN (Pre-configured for demo)
# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

NEXT_PUBLIC_NFT_CONTRACT_ADDRESS=0x8e205B621E7D122C8B1FD2695080A5Ea31280709
NEXT_PUBLIC_POLYGON_RPC_URL=https://rpc-amoy.polygon.technology
NEXT_PUBLIC_CHAIN_ID=80002

Database Setup

Run these SQL scripts in Supabase SQL Editor (in order):

  1. supabase/setup.sql โ€“ Core tables (sensor_data, zones, users)
  2. supabase/blockchain_tables.sql โ€“ Harvest batches, blockchain logs
  3. supabase/fix_rls.sql โ€“ Relaxed RLS for demo mode โš ๏ธ
  4. supabase/sample_data.sql โ€“ Optional demo data

๐Ÿ”— Blockchain

Deployed Smart Contract

The AgroflowNFT contract is live on Polygon Amoy Testnet:

Property Value
Contract Address 0x8e205B621E7D122C8B1FD2695080A5Ea31280709
Network Polygon Amoy (Chain ID: 80002)
Token Symbol AGRO
Token Standard ERC-721
Explorer View on PolygonScan

How NFT Traceability Works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  1. Create  โ”‚ โ†’  โ”‚ 2. Generate โ”‚ โ†’  โ”‚  3. Mint    โ”‚ โ†’  โ”‚  4. Verify  โ”‚
โ”‚   Batch     โ”‚    โ”‚   QR Code   โ”‚    โ”‚    NFT      โ”‚    โ”‚  on Chain   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    Farmer logs        Unique ID          MetaMask          Consumer
    harvest data       assigned          signs tx           scans QR

Smart Contract Functions

// Mint a new harvest batch NFT
function mintBatch(address to, string qrCodeId, bytes32 dataHash, string uri) โ†’ uint256

// Look up token by QR code
function getTokenByQrCode(string qrCodeId) โ†’ uint256

// Verify data integrity
function verifyIntegrity(uint256 tokenId, bytes32 dataHash) โ†’ bool

// Get batch details
function getBatchInfo(uint256 tokenId) โ†’ (owner, qrCodeId, dataHash, uri)

Deploy Your Own Contract

See contracts/DEPLOYMENT.md for step-by-step instructions using Hardhat or Remix.


๐Ÿ“ก API Reference

Core Endpoints

Endpoint Method Description
/api/ask POST AI chatbot with multilingual support
/api/harvest GET Fetch all harvest batches
/api/harvest POST Create new harvest batch
/api/harvest PUT Update batch / Mint as NFT
/api/verify?qr_code_id=XX GET Public verification endpoint
/api/weather GET Weather forecast data
/api/recommendations GET AI crop recommendations
/api/nft-metadata/[qrCodeId] GET NFT metadata (for OpenSea)

Example: AI Chatbot

curl -X POST http://localhost:3000/api/ask \
  -H "Content-Type: application/json" \
  -d '{
    "question": "เคฎเฅ‡เคฐเฅ€ เคซเคธเคฒ เค•เฅ‡ เคฒเคฟเค เคธเคฌเคธเฅ‡ เค…เคšเฅเค›เคพ เคธเคฎเคฏ เค•เฅเคฏเคพ เคนเฅˆ?",
    "language": "hindi"
  }'

Example: Create Batch

curl -X POST http://localhost:3000/api/harvest \
  -H "Content-Type: application/json" \
  -d '{
    "cropName": "Tomato",
    "cropVariety": "Roma",
    "plantingDate": "2026-01-15",
    "farmLocation": "Chennai, Tamil Nadu",
    "isOrganic": true
  }'

๐Ÿ”Œ ESP32 IoT Setup

Hardware Required

Component Purpose GPIO
ESP32 DevKit Main controller -
DHT22 Temperature & Humidity GPIO 4
Soil Moisture Sensor Soil monitoring GPIO 34 (ADC)
5V Relay Module Pump control GPIO 26
Water Pump Irrigation Via Relay

Wiring Diagram

ESP32                    Sensors
โ”€โ”€โ”€โ”€โ”€                    โ”€โ”€โ”€โ”€โ”€โ”€โ”€
GPIO 4  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ DHT22 Data
GPIO 34 โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Moisture Sensor (Analog)
GPIO 26 โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Relay IN (Pump Control)
3.3V    โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ DHT22 VCC
5V      โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Relay VCC, Moisture VCC
GND     โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ All GND

Firmware Setup

  1. Open esp32/agroflow_firmware.ino in Arduino IDE
  2. Install required libraries: DHT sensor library, ArduinoJson, WiFi
  3. Update credentials:
    const char* ssid = "YOUR_WIFI_SSID";
    const char* password = "YOUR_WIFI_PASSWORD";
    const char* supabaseUrl = "https://your-project.supabase.co";
    const char* supabaseKey = "your_anon_key";
  4. Upload to ESP32
  5. Open Serial Monitor (115200 baud) to verify connection

See esp32/README.md for detailed troubleshooting.


๐Ÿ“ Project Structure

Agroflow/
โ”œโ”€โ”€ app/                      # Next.js App Router
โ”‚   โ”œโ”€โ”€ api/                  # API Routes
โ”‚   โ”‚   โ”œโ”€โ”€ ask/              # AI Chatbot
โ”‚   โ”‚   โ”œโ”€โ”€ harvest/          # Batch CRUD
โ”‚   โ”‚   โ”œโ”€โ”€ verify/           # Public verification
โ”‚   โ”‚   โ””โ”€โ”€ nft-metadata/     # NFT metadata endpoint
โ”‚   โ”œโ”€โ”€ dashboard/            # Main monitoring dashboard
โ”‚   โ”œโ”€โ”€ traceability/         # NFT minting interface
โ”‚   โ”œโ”€โ”€ verify/[qrCodeId]/    # Consumer verification page
โ”‚   โ”œโ”€โ”€ chatbot/              # AI assistant page
โ”‚   โ”œโ”€โ”€ settings/             # User preferences
โ”‚   โ”œโ”€โ”€ docs/                 # Documentation
โ”‚   โ””โ”€โ”€ about/                # About page
โ”œโ”€โ”€ components/               # React components
โ”‚   โ”œโ”€โ”€ WalletConnect.tsx     # MetaMask integration
โ”‚   โ””โ”€โ”€ ui/                   # Shadcn UI components
โ”œโ”€โ”€ contracts/                # Solidity smart contracts
โ”‚   โ”œโ”€โ”€ src/AgroflowNFT.sol   # Main ERC-721 contract
โ”‚   โ”œโ”€โ”€ scripts/deploy.js     # Hardhat deploy script
โ”‚   โ””โ”€โ”€ DEPLOYMENT.md         # Deployment guide
โ”œโ”€โ”€ esp32/                    # ESP32 Arduino firmware
โ”‚   โ”œโ”€โ”€ agroflow_firmware.ino # Main firmware
โ”‚   โ””โ”€โ”€ README.md             # Hardware setup guide
โ”œโ”€โ”€ lib/                      # Utility libraries
โ”‚   โ”œโ”€โ”€ wallet.ts             # MetaMask/blockchain utils
โ”‚   โ”œโ”€โ”€ supabase.ts           # Database client
โ”‚   โ””โ”€โ”€ blockchain.ts         # Hash functions
โ”œโ”€โ”€ supabase/                 # Database scripts
โ”‚   โ”œโ”€โ”€ setup.sql             # Core tables
โ”‚   โ”œโ”€โ”€ blockchain_tables.sql # NFT tables
โ”‚   โ”œโ”€โ”€ fix_rls.sql           # RLS policies
โ”‚   โ””โ”€โ”€ sample_data.sql       # Demo data
โ””โ”€โ”€ public/                   # Static assets

๐ŸŽฅ Demo

Live Pages

Page Description
/ Landing page with feature overview
/dashboard Real-time sensor monitoring
/traceability Create batches & mint NFTs
/chatbot AI farming assistant
/verify/[qrCodeId] Consumer verification
/docs API documentation

Test NFT Minting

  1. Get test MATIC from Polygon Faucet
  2. Connect MetaMask to Polygon Amoy
  3. Go to /traceability โ†’ Create batch โ†’ Mint NFT
  4. View your NFT on PolygonScan

๐Ÿค Contributing

We welcome contributions! Here's how:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License โ€“ see LICENSE for details.


๐Ÿ‘ฅ Team

Built with โค๏ธ for sustainable agriculture and transparent food supply chains.

Repository: github.com/Devvaibhavpk/Agroflow


๐ŸŒฑ Empowering Farmers โ€ข Connecting Consumers โ€ข Securing the Food Chain ๐ŸŒฑ

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages