Inspiration
Indonesian smallholder chili farmers face a double crisis that repeats every season. First, without coordinated market intelligence, thousands of farmers across dozens of districts plant at the same time, which floods the market three months later and crashes prices from Rp 60,000/kg to Rp 3,000/kg below the cost of production. Second, Anthracnose (Patek) can destroy 60–80% of a chili plot in days when farmers guess the wrong fungicide because there is no agronomist nearby when the first leaf lesion appears.
Both crises share the same root: the information a farmer needs is either expert knowledge locked in a university lab, or a statistical pattern across thousands of regional planting records that no individual can see. We wanted to build a tool that puts that intelligence in the farmer's pocket, one that works even with the unstable mobile connections typical of rural Indonesian growing areas.
The #BuildHybridAI challenge made the timing perfect: Firebase AI Logic's hybrid inference SDK was exactly the architecture we needed. Fast, free, private on-device AI for the moments when connectivity is unavailable; full cloud Gemini power for the structured analysis that actually changes a farmer's decision.
What it does
SmartChili is a bilingual (English / Bahasa Indonesia) Progressive Web App with four field tools, all gated by role-based access across four user types: Cooperative Lead (Admin), Field Advisor (Agronomist), Farmer, and Read-Only Observer (Viewer):
Plant Doctor: The farmer photographs a leaf or fruit showing symptoms. On-device Gemini Nano produces an immediate 2-sentence triage summary (offline, free, instant). Firebase AI Logic cloud inference then delivers a full structured diagnosis: disease classification (Anthracnose vs. Cercospora Leaf Spot vs. Yellow Leaf Curl Virus vs. wilt vs. healthy), severity level, targeted fungicide recommendation, and a plain-language action plan. The inference engine that produced each result (on-device or cloud) is shown directly in the UI.
Price & Timing Advisor: An AI market advisor that answers questions about price risk, harvest timing, and variety selection. Simple single-variety questions are answered on-device from cached 12-month price series. Multi-variety comparisons and staggered-planting analysis route to the cloud model for structured reasoning.
Planting Insights: Blends a farmer's own planting block history, disease scan history, and 12-month price forecasts to recommend a next-cycle transplant date that avoids both a disease-break failure and a synchronized regional harvest collision.
Regional Pest Alert Map: A community-powered outbreak map where farmers log disease sightings by region and severity. Agronomists can verify reports; admins can moderate. The map falls back to an SVG coordinate radar when offline or when no maps API key is configured, so it always works.
How we built it
Hybrid AI core: All generative inference uses the firebase/ai SDK with two model modes: InferenceMode.ONLY_ON_DEVICE for Gemini Nano (lightweight summaries, offline) and InferenceMode.ONLY_IN_CLOUD for full structured analysis (JSON schema-enforced, multimodal image input, thinking enabled). Routing logic in hybridAi.ts tries on-device first, falls back to a local deterministic triage if Nano is unavailable, and routes to the cloud for full analysis. All transparently reported to the user via an InferenceEngine label on each AI response.
Firebase ecosystem: Firebase Auth (Google sign-in), Cloud Firestore (planting records, pest reports, and user roles are enforced with security rules in firestore.rules), and Firebase App Check (reCAPTCHA Enterprise for production; registered debug tokens for the submission and preview deployments via VITE_APPCHECK_DEBUG_TOKEN).
PWA shell: A Node.js / Express server (server.ts) serves the Vite-built React 19 + TypeScript + Tailwind CSS PWA. The server also proxies /api/weather to Google Maps Weather API, with a full fallback to Open-Meteo + OpenStreetMap Nominatim (free, no API key) when no Google Maps key is configured. The interactive outbreak map similarly falls back from Google Maps to Leaflet + OpenStreetMap.
Offline-first: vite-plugin-pwa generates a service worker. The app installs to home screen, works offline with cached data, and shows a clear online/offline status badge alongside the hybrid inference status indicator.
Tooling: Designed at Google AI Studio and developed with Antigravity using the Firebase agent skills, running in this workspace throughout the hackathon period.
Challenges we ran into
Firebase App Check across domains. App Check with reCAPTCHA Enterprise rejects any domain not explicitly registered, including the Railway preview URL. The fix was to support VITE_APPCHECK_DEBUG_TOKEN at build time so the cloud Gemini calls work on any deployed URL without needing to authorize every preview subdomain in the reCAPTCHA Enterprise console.
React 19 + react-leaflet peer dependency. react-leaflet@4 declares a strict peer dependency on react@^18, which conflicts with our React 19 project. This required npm install --legacy-peer-deps and replacing react-leaflet's <Popup onOpen> / <Popup onClose> props (not available in the TypeScript types) with eventHandlers equivalents.
On-device Gemini Nano availability. Gemini Nano is only available in Chrome 128+ on supported hardware with the flag enabled. The hybrid routing needed to handle three states gracefully: Nano available, Nano not available (fall back to local triage), and cloud unreachable (surface a clear error rather than a silent blank response).
CORS on weather APIs. weather.googleapis.com does not send CORS headers, so direct browser calls fail. The Express server proxy was essential, but needed a full fallback for deployments without a Google Maps API key (the hackathon review environment may not have one). Open-Meteo is fully CORS-enabled and free, making it the right fallback.
Accomplishments that we're proud of
True hybrid inference with observable routing. Every AI response in SmartChilli shows the user exactly which engine generated it: on-device Gemini Nano or cloud Gemini. This is not a cosmetic badge; it reflects the actual
response.inferenceSourcefrom the Firebase AI Logic SDK, surfaced through the app'sInferenceEnginetelemetry layer.A realistic cooperative RBAC model. Four roles: Admin, Agronomist, Farmer, and Viewer with 17 distinct permission keys, enforced both in Firestore Security Rules (server-side) and in the React UI (client-side). The permission model reflects how chili cooperatives (poktan) in Indonesia actually work: agronomists verify reports but cannot price-advise, viewers can export data but cannot run AI inference.
Complete offline experience. The app installs as a PWA, works offline with service-worker caching, falls back from Google Maps to free OpenStreetMap for both the weather widget and the pest alert map, and always shows a local deterministic AI triage even when both Nano and the network are unavailable.
Zero API keys required to run. All AI runs through Firebase AI Logic (no Gemini API key on the client or server). Weather and maps work without Google Maps keys via Open-Meteo and Leaflet/OSM. A judge can clone the repo,
npm install --legacy-peer-deps, setVITE_ADMIN_EMAILandVITE_APPCHECK_DEBUG_TOKEN, and run a full end-to-end local instance.
What we learned
Firebase App Check is non-negotiable when Firebase AI Logic is enforced. The 401/400 error cycle from an unregistered debug token or an unauthorized reCAPTCHA domain is easy to misread as a network or project configuration problem. The clearest diagnostic is always the browser DevTools console, as the Firebase SDK logs the exact App Check error code and throttle timer.
Hybrid inference design requires explicit fallback contracts.
InferenceMode.PREFER_ON_DEVICEsounds convenient but makes routing opaque. We found it cleaner to implement the routing explicitly inhybridAi.ts: try on-device → catch (fall to local triage) → try cloud → surface error. Each level has a defined user-facing label and cost implication.Firebase web config is intentionally public. The
apiKey,appId,projectId,recaptchaSiteKeyandoAuthClientIdinfirebase-applet-config.jsonare routing identifiers, not authentication secrets. Actual security is enforced by App Check, Firestore Security Rules, and Firebase Auth — not by hiding the config.Offline-first discipline pays off in rural deployment scenarios. Building the weather fallback, the SVG map fallback, and the local AI triage fallback from the beginning meant the app remained fully functional throughout development even when API keys weren't configured, which dramatically sped up iteration.
What's next for SmartChilli
Android PWA + native Gemini Nano via Firebase AI Logic. The hybrid architecture is ready; the next step is testing on Android Chrome and packaging as a TWA (Trusted Web Activity) for Play Store distribution, reaching farmers who already have Android smartphones but limited data plans.
Regional price data integration. Connecting to PIHPS Nasional (Indonesia's official horticultural price information system) and BPS chili price series would replace the simulated 12-month price forecasts with live government data, making the Price & Timing Advisor directly actionable.
Cooperative multi-tenant workspaces. The current RBAC model supports a single cooperative workspace per Firebase project. The next step is multi-workspace support so a district agricultural office can host a single SmartChilli instance shared across dozens of poktan groups, each with isolated data and their own Admin.
On-device multimodal Plant Doctor. When Gemini Nano gains stable multimodal image input support in Chrome, the full leaf diagnosis (not just the text summary) could run entirely on-device, eliminating the need for a cloud call, data usage, and latency for the most time-sensitive feature.
Built With
- antrigravity
- chrome
- express.js
- firebase
- firestore
- gemini
- github
- googleaistudio
- kiro
- leaflet.js
- node.js
- open-meteo-forecast
- openstreetmap
- railway
- react
- remotion
- tailwind
- typescript
- vite