National early warning dashboard for monitoring public sentiment, alerts, and county-level risk signals across Kenya.
Nyayo Sentinel Dashboard – Early Warning System
================================================
A secure, production-ready government analytics platform for monitoring public sentiment across all 47 Kenyan counties. Designed as an **early warning system** for detecting emerging frustration, unrest, or spikes in negative sentiment, with county- and topic-level drill-downs, real-time alerting, email notifications, automated web scraping, and full audit logging.
---
## Architecture
```
Kenyan News / Reddit / Facebook / Instagram → Python Scraper (NLP) → POST /api/ingest/events
↓
Browser → Next.js Frontend (3000) → Express Backend (4000) → PostgreSQL (5432)
↕ Socket.io (real-time alerts)
↕ Gmail SMTP (email notifications)
↕ Anthropic Claude API (AI alert summaries)
```
| Layer | Technology |
|-------|-----------|
| Frontend | Next.js 14 (App Router), React 18, TypeScript, Recharts, React Simple Maps |
| Backend | Node.js 20, Express 4, TypeScript, Prisma 5, Socket.io 4, Nodemailer |
| Database | PostgreSQL 16 |
| Auth | JWT (access 15 min / refresh 7 days, httpOnly cookies), Email OTP 2FA |
| Email | Gmail SMTP via Nodemailer (invite, 2FA OTP, alerts, password reset) |
| Scraper | Python 3.12, HuggingFace Transformers, feedparser, requests, instaloader, facebook-scraper |
| AI Summaries | Anthropic Claude Haiku — plain-English alert summaries generated at alert-fire time |
| Deployment | Docker + Docker Compose |
---
## Quick Start
### Prerequisites
- Docker & Docker Compose
- Node.js 20+ (for local development)
### 1. Configure environment
Create `backend/.env`:
```env
DATABASE_URL=postgres://nyayo:nyayo_secure_password@localhost:5432/nyayo_sentinel
NODE_ENV=development
PORT=4000
JWT_ACCESS_TOKEN_SECRET=change-me-in-production
JWT_REFRESH_TOKEN_SECRET=change-me-in-production
JWT_ACCESS_TOKEN_TTL=900
JWT_REFRESH_TOKEN_TTL=604800
ALLOWED_ORIGINS=
localhost
MFA_ISSUER=NyayoSentinel
SMTP_USER=your-gmail@gmail.com
SMTP_PASS=your-gmail-app-password
FRON …