SheNeeds Backend is a robust Flask REST API powering a donation platform dedicated to menstrual health in Kenya. It streamlines the connection between donors and verified charities with integrated M-Pesa payments, automated recurring donations, and a comprehensive charity verification workflow.
# SheNeeds — Donation Platform Backend
Flask REST API for the SheNeeds Donation Platform, connecting donors with verified charities focused on menstrual health education and access in Kenya.
## Tech Stack
- **Flask 3.0** + Flask-SQLAlchemy + Flask-Migrate
- **Flask-JWT-Extended** — JWT authentication with role-based access
- **Flask-Limiter** — rate limiting
- **Flask-APScheduler** — recurring donation processing
- **PostgreSQL** (production) / **SQLite** (development)
- **Gunicorn** — production WSGI server
- **M-Pesa Daraja API** — STK Push payments (sandbox + mock mode)
## Architecture
```
app/
├── __init__.py # Application factory
├── config.py # Config classes (Dev/Test/Prod) + env var loading
├── extensions.py # Extension singletons (db, jwt, limiter, scheduler)
├── models/
│ ├── user.py # User — roles: donor, charity, admin
│ ├── charity.py # Charity + CharityApplication (approval workflow)
│ ├── donation.py # Donation — amount in cents, STK Push tracking
│ ├── subscription.py # Recurring donation schedules
│ ├── story.py # Impact stories posted by charities
│ ├── beneficiary.py # Beneficiaries + inventory tracking
│ └── charity_document.py # Uploaded verification documents
├── routes/
│ ├── auth.py # /auth — register, login, /me
│ ├── donor.py # /donor — dashboard, charities, donations
│ ├── charity.py # /charity — application, profile, donations
│ ├── admin.py # /admin — users, applications, stats, analytics
│ ├── donations_api.py # /api/donations — M-Pesa initiation, status polling
│ ├── payment.py # /api/mpesa — Safaricom callbacks
│ ├── public.py # /charities — unauthenticated browsing
│ ├── stories.py # /stories — impact stories
│ ├── beneficiaries.py # /beneficiaries — charity beneficiary management
│ ├── pesapal.py # /api/pesapal — Pesapal gateway (alternative)
│ └── health.py # /health — se …