Skip to content

Botanical APIs and Data Pipeline

Oussama Elhadji edited this page Nov 7, 2026 · 1 revision

Botanical APIs & Automated Image Pipeline 🌐🧬

LKHODRA integrates live open-access botanical, nutritional, and agro-meteorological APIs alongside a deterministic local image pipeline so the application works both online and 100% offline.


🌐 Live Agro-Botanical APIs (src/services/agroApis.ts)

API Provider Endpoint / Service Purpose in LKHODRA Authentication
Open-Meteo Agro-Climate API https://api.open-meteo.com/v1/forecast Real-time temperature, relative humidity, soil moisture, and reference evapotranspiration (ET0) across all 8 Moroccan agricultural terroir regions Free / No API Key
GBIF (Global Biodiversity Information Facility) https://api.gbif.org/v1/species/match Taxonomic verification, kingdom/family hierarchy, and Moroccan occurrence records by binomial scientific name Free / No API Key
Open Food Facts API https://world.openfoodfacts.org/cgi/search.pl Cross-referencing Nutri-Score, NOVA food group, and macronutrient profiles Free / No API Key
Wikidata & Wikipedia REST API https://en.wikipedia.org/w/api.php Botanical lead imagery, multilingual taxonomy, and ethnobotanical references Free / No API Key

🖼️ Automated Botanical Image Pipeline (scripts/fetch-all-produce-images.ts)

To guarantee zero broken images (0% 404) and zero repetitive pictures, LKHODRA uses an automated TypeScript pipeline (scripts/fetch-all-produce-images.ts):

  1. Primary Image Download (public/images/produce/<id>-1.jpg):
    • Queries Wikipedia's pageimages API and Wikimedia Commons' generator=search API using each species' exact binomial scientificName and English cultivar name.
    • Filters out non-photographic files (maps, distribution charts, herbarium sheets, .svg, .tif, .pdf).
    • Downloads all 108 species' primary images locally into public/images/produce/<id>-1.jpg and precaches them via Workbox PWA.
  2. 3-Photo Non-Repetitive Gallery Registry (src/data/verifiedProduceImages.ts):
    • Maintains a global Set (globalUsedRemoteUrls) across the entire catalog run so no two species ever share the same image URL and every species has 3 distinct gallery photos (1. Whole, 2. Inside/Cut, 3. Terroir/Culinary).
  3. Automatic Local Fallback:
    • Both ProduceCard.tsx and ProduceModal.tsx attach an onError handler that automatically falls back to /images/produce/${item.id}-1.jpg if the user is offline or rate-limited.

Clone this wiki locally