Skip to content

Rahnuma is an AI-powered agricultural platform designed to empower Pakistani farmers with intelligent guidance, smart irrigation planning, fertilizer optimization, energy tracking, and a blockchain-based marketplace.

Notifications You must be signed in to change notification settings

MuhammadAbyaz/rahnuma

Repository files navigation

راہ نُما (Rahnuma) - AI-Powered Agriculture Platform

Every farmer's guide β€” from knowledge to prosperity

Rahnuma is an AI-powered agricultural platform designed to empower Pakistani farmers with intelligent guidance, smart irrigation planning, fertilizer optimization, energy tracking, and a blockchain-based marketplace. The platform supports Urdu and English languages to bridge the digital divide for farmers.

🌟 Features

1. AI Chatbot Assistant

  • Natural language conversations in Urdu and English
  • Voice and text input support
  • Instant answers to farming questions
  • Weather information and market insights
  • Available 24/7 for farmers

2. Water Management

  • Smart irrigation scheduling based on crop, soil, and weather data
  • Water savings predictions and cost reduction estimates
  • Weather integration for optimal watering decisions
  • Daily reminder notifications

3. Fertilizer Optimizer

  • Precise fertilizer recommendations based on crop and soil analysis
  • Organic farming alternatives and tips
  • Prevents overuse and chemical damage
  • Cost-saving suggestions

4. Energy Tracker

  • Monitor farm energy consumption (electricity and diesel)
  • Track tube well and machinery usage
  • Solar power recommendations with ROI calculations
  • Efficiency optimization tips

5. Blockchain Marketplace

  • Transparent buying and selling of agricultural products
  • Blockchain-based transaction records
  • Direct farmer-to-buyer connections
  • No middlemen, fair pricing
  • Support for multiple roles: Farmers, Retailers, Distributors

πŸ› οΈ Tech Stack

Frontend

  • Next.js 15 - React framework with App Router
  • React 19 - UI library
  • TypeScript - Type safety
  • Tailwind CSS 4 - Styling
  • Framer Motion - Animations
  • Radix UI - Accessible UI components
  • React Hook Form - Form management
  • Zod - Schema validation

Backend & Database

  • Next.js API Routes - Server-side endpoints
  • PostgreSQL - Primary database
  • Drizzle ORM - Database toolkit
  • NextAuth.js v5 - Authentication (Google OAuth)

AI & Integrations

  • AI SDK - AI integration framework
  • Google Gemini AI - Primary AI model
  • Groq - Fast AI inference
  • Tavily - Web search for real-time information
  • OpenWeather API - Weather data

Blockchain

  • Hardhat - Smart contract development
  • Ethers.js v6 - Ethereum interactions
  • Polygon (Amoy testnet) - Blockchain network
  • Solidity - Smart contract language

Storage & Services

  • Supabase Storage - Image uploads
  • PostgreSQL - Relational database

πŸ“‹ Prerequisites

  • Node.js 20+ and pnpm 10+
  • PostgreSQL database
  • Google OAuth credentials
  • API Keys: Google Gemini, Groq, Tavily, OpenWeather
  • Blockchain: Polygon Amoy testnet (or mainnet) setup

πŸš€ Getting Started

1. Clone the repository

git clone <repository-url>
cd rahnuma

2. Install dependencies

pnpm install

3. Set up environment variables

Create a .env file in the root directory with the following variables:

# Database
DATABASE_URL="postgresql://user:password@localhost:5432/rahnuma"

# Authentication
AUTH_SECRET="your-auth-secret-key"
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"

# AI Services
GOOGLE_GENERATIVE_AI_API_KEY="your-gemini-api-key"
GROQ_API_KEY="your-groq-api-key"
TAVILY_API_KEY="your-tavily-api-key"

# Weather API
NEXT_PUBLIC_OPENWEATHER_API_KEY="your-openweather-api-key"

# Supabase
NEXT_PUBLIC_SUPABASE_URL="your-supabase-url"
NEXT_PUBLIC_SUPABASE_ANON_KEY="your-supabase-anon-key"
NEXT_PUBLIC_BUCKET_NAME="your-bucket-name"

# Blockchain (Optional)
DEPLOYER_PRIVATE_KEY="your-deployer-private-key"
ALCHEMY_RPC_URL="https://polygon-amoy.g.alchemy.com/v2/your-key"
POLYGONSCAN_API_KEY="your-polygonscan-api-key"
WALLET_ENCRYPTION_KEY="your-wallet-encryption-key"
GAS_RELAYER_PRIVATE_KEY="your-gas-relayer-private-key"

# Contract Address (after deployment)
NEXT_PUBLIC_CONTRACT_ADDRESS="your-contract-address"
NEXT_PUBLIC_RPC_URL="your-rpc-url"
NEXT_PUBLIC_CHAIN_ID="80002"  # Polygon Amoy testnet

4. Set up the database

# Generate migration files
pnpm db:generate

# Push schema to database
pnpm db:push

# Or run migrations
pnpm db:migrate

5. Deploy smart contracts (Optional)

# Compile contracts
pnpm contracts:compile

# Deploy to Amoy testnet
pnpm contracts:deploy

# Deploy to Polygon mainnet
pnpm contracts:deploy:mainnet

6. Run the development server

pnpm dev

The application will be available at http://localhost:3000

πŸ“œ Available Scripts

Development

  • pnpm dev - Start development server with Turbopack
  • pnpm build - Build for production
  • pnpm start - Start production server
  • pnpm preview - Build and preview production build

Code Quality

  • pnpm lint - Run ESLint
  • pnpm lint:fix - Fix ESLint errors
  • pnpm typecheck - Run TypeScript type checking
  • pnpm format:check - Check code formatting
  • pnpm format:write - Format code with Prettier
  • pnpm check - Run lint and typecheck together

