How s0sp/ruralroots works
Project Type and Purpose
• From the file tree and README, this is a full-stack, serverless web application (“Rural Roots”) built with React/TypeScript on the frontend, hosted on Netlify, with serverless backend logic (Netlify Functions) and integration with external services (OpenWeatherMap API, SMS gateway, optional AI APIs). Its purpose is to assist farmers by providing weather forecasts, disease diagnosis tools, and SMS alerts.
High-Level Architecture Components
a. Frontend SPA
• Hosted on Netlify as static assets (index.html + JS/CSS bundles in public/ and src/).
• Built with React, TypeScript, React Router, styled-components.
• Core modules:
– UI components (src/components/*)
– Page views (src/pages/*)
– Context & auth (src/contexts/AuthContext.tsx, src/config/firebase.ts)
– Services for direct API calls from client (src/services/*, e.g. weatherService.ts, placesService.ts, smsService.ts).
b. Serverless Backend (Netlify Functions)
• netlify/functions/api.js and netlify/functions/sms.js wrap Node handlers.
• Underlying business logic resides in src/server/ (controllers, routes, services):
– weatherAlertController.js, alertRoutes.js → schedule weather alerts
– smsRoutes.js, sms.js → interface with SMS gateway
• Uses cron/scheduler for alerts (alertScheduler.js) and third-party HTTP clients (weatherApiService.js).
c. External Services
• OpenWeatherMap (weather data)
• SMS gateway (Twilio or similar)
• Optional AI API for disease detection (mocked now via geminiService.ts)
• (Future) Firebase Auth + Firestore for user management
Relationships and Data Flows
• User’s Browser ↔ React SPA ↔ Netlify Functions
→ Weather endpoints → OpenWeatherMap
→ SMS endpoints → SMS gateway
→ (Future) Auth calls → Firebase
• Scheduler Function (triggered on Netlify) → checks weather conditions → sends SMS via gateway
• Disease Detection: Image uploaded in SPA → processed client-side or forwarded to AI API
Architectural Patterns and Design Principles
• SPA on a CDN behind a serverless BFF (Backend-for-Frontend)
• Separation of concerns:
• UI layer (components/pages)
• Service layer (API wrappers in src/services)
• Backend logic (controllers/services under src/server)
• Use of contexts for cross-cutting concerns (AuthContext)
• Modular routing in serverless functions