Tahadhari — a FastAPI backend that turns rainfall/flood alerts into personalized WhatsApp/SMS advisories for at-risk rural and urban residents in Kenya.
# Tahadhari
Tahadhari turns weather warnings into clear, specific action. Farmers, fishermen, and drivers get Telegram instructions by occupation. Commuters get flood predictions for their exact road, with a map
## Built with
Python, FastAPI, Supabase, OpenAI, GPT-4o-mini, httpx, Tenacity, Pydantic, JWT, Telegram Bot API, Google Maps API, Open-Meteo
API, ICPAC GeoNode, WFS, GeoSpatial, pytest, GitHub Actions, REST API, Uvicorn, Docker,
Railway
## Stack
- **Backend API** (`app/`): FastAPI + SQLAlchemy, Supabase Postgres in production / SQLite in-memory for tests.
- **AI layer** (`ai_layer/`): a separate package that calls OpenAI (ChatGPT) to personalize messages and classify feedback, talking to the backend API over HTTP. Message personalization (`ai_layer/services/personalizer.py`) geocodes the alert's ward/corridor name via Google Maps, pulls live Open-Meteo rainfall for it, and has the LLM weave that into a fuller message with a brief why-it-matters explanation and occupation-specific action tips — falling back to the plain filled template on any lookup/LLM failure. Claude support is kept intact but disabled — see `ai_layer/clients/claude_client.py`. Also includes an ICPAC WFS poller (`ai_layer/icpac_poll.py`) that ingests hazard data as alerts, and a location/weather poller (`ai_layer/location_poll.py`) that geocodes a user's free-text location reply via Google Maps, pulls Open-Meteo rainfall for it, and ingests it through the same alert pipeline.
See `API_GUIDE.md` for the full endpoint reference.
## Local setup
```bash
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # fill in DATABASE_URL, SUPABASE_URL, SUPABASE_KEY, SERVICE_API_KEY, JWT_SECRET_KEY, OPENAI_API_KEY, GOOGLE_MAPS_API_KEY, etc.
python -m uvicorn app.main:app --reload
```
The API is then available at `
localhost` (interactive docs at `/docs`).
### Local Telegram E2E run (recommended)
For Telegram button-flow testing, run the …