Inspiration

Smallholder farmers in Kenya produce 75% of the nation's food, yet agricultural extension agents default to generic, homogenous fertilizer recommendations. Soil composition varies at the micro-level; applying diammonium phosphate to highly acidic soil results in guaranteed yield loss. AgriFusion bridges the critical gap between enterprise-grade agronomic science (the QUEFTS nutritional model) and edge-deployment realities (low-end Android devices with intermittent connectivity, and inaccessible high accuracy soil assesment hardware/sensors). The objective: deploy localized soil diagnostics directly to the field layer where it generates the highest economic return while accounting for accuracy and reliablity gaps in the methods or sensors available.

What it does

AgriFusion is an offline-first Progressive Web App (PWA) engineered for agricultural extension agents. It executes a structured 5-step soil assessment (field profile, visual scoring, chemical analysis, disease vectors, and crop history) and runs the data through a deterministic QUEFTS agronomic model. Factoring in data reliability, the system generates localized, scientifically rigorous fertilizer dosing.

An AI advisory layer (AWS Bedrock via Claude) leverages a GraphRAG pipeline against verified KALRO and FAO corpuses to synthesize actionable, WhatsApp-optimized advisories in both English and Swahili. The platform dynamically integrates 7-day Open-Meteo precipitation forecasts for application timing, executes PostGIS spatial queries to route farmers to the nearest stocked agro-dealers, and utilizes pgvector to cluster farms by agronomic similarity (pH, texture, history). A real-time manager dashboard aggregates sub-county analytics and agent performance metrics.

How we built it

Frontend Engine: Built as a React-based PWA utilizing IndexedDB for persistent, offline-first state management. The 5-step diagnostic wizard auto-saves continuously to prevent data loss in volatile hardware environments.

Dual-Compute Architecture:

Online Path: Data routes through Next.js server handlers to an Aurora PostgreSQL instance. The server calculates QUEFTS baselines, fetches 7-day weather APIs, runs PostGIS spatial proximity scans for agro-dealers, and executes pgvector cosine-similarity searches against agricultural literature. AWS Bedrock (Claude) synthesizes this strict context into bilingual advisories. Offline Path: The exact QUEFTS logic executes client-side utilizing pre-fetched iSDA spatial soil grids stored in IndexedDB. Synchronization: A custom SyncManager detects network restoration, batch-commits queued assessments via PostgreSQL transactions, and warms local caches with localized weather and soil geometries.

Management Layer: Managers access regional analytics driven by SQL aggregations, and utilize an NLP-to-SQL GraphRAG interface to query fleet data in natural language.

Challenges we ran into

Dual-State Architecture Overhead: Engineering parallel data flows (online API routing vs. offline IndexedDB compute) required redundant implementation of the QUEFTS engine and graceful degradation protocols, doubling the logic surface. Microservice Orchestration: The core /api/assess endpoint requires synchronous resolution of six distinct operations (QUEFTS logic → weather API → vector embeddings → pgvector similarity search → PostGIS spatial lookup → Bedrock LLM synthesis/translation). Handling cascading timeouts and failure states required aggressive error bounding. Agronomic Model Translation: Porting the mathematical QUEFTS fertilizer model into strict TypeScript required deep domain expertise and the management of a 4,800-line stoichiometric lookup table. Relational Schema Density: Managing 25+ tables combining standard relational constraints, PostGIS GEOGRAPHY types, and pgvector HNSW indexes necessitated highly rigid seeding scripts and migration sequencing. External API Volatility: The external iSDA soil API proved unstable, requiring the implementation of aggressive TTL token caching and robust offline mock-fallbacks to maintain system integrity.

Accomplishments that we're proud of

  • Deployed a zero-latency, offline-first PWA guaranteed to function on low-tier Android hardware without network access.
  • Engineered a deterministic, 3-tier fertilizer recommendation engine outputting precise chemical nomenclature, required bag counts, and projected KES expenditures.
  • Executed full systemic bilingual support (English/Swahili) across the entire UI and Bedrock-generated advisory outputs.
  • Eliminated LLM hallucination by restricting Bedrock inference strictly to retrieved KALRO/FAO document vectors (GraphRAG).
  • Integrated native PostGIS spatial queries to dynamically route farmers to the nearest stocked agro-dealers based on coordinate proximity.
  • Successfully seeded 120 complex, geographically dispersed demo assessments across 6 sub-counties to prove load and analytic integrity.

What we learned

  • State Management: Offline-first architecture cannot be retrofitted. Data flow must default to local cache and treat the network as an intermittent enhancement.
  • Infrastructure Synergy: Combining Aurora PostgreSQL, pgvector, and PostGIS within a single cluster eliminates the need for separate vector and spatial databases, drastically reducing operational complexity.
  • Domain Constraint: Algorithmic agriculture requires rigid mathematical models (QUEFTS) to bound LLMs. The science must dictate the logic; the LLM merely translates it.
  • RAG Efficacy: Context-restricted LLMs generate highly empathetic, technically accurate agricultural advisories when fed high-quality, domain-specific vector data.

What's next for AgriFusion

  • Deploy strict RBAC (Role-Based Access Control) authentication matrix for extension agents, regional managers, and system administrators.
  • Expand the QUEFTS agronomic model logic parameters to support Beans, Cassava, and Sorghum profiles.
  • Implement ServiceWorker push notifications for localized extreme weather events and background sync completion.
  • Execute localized field trials with active Kenyan agricultural extension units to validate UX and fertilizer output accuracy.

Built With

Share this project:

Updates

Submission history