A Flask-based REST API backend supporting a clean water and sanitation monitoring platform aligned with UN Sustainable Development Goal 6: Clean Water and Sanitation.
This API powers a comprehensive water quality and sanitation resource platform for Victoria, Australia. It enables users to:
- Monitor water quality at beaches and rivers
- Locate public toilets and water fountains
- Rate and review sanitation facilities
- Subscribe to water quality updates via email notifications
- Access educational information about water quality measurement
- Victoria residents
- Families with children and pets
- Australian tourists
- Outdoor activity enthusiasts
- Outdoor workers (delivery staff, drivers, Uber drivers)
- EC2: Hosts the Flask API application
- RDS (PostgreSQL): Database for storing all application data
- Route 53: Domain name management and DNS routing
- S3 + CloudFront: Frontend static file hosting and CDN
- ACM (AWS Certificate Manager): SSL/TLS certificate management for secure connections
Simple status endpoint to verify API availability.
GET /api/v1/health
Response:
{
"success": true,
"status": "ok"
}Endpoints for user CRUD operations.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/v1/users |
List all users |
POST |
/api/v1/users |
Create new user |
GET |
/api/v1/users/<user_id> |
Get user by ID |
PUT |
/api/v1/users/<user_id> |
Update user details |
DELETE |
/api/v1/users/<user_id> |
Delete user |
GET |
/api/v1/users/search |
Search users |
Manage beach locations and water quality data.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/v1/beaches |
List all beaches |
POST |
/api/v1/beaches |
Add new beach |
GET |
/api/v1/beaches/<beach_id> |
Get beach by ID |
PUT |
/api/v1/beaches/<beach_id> |
Update beach details |
DELETE |
/api/v1/beaches/<beach_id> |
Remove beach |
DELETE |
/api/v1/beaches/update-all-predictions |
Update water quality predictions for all beaches |
Manage river monitoring locations with ML-based water quality predictions.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/v1/rivers |
List all rivers |
POST |
/api/v1/rivers |
Add new river |
GET |
/api/v1/rivers/<river_id> |
Get river by ID |
PUT |
/api/v1/rivers/<river_id> |
Update river details |
DELETE |
/api/v1/rivers/<river_id> |
Remove river |
GET |
/api/v1/rivers/<river_id>/predict |
Get prediction for specific river |
POST |
/api/v1/rivers/<river_id>/predict |
Generate prediction for specific river |
POST |
/api/v1/rivers/<river_id>/update-predict |
Update prediction value |
POST |
/api/v1/rivers/update-all-predictions |
Batch update all river predictions |
GET |
/api/v1/rivers/<river_id>/with-prediction |
Get river data with prediction |
Email notification system for water quality updates.
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/v1/notifications |
Create notification subscription |
GET |
/api/v1/notifications?booking_datetime=YYYY-MM-DD HH:MM:SS |
Get notifications for specific datetime |
POST |
/api/v1/notifications/send-due |
Trigger sending of due notifications |
Community rating system for public toilets.
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/v1/toilet-ratings |
Submit toilet rating |
GET |
/api/v1/toilet-ratings |
Get all ratings |
GET |
/api/v1/toilet-ratings/<rating_id> |
Get rating by ID |
GET |
/api/v1/toilet-ratings/latest |
Get latest rating comments |
GET |
/api/v1/toilet-ratings/average/<toilet_id> |
Get average rating for toilet |
Public water fountain location management.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/v1/water-fountains |
List all water fountains with place names |
GET |
/api/v1/water-fountains/<fountain_id> |
Get water fountain by ID with place name |
- Framework: Flask (Python)
- Database: PostgreSQL (AWS RDS)
- Cloud Platform: AWS
- API Style: RESTful
- Python 3.8+
- PostgreSQL
- AWS Account (for deployment)
- Clone the repository
git clone https://github.com/lily-yyyy/IE_Flask_Api.git
cd IE_Flask_Api- Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Configure environment variables
# Create .env file with the following:
DATABASE_URL=postgresql://username:password@localhost:5432/dbname
FLASK_ENV=development
SECRET_KEY=your-secret-key
AWS_ACCESS_KEY_ID=your-aws-key
AWS_SECRET_ACCESS_KEY=your-aws-secret- Initialize database
flask db init
flask db migrate
flask db upgrade- Run the application
flask runThe API will be available at http://localhost:5000
- Launch EC2 instance (Amazon Linux 2 or Ubuntu)
- Install Python and required dependencies
- Clone repository and set up application
- Configure RDS PostgreSQL connection
- Set up nginx as reverse proxy
- Configure SSL certificate with ACM
- Update Route 53 DNS records
Ensure the following environment variables are set in production:
DATABASE_URL: PostgreSQL connection stringFLASK_ENV: Set toproductionSECRET_KEY: Strong secret key for session managementAWS_REGION: AWS region for services- Email configuration for notification system
- HTTPS enforced via AWS ACM certificates
- Environment variables for sensitive data
- Input validation on all endpoints
- CORS configured for frontend domain
- SQL injection prevention through ORM
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or support, please open an issue in the GitHub repository.
Built with ❤️ for cleaner water and better sanitation in Victoria, Australia