A minimal Flask-based web service for URL shortener, featuring PostgreSQL persistence, observability, and caching. Designed for reliability, performance, and maintainability.
- Python (Flask)
- Peewee ORM
- PostgreSQL
- Prometheus (metrics)
- Grafana (monitoring dashboard)
- Redis (caching)
- Docker & Docker Compose
- cAdvisor (system metrics)
- app/:
- models/: Database models (User, Event, URL)
- routes/: API endpoints (users, events, urls)
- services/: Business logic, caching
- observability/: Logging and metrics
- database.py: DB connection and base model
- artifacts/: Misc files
- tests/: Unit and integration tests
- prometheus.yml: Prometheus config
- prometheus-rules.yml: Alerting rules
- Dockerfile / docker-compose.yml: Containerization
GET /users— List all usersGET /users/<id>— Get user by IDPOST /users— Create userPUT /users/<id>— Update userDELETE /users/<id>— Delete user
GET /events— List all eventsGET /events/<id>— Get event by IDPOST /events— Create eventPUT /events/<id>— Update eventDELETE /events/<id>— Delete event
GET /urls— List all URLsGET /urls/<id>— Get URL by IDPOST /urls— Create URLPUT /urls/<id>— Update URLDELETE /urls/<id>— Delete URL
GET /health— Health check
- Centralized logging via
app/observability/logging.py - Logs requests, errors, and key events
- Prometheus scrapes application and cAdvisor metrics
- Grafana dashboard for SRE signals and system resources
- Custom metrics via
app/observability/metrics.py
- Redis-based caching for user, event, and URL lookups
- Implemented in
app/services/cache.py
- Install Docker
- Run
cp .env.example .envto create your .env file
- See this guide for getting your Discord Webhook URL
- Run
docker compose up -dto run in detached mode - See your app in
http://localhost:8000
- All tests in
tests/(unit and integration) - Run with
pytest