Digital Food Security & Farmer Credit Intelligence Platform
Empowering African Smallholder Farmers with Verifiable Digital Reputation
Problem β’ Solution β’ Features β’ Tech Stack β’ Getting Started β’ Architecture
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.
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) β
ββββββββββββββββββββββββ
- Register - Phone-based OTP authentication (works with feature phones via SMS)
- Add Farms - GPS-verified farm locations and sizes
- Track Crops - Log planting, growth stages, inputs used
- Verify Harvests - Photo + GPS + timestamp verification
- Build Credit - Every verified activity increases credit score
- Access Markets - Sell directly to buyers at fair prices
- Get Loans - Credit score unlocks microfinance opportunities
| 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 | - |
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
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 |
- π 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
- Node.js 20+
- pnpm 9+
- Cloudflare account (free tier works)
# 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| Service | URL |
|---|---|
| Web App | http://localhost:3000 |
| API | http://localhost:8787 |
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
βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ
β farmers ββββββΆβ farms ββββββΆβ crop_cycles β
βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ
β β
β βββββββββββββββ β
βββββββββββββΆβ listings β β
β βββββββββββββββ βΌ
β βββββββββββββββββββββββ
β β harvest_verificationsβ
βΌ βββββββββββββββββββββββ
ββββββββββββββββ
βcredit_events β (Immutable audit trail)
ββββββββββββββββ
# 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": "..." }# 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 conflictsSupported 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 |
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 |
- 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
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-featureThis project is licensed under the MIT License - see the LICENSE file for details.
- Cloudflare for edge infrastructure
- African farming communities for inspiration
- Open source contributors
Built with β€οΈ for African Farmers
Transforming agriculture through technology