Database

  • pnpm db:generate - Generate Drizzle migration files
  • pnpm db:push - Push schema changes to database
  • pnpm db:migrate - Run database migrations
  • pnpm db:studio - Open Drizzle Studio

Blockchain

  • pnpm contracts:compile - Compile Hardhat contracts
  • pnpm contracts:deploy - Deploy contracts to Amoy testnet
  • pnpm contracts:deploy:mainnet - Deploy to Polygon mainnet
  • pnpm contracts:verify - Verify contracts on Polygonscan
  • pnpm generate-wallets - Generate custodial wallets
  • pnpm fund-gas-wallet - Fund the gas relayer wallet

πŸ“ Project Structure

rahnuma/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                    # Next.js App Router
β”‚   β”‚   β”œβ”€β”€ (dashboard)/        # Protected dashboard routes
β”‚   β”‚   β”‚   β”œβ”€β”€ energy-tracking/
β”‚   β”‚   β”‚   β”œβ”€β”€ fertilizer-optimizer/
β”‚   β”‚   β”‚   β”œβ”€β”€ marketplace/
β”‚   β”‚   β”‚   β”œβ”€β”€ water-management/
β”‚   β”‚   β”‚   β”œβ”€β”€ profile/
β”‚   β”‚   β”‚   └── layout.tsx
β”‚   β”‚   β”œβ”€β”€ api/                # API routes
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”‚   β”œβ”€β”€ blockchain/
β”‚   β”‚   β”‚   β”œβ”€β”€ chat/
β”‚   β”‚   β”‚   β”œβ”€β”€ listings/
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”œβ”€β”€ login/
β”‚   β”‚   β”œβ”€β”€ onboarding/
β”‚   β”‚   β”œβ”€β”€ layout.tsx
β”‚   β”‚   └── page.tsx            # Landing page
β”‚   β”œβ”€β”€ components/             # React components
β”‚   β”‚   β”œβ”€β”€ ai/                 # AI chat components
β”‚   β”‚   β”œβ”€β”€ marketplace/        # Marketplace components
β”‚   β”‚   β”œβ”€β”€ ui/                 # Reusable UI components
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ constants/              # Translation constants
β”‚   β”‚   β”œβ”€β”€ en.ts               # English translations
β”‚   β”‚   β”œβ”€β”€ ur.ts               # Urdu translations
β”‚   β”‚   └── prompts.ts          # AI prompts
β”‚   β”œβ”€β”€ contexts/               # React contexts
β”‚   β”œβ”€β”€ hooks/                  # Custom React hooks
β”‚   β”œβ”€β”€ lib/                    # Utility libraries
β”‚   β”‚   β”œβ”€β”€ services/           # Business logic services
β”‚   β”‚   β”œβ”€β”€ utils/              # Utility functions
β”‚   β”‚   └── schemas/            # Zod schemas
β”‚   β”œβ”€β”€ server/                 # Server-side code
β”‚   β”‚   β”œβ”€β”€ auth/               # Authentication config
β”‚   β”‚   └── db/                  # Database schema and config
β”‚   β”œβ”€β”€ styles/                 # Global styles
β”‚   └── types/                  # TypeScript type definitions
β”œβ”€β”€ contracts/                  # Solidity smart contracts
β”‚   └── RahnumaMarketplace.sol
β”œβ”€β”€ drizzle/                    # Database migration files
β”œβ”€β”€ scripts/                    # Utility scripts
β”œβ”€β”€ public/                     # Static assets
β”œβ”€β”€ hardhat.config.cjs         # Hardhat configuration
β”œβ”€β”€ drizzle.config.ts           # Drizzle configuration
β”œβ”€β”€ next.config.js              # Next.js configuration
β”œβ”€β”€ tailwind.config.js          # Tailwind CSS configuration
└── package.json

🌐 Language Support

Rahnuma supports bilingual interface:

  • English - Full application support
  • Urdu - Full application support with RTL layout

Users can switch between languages using the language selector in the header.

πŸ” Authentication

The platform uses NextAuth.js with Google OAuth for authentication. Users need to:

  1. Sign in with Google
  2. Select their role (Farmer, Retailer, or Distributor)
  3. Access platform features based on their role

πŸ—οΈ Architecture

Frontend Architecture

  • Next.js App Router - File-based routing with server and client components
  • Server Components - For data fetching and SEO optimization
  • Client Components - For interactivity and state management
  • API Routes - RESTful API endpoints for backend operations

Database Schema

  • Users - Authentication and user profiles
  • Listings - Agricultural product listings
  • Transactions - Purchase/sale transactions
  • Supply Chain Events - Transaction lifecycle tracking

Blockchain Integration

  • Custodial Wallets - Server-managed wallets for users
  • Gas Relayer - Platform pays for transaction fees
  • Smart Contracts - Marketplace operations on-chain
  • Polygon Network - Low-cost, fast transactions

🚒 Deployment

Environment Setup

  1. Set up PostgreSQL database (Supabase, Railway, or self-hosted)
  2. Configure environment variables for production
  3. Set up Supabase storage for image uploads
  4. Deploy smart contracts to Polygon network
  5. Configure domain and SSL certificates

Build for Production

pnpm build
pnpm start

πŸ“ License

This project is private and proprietary.

πŸ‘₯ Contributing

This is a private project. For contributions, please contact the project maintainers.

πŸ“§ Support

For support and inquiries, please contact through the platform's support channels.


Built with ❀️ for Pakistani Farmers

About

Rahnuma is an AI-powered agricultural platform designed to empower Pakistani farmers with intelligent guidance, smart irrigation planning, fertilizer optimization, energy tracking, and a blockchain-based marketplace.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •