An open API service indexing awesome lists of open source software.

https://github.com/troutlytics/troutlytics-backend

Backend support to provide updated information about trout stocking in Washington state. This repository contains all the essential backend components of the project, including database management, Web API, and a web scraper.
https://github.com/troutlytics/troutlytics-backend

contributions-welcome contributors data-visualization docker fastapi fish fishing folium lakes maps python sqlalchemy statistics trout washington wdfw webscraper webscraping website

Last synced: 3 months ago
JSON representation

Backend support to provide updated information about trout stocking in Washington state. This repository contains all the essential backend components of the project, including database management, Web API, and a web scraper.

Awesome Lists containing this project

README

          

# 🐟 Troutlytics Backend

[![Python application](https://github.com/troutlytics/troutlytics-backend/actions/workflows/python-app.yml/badge.svg)](https://github.com/troutlytics/troutlytics-backend/actions/workflows/python-app.yml)

## Description

**Troutlytics** is a data-driven Python application that scrapes and stores trout stocking data for Washington State lakes. It runs on a scheduled AWS Fargate task and stores results in an Aurora PostgreSQL database for use in dashboards, maps, and analysis tools.

---

## πŸ“¦ Project Structure

```bash
.
β”œβ”€β”€ api/ # 🎯 Main application API
β”‚ β”œβ”€β”€ __init__.py # API package initializer
β”‚ β”œβ”€β”€ index.py # API entrypoint (routes/controllers)
β”‚ β”œβ”€β”€ requirements.txt # API dependencies
β”‚ β”œβ”€β”€ dockerfiles/
β”‚ β”‚ β”œβ”€β”€ dev/Dockerfile # Dev Dockerfile
β”‚ β”‚ └── prod/ # Production Dockerfile (Lambda-ready)
β”‚ β”‚ β”œβ”€β”€ Dockerfile
β”‚ β”‚ └── lambda_entry_script.sh
β”‚ └── README.md # API-specific usage docs

β”œβ”€β”€ web_scraper/ # πŸ•ΈοΈ Web scraping service
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ scraper.py # Main script for collecting trout/creel data
β”‚ β”œβ”€β”€ Dockerfile # Docker setup for scraper
β”‚ β”œβ”€β”€ Makefile # Shortcuts for common dev tasks
β”‚ β”œβ”€β”€ requirements.txt
β”‚ β”œβ”€β”€ README.md
β”‚ └── tests/ # πŸ”¬ Pytest-based tests
β”‚ β”œβ”€β”€ __init__.py
β”‚ └── test_scraper.py

β”œβ”€β”€ data/ # πŸ—ƒοΈ Database models and storage
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ database.py # SQLAlchemy engine and session config
β”‚ β”œβ”€β”€ models.py # ORM models for tables
β”‚ β”œβ”€β”€ backup_data.sql # SQL dump for backup or restore
β”‚ β”œβ”€β”€ backup_data.txt # Raw text backup
β”‚ └── sqlite.db # Local development database

β”œβ”€β”€ aws_config/ # ☁️ AWS deployment and secrets setup
β”‚ β”œβ”€β”€ configure-aws-credentials-latest.yml # GitHub Actions for AWS login
β”‚ └── fargate-rds-secrets.yaml # Fargate setup with RDS and Secrets Manager served there)
β”œβ”€β”€ README.md # You are here πŸ“˜
```

βΈ»

πŸš€ Deployment Overview

AWS Infrastructure:

- Fargate runs the scraper every 24 hours via EventBridge.
- Secrets Manager securely stores DB credentials.
- Aurora PostgreSQL stores structured stocking data.
- CloudWatch Logs tracks runtime output for visibility.
- API hosted with API Gateway and Lambda

GitHub β†’ ECR Workflow:

- Automatically builds and pushes Docker image on main branch updates.
- Uses secure OIDC GitHub Actions role to push to ECR.

βΈ»

πŸ“‹ Prerequisites

- An AWS Account configured with appropriate permissions
- AWS CLI configured with appropriate permissions
- Docker installed (for local and prod builds)
- Python 3.11+

βΈ»

πŸ§ͺ Run Locally

## πŸš€ Docker Compose Commands Cheat Sheet

Everything is ran from the root repo folder

| Action | Command | Notes |
| :--------------------------- | :--------------------------------- | :-------------------------------------------- |
| **Build all services** | `docker compose build` | Build all images |
| **Start all services** | `docker compose up` | Start API(s), Scraper |
| **Start all + rebuild** | `docker compose up --build` | Force rebuild before starting |
| **Start dev API only** | `docker compose up api-dev` | Starts API Dev service |
| **Start prod API only** | `docker compose up api-prod` | Starts API Prod service |
| **Start scraper only** | `docker compose up web-scraper` | Starts Scraper |
| **Stop all services** | `docker compose down` | Stops and removes all containers and networks |
| **Rebuild dev API only** | `docker compose build api-dev` | Rebuild only the dev API image |
| **Rebuild prod API only** | `docker compose build api-prod` | Rebuild only the prod API image |
| **Rebuild scraper only** | `docker compose build web-scraper` | Rebuild only the scraper image |
| **View running containers** | `docker compose ps` | Show status of all services |
| **View logs (all services)** | `docker compose logs` | View logs for all services |
| **Follow logs live** | `docker compose logs -f` | Stream logs in real time |
| **Stop dev API** | `docker compose stop api-dev` | Stop only the dev API container |
| **Stop prod API** | `docker compose stop api-prod` | Stop only the prod API container |
| **Stop scraper** | `docker compose stop web-scraper` | Stop only the scraper container |
| **Restart all containers** | `docker compose restart` | Restart all running services |

---

## πŸ› οΈ Cloud Setup

Deploy the CloudFormation Stack:

```bash
aws cloudformation deploy \
--template-file aws_config/configure-aws-credentials-latest.yml \
--stack-name troutlytics-stack \
--capabilities CAPABILITY_NAMED_IAM \
--parameter-overrides \
ECRImageUriScraper=123456789012.dkr.ecr.us-west-2.amazonaws.com/scraper:latest \
ECRImageUriAPI=123456789012.dkr.ecr.us-west-2.amazonaws.com/api:latest \
VpcId=vpc-xxxxxxxx \
SubnetIds=subnet-aaaa,subnet-bbbb \
SecurityGroupId=sg-xxxxxxxx
```

βΈ»

πŸ” GitHub β†’ ECR Deploy (CI/CD)

To enable GitHub Actions auto-deploy:

1. Deploy the github_oidc_ecr_access.yaml CloudFormation template.
2. Add the output IAM Role ARN to your GitHub Actions secrets or workflows.
3. Push to main β€” your image builds and publishes to ECR automatically.

βΈ»

πŸ“ˆ Roadmap Ideas

- Add support for weather/streamflow overlays
- Enable historical trend analysis by lake
- Integrate public stocking alerts
- Expand scraper coverage to other regions or species

βΈ»

🧠 Credits

Created by @thomas-basham β€” U.S. Army veteran, full-stack developer, and passionate angler 🎣

βΈ»

License

MIT