Backend

This directory contains the server-side code for the Osun State Flood Alert System.

Structure

  • index.ts - Main entry point for the HTTP API
  • cron.ts - Scheduled job to check for floods and send alerts
  • database/ - Database schema and queries
  • routes/ - API route handlers
  • services/ - Business logic services

API Endpoints

Authentication

  • POST /api/auth/signup - Create a new user account
  • POST /api/auth/login - Log in to an existing account
  • GET /api/auth/me - Get current user information

Locations

  • GET /api/locations - Get all locations for the current user
  • POST /api/locations - Add a new location
  • GET /api/locations/:id - Get a specific location
  • DELETE /api/locations/:id - Delete a location

Flood Checking

  • POST /api/check-floods - Check for potential floods for a user's locations

Cron Job

The cron.ts file contains a scheduled job that runs daily to:

  1. Check for pending flood alerts
  2. Send email notifications to users
  3. Mark alerts as sent

Environment Variables

  • JWT_SECRET - Secret key for JWT token generation (optional, has default)