Community-powered safety intelligence for Nigeria — SafeAlert NG
# SafeAlert NG — Backend API
Community-powered safety intelligence platform for Nigeria.
## Stack
- **Runtime:** Node.js 18+
- **Framework:** Express.js
- **Database:** Firebase Firestore (real-time, offline-capable)
- **Auth:** Custom OTP via Africa's Talking SMS
- **SMS/USSD:** Africa's Talking API
- **Push Notifications:** Firebase Cloud Messaging (FCM)
- **Maps:** OpenStreetMap (client-side only — free)
---
## Quick Start
```bash
# 1. Clone and install
git clone
github.com
cd safealert-ng-backend
npm install
# 2. Configure environment
cp .env.example .env
# Edit .env with your Firebase and Africa's Talking credentials
# 3. Run in development
npm run dev
# 4. Run in production
npm start
```
---
## Environment Setup
### Firebase Setup
1. Go to
console.firebase.google.com
2. Create a new project named `safealert-ng`
3. Enable Firestore (production mode)
4. Go to Project Settings → Service Accounts → Generate new private key
5. Copy `project_id`, `private_key`, `client_email` into your `.env`
6. Enable Firebase Cloud Messaging in the console
7. Deploy Firestore rules: `firebase deploy --only firestore:rules`
8. Create indexes: `firebase deploy --only firestore:indexes`
### Africa's Talking Setup
1. Register at
africastalking.com
2. Create an account for Nigeria
3. Get your API key from the dashboard
4. Register your shortcode (or use sandbox shortcode for testing)
5. Apply to NCC for USSD code:
ncc.gov.ng
---
## API Reference
Base URL: `
api.safealertng.com`
### Authentication
```
POST /auth/request-otp — Send OTP
POST /auth/verify-otp — Verify OTP → get token
POST /auth/logout — Revoke token
```
### Zones (Incident Reports)
```
GET /zones — All active zones (?lat&lng&radius)
GET /zones/:id — Single zone
POST /zones — Report incident (creates/merges zone)
PATCH /zones/:id/confirm — Confirm still dangerous (auth requi …