WhatsApp Delivery & Logistics Platform for Zimbabwe - Connects WhatsApp API to Supabase with PostGIS spatial tracking.
# WhatsApp Delivery & Logistics Platform - Zimbabwe
A data-optimized delivery platform that connects WhatsApp API messages to a Supabase backend, tracking spatial coordinates for delivery logistics in Zimbabwe.
## Features
- WhatsApp Business API integration
- Real-time location tracking using PostGIS
- Order management system
- Driver availability tracking
- Spatial queries for efficient delivery routing
## Project Structure
```
├── src/
│ └── index.ts # Main Express server
├── migrations/
│ └── 001_initial_schema.sql # Database schema
├── package.json
├── tsconfig.json
├── .env.example
└── README.md
```
## Setup Instructions
### 1. Environment Setup
1. Copy the environment variables file:
```bash
cp .env.example .env
```
2. Fill in your environment variables in `.env`:
- `WHATSAPP_VERIFY_TOKEN`: Your WhatsApp webhook verification token
- `WHATSAPP_ACCESS_TOKEN`: Your WhatsApp API access token
- `SUPABASE_URL`: Your Supabase project URL
- `SUPABASE_ANON_KEY`: Your Supabase anonymous key
- `SUPABASE_SERVICE_ROLE_KEY`: Your Supabase service role key
### 2. Database Setup
1. Run the SQL migration in your Supabase project:
```sql
-- Execute the contents of migrations/001_initial_schema.sql
```
This will:
- Enable PostGIS extension
- Create merchants, drivers, and orders tables
- Set up spatial indexes for efficient location queries
- Configure RLS policies
### 3. Running the Application
Development mode:
```bash
npm run dev
```
Development with auto-restart:
```bash
npm run dev:watch
```
Production build and run:
```bash
npm run build
npm start
```
## API Endpoints
### WhatsApp Webhook
- **GET** `/api/whatsapp/webhook` - Hub verification challenge
- **POST** `/api/whatsapp/webhook` - Incoming WhatsApp messages
### Health Check
- **GET** `/health` - Service health status
## Database Schema
### Merchants Table
- `id`: UUID primary key
- `name`: Merchant name
- `contact_phone`: Contact phone number
- `active`: Active status
### Drive …