Skip to content

ghwmelite-dotcom/AgroTrust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

44 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Platform SDG 2 Cloudflare License

🌱 AgroTrust

Digital Food Security & Farmer Credit Intelligence Platform
Empowering African Smallholder Farmers with Verifiable Digital Reputation

Problem β€’ Solution β€’ Features β€’ Tech Stack β€’ Getting Started β€’ Architecture


🌍 The Problem

70% of Africa's food is produced by smallholder farmers who face systemic barriers:

Challenge Impact
No Credit History Banks refuse loans to 80% of smallholders
Climate Uncertainty Unpredictable weather destroys harvests
Middlemen Exploitation Farmers receive only 20-30% of market value
Post-Harvest Losses 30-40% of produce lost due to poor storage/logistics
No Digital Identity Farmers are invisible to the formal economy

The vicious cycle: Banks don't trust farmers β†’ Farmers stay poor β†’ Food insecurity grows β†’ 282 million Africans face hunger.


πŸ’‘ Solution

AgroTrust creates a verifiable digital reputation for farmers, transforming farming activities into creditworthy data.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Farmer logs    │────▢│  AI verifies &   │────▢│  Credit score   β”‚
β”‚  crops/harvests β”‚     β”‚  builds trust    β”‚     β”‚  unlocks loans  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  Direct marketplace  β”‚
                    β”‚  (no middlemen)      β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

How It Works

  1. Register - Phone-based OTP authentication (works with feature phones via SMS)
  2. Add Farms - GPS-verified farm locations and sizes
  3. Track Crops - Log planting, growth stages, inputs used
  4. Verify Harvests - Photo + GPS + timestamp verification
  5. Build Credit - Every verified activity increases credit score
  6. Access Markets - Sell directly to buyers at fair prices
  7. Get Loans - Credit score unlocks microfinance opportunities

✨ Features

Core Features

Feature Description Credit Points
πŸ“± Offline-First PWA Works without internet, syncs when connected -
πŸ—ΊοΈ Farm Mapping GPS-verified farm boundaries +15 pts
🌾 Crop Tracking Full crop lifecycle management -
πŸ“Έ Harvest Verification Photo + location proof of harvest +25 pts
πŸ“Š Credit Scoring Transparent, activity-based scoring -
πŸ›’ Digital Marketplace Direct farmer-to-buyer sales +20 pts
🌀️ Weather Alerts Climate-smart recommendations +10 pts
πŸ“² SMS/USSD Support For farmers without smartphones -

Credit Score System

Score Range    β”‚ Category   β”‚ Benefits
───────────────┼────────────┼─────────────────────────────
0 - 300        β”‚ Poor       β”‚ Basic marketplace access
300 - 500      β”‚ Fair       β”‚ Verified seller badge
500 - 700      β”‚ Good       β”‚ Priority buyer matching
700 - 850      β”‚ Excellent  β”‚ Microfinance eligibility

πŸ› οΈ Tech Stack

100% Cloudflare-Native Architecture for global edge performance:

Layer Technology Purpose
Frontend Next.js 14 + PWA Offline-first mobile experience
API Hono.js on Workers Edge-native, <50ms latency in Africa
Database Cloudflare D1 SQLite at the edge, GDPR compliant
Storage Cloudflare R2 Cost-effective photo storage
Cache Cloudflare KV Session management, API caching
ORM Drizzle ORM Type-safe database queries
Validation Zod Runtime type checking
Offline Sync Dexie.js IndexedDB with conflict resolution
Styling Tailwind CSS Utility-first, mobile-optimized

Why Cloudflare?

  • 🌍 African Edge Presence - Data centers in Johannesburg, Lagos, Nairobi, Cairo
  • πŸ’° Cost Effective - Free tier supports MVP, scales affordably
  • ⚑ Performance - <100ms response times across Africa
  • πŸ”’ Security - DDoS protection, SSL by default
  • πŸ“± Offline-First - Service workers + D1 enable true offline

πŸš€ Getting Started

Prerequisites

  • Node.js 20+
  • pnpm 9+
  • Cloudflare account (free tier works)

Quick Start

# Clone repository
git clone https://github.com/ghwmelite-dotcom/AgroTrust.git
cd AgroTrust

# Install dependencies
pnpm install

# Set up environment files
cp apps/api/.dev.vars.example apps/api/.dev.vars
cp apps/web/.env.example apps/web/.env.local

# Create Cloudflare resources
npx wrangler d1 create agrotrust-db
npx wrangler r2 bucket create agrotrust-photos
npx wrangler kv namespace create KV

# Update apps/api/wrangler.toml with generated IDs

# Run database migrations
cd packages/db && npx drizzle-kit generate:sqlite
cd ../../apps/api && npx wrangler d1 execute agrotrust-db --local --file=../../packages/db/migrations/0000_*.sql

# Start development
pnpm dev

Development URLs

Service URL
Web App http://localhost:3000
API http://localhost:8787

πŸ“ Architecture

agrotrust/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ api/                    # Hono API on Cloudflare Workers
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ routes/         # API endpoints
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth.ts     # OTP authentication
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ farmers.ts  # Farmer profiles & credit
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ farms.ts    # Farm management
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ crops.ts    # Crop cycle tracking
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ harvests.ts # Harvest verification
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ listings.ts # Marketplace
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ sync.ts     # Offline sync
β”‚   β”‚   β”‚   β”‚   └── upload.ts   # R2 photo uploads
β”‚   β”‚   β”‚   β”œβ”€β”€ middleware/     # Auth middleware
β”‚   β”‚   β”‚   └── index.ts        # App entry point
β”‚   β”‚   └── wrangler.toml       # Workers config
β”‚   β”‚
β”‚   └── web/                    # Next.js PWA on Cloudflare Pages
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ app/            # App Router pages
β”‚       β”‚   β”œβ”€β”€ components/     # React components
β”‚       β”‚   β”œβ”€β”€ hooks/          # Custom hooks
β”‚       β”‚   └── lib/            # Utilities
β”‚       └── public/             # PWA assets
β”‚
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ db/                     # Drizzle ORM + D1 schema
β”‚   β”‚   └── src/schema/         # Database tables
β”‚   β”œβ”€β”€ shared/                 # Shared code
β”‚   β”‚   β”œβ”€β”€ schemas/            # Zod validation schemas
β”‚   β”‚   β”œβ”€β”€ types/              # TypeScript types
β”‚   β”‚   └── constants/          # App constants (crops, etc.)
β”‚   └── sync/                   # Offline sync engine
β”‚       β”œβ”€β”€ offline-db.ts       # Dexie.js setup
β”‚       β”œβ”€β”€ sync-engine.ts      # Sync logic
β”‚       └── hooks.ts            # React hooks
β”‚
└── turbo.json                  # Monorepo config

Database Schema

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   farmers   │────▢│    farms    │────▢│    crop_cycles      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                                          β”‚
       β”‚            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
       └───────────▢│  listings   β”‚               β”‚
       β”‚            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β–Ό
       β”‚                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚                              β”‚ harvest_verificationsβ”‚
       β–Ό                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚credit_events β”‚  (Immutable audit trail)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‘ API Reference

Authentication

# Request OTP
POST /auth/otp/request
{ "phone": "+254712345678" }

# Verify OTP
POST /auth/otp/verify
{ "phone": "+254712345678", "code": "123456" }

# Register (new users)
POST /auth/register
{ "phone": "...", "firstName": "...", "lastName": "...", "address": {...}, "registrationToken": "..." }

Protected Endpoints (Bearer token required)

# Farmer
GET    /api/farmers/me           # Get profile
PATCH  /api/farmers/me           # Update profile
GET    /api/farmers/me/credit    # Credit score breakdown
GET    /api/farmers/me/dashboard # Dashboard data

# Farms
GET    /api/farms                # List farms
POST   /api/farms                # Create farm (+15 pts)
GET    /api/farms/:id            # Get farm
PATCH  /api/farms/:id            # Update farm
DELETE /api/farms/:id            # Delete farm

# Crops
GET    /api/crops                # List crop cycles
POST   /api/crops                # Start crop cycle
PATCH  /api/crops/:id            # Update cycle
POST   /api/crops/:id/harvest    # Mark harvested

# Harvest Verification
POST   /api/harvests             # Submit verification (+25 pts)

# Marketplace
GET    /api/listings             # Browse (public)
GET    /api/listings/my          # My listings
POST   /api/listings             # Create listing
POST   /api/listings/:id/sold    # Mark sold (+20 pts)

# Sync (offline support)
GET    /api/sync/changes         # Pull changes
POST   /api/sync/push            # Push changes
POST   /api/sync/resolve         # Resolve conflicts

🌐 Localization

Supported languages for African markets:

Code Language Region
en English Pan-African
sw Swahili East Africa
ha Hausa West Africa
am Amharic Ethiopia
fr French Francophone Africa
pt Portuguese Lusophone Africa

🎯 SDG Alignment

AgroTrust directly contributes to UN Sustainable Development Goals:

SDG Goal How AgroTrust Contributes
🍽️ SDG 2 Zero Hunger Increases farmer productivity & market access
πŸ’° SDG 1 No Poverty Enables financial inclusion for smallholders
πŸ‘©β€πŸŒΎ SDG 5 Gender Equality Empowers women farmers with digital identity
🏭 SDG 8 Decent Work Creates transparent, fair agricultural markets
🌑️ SDG 13 Climate Action Provides climate-smart farming recommendations

πŸ›£οΈ Roadmap

  • Phase 1: MVP - Core platform (Farmer profiles, farms, crops, credit)
  • Phase 2: AI - Yield prediction, pest detection from photos
  • Phase 3: Fintech - Microfinance partner integrations
  • Phase 4: Scale - SMS/USSD for feature phones, multi-country expansion

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines.

# Fork and clone
git clone https://github.com/YOUR_USERNAME/AgroTrust.git

# Create feature branch
git checkout -b feature/amazing-feature

# Make changes and commit
git commit -m "Add amazing feature"

# Push and create PR
git push origin feature/amazing-feature

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

  • Cloudflare for edge infrastructure
  • African farming communities for inspiration
  • Open source contributors

Built with ❀️ for African Farmers
Transforming agriculture through technology

Report Bug β€’ Request Feature

About

🌱 Digital Food Security & Farmer Credit Intelligence Platform for African Smallholder Farmers | Cloudflare-native | Offline-first PWA | SDG 2: Zero Hunger

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages