Skip to content

πŸ’» Development Guide

Everything you need to contribute to the Epguides API.


πŸš€ Quick Start

# Clone and start
git clone https://github.com/frecar/epguides-api.git
cd epguides-api
make up

# πŸŽ‰ API running at http://localhost:3000

πŸ”§ Commands

Command Description
make up ▢️ Start development environment
make up-prod πŸš€ Start production environment
make down ⏹️ Stop all Docker services
make test πŸ§ͺ Run all tests
make fix πŸ”§ Format and lint
make run ▢️ Run locally (no Docker)
make logs πŸ“‹ View container logs
make docs πŸ“– Serve docs locally
make docs-build πŸ“¦ Build static docs

πŸͺ Pre-commit Hooks

Automatic Quality Checks

Pre-commit hooks ensure code quality on every commit.

What They Do

  1. πŸ”’ Update version - Increments build number
  2. πŸ”§ Format & lint - Runs make fix

Setup

# Install hooks (one-time)
pre-commit install
git commit --no-verify

🏷️ Versioning

Automatic Versioning

Version is a simple incrementing number based on git commits.

Component Location
Version file VERSION
Updated by Pre-commit hook
Manual management Not needed
# Check current version
cat VERSION

# Or via API
curl http://localhost:3000/health

πŸ§ͺ Testing

Run Tests

# All tests
make test

# With coverage
pytest --cov=app --cov-report=term-missing

# Specific file
pytest app/tests/test_endpoints.py

# Specific test
pytest app/tests/test_endpoints.py::test_get_show

# LLM integration tests (requires LLM)
pytest app/tests/test_e2e.py -k "llm"

Test Structure

app/tests/
β”œβ”€β”€ test_endpoints.py      # REST API unit tests
β”œβ”€β”€ test_e2e.py            # End-to-end tests
β”œβ”€β”€ test_llm_service.py    # LLM service tests
β”œβ”€β”€ test_mcp.py            # MCP server tests
β”œβ”€β”€ test_mcp_endpoints.py  # MCP HTTP tests
└── test_services.py       # Service layer tests

✨ Code Quality

Tooling

The project enforces consistent code quality.

Tool Purpose
⚑ Ruff Linting, formatting (120 chars), and import sorting
πŸ§ͺ pytest Testing (100% coverage required)
πŸ”Ž mypy Static type checking
πŸ“¦ uv Dependency + environment management

Manual Checks

# Format only
make format

# Lint only
make lint

# Fix all
make fix

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚REST Router β”‚      β”‚ MCP Router β”‚
β”‚  /shows/*  β”‚      β”‚    /mcp    β”‚
β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
      β”‚                    β”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β–Ό
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β”‚  Service Layer  β”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β–Ό         β–Ό         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”
β”‚ Redis β”‚ β”‚  EPG  β”‚ β”‚TVMaze β”‚
β”‚ Cache β”‚ β”‚scraperβ”‚ β”‚client β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”˜

🐳 Docker Environments

Two Docker Compose Files

The project includes separate configurations for development and production.

Development Mode

make up
# or: docker compose up -d

Features:

  • πŸ”„ Hot reload (code changes apply instantly)
  • πŸ› Debug logging
  • πŸ’Ύ 256MB Redis cache
  • πŸ“ Volume mount for live code editing

Production Mode

make up-prod
# or: docker compose -f docker-compose.prod.yml up -d

Features:

  • ⚑ 12 uvicorn workers (optimized for 16-core server)
  • πŸš€ uvloop + httptools (2x faster)
  • πŸ’Ύ 5GB Redis cache with io-threads
  • πŸ“Š Health checks and logging rotation
  • πŸ”’ Resource limits and reservations

Configuration Comparison

Setting Development Production
Workers 1 (with reload) 12
Event loop asyncio uvloop
HTTP parser default httptools
Log level debug warning
Redis memory 256MB 5GB
Redis io-threads - 8
Health checks Basic Full
Restart policy - unless-stopped

Switching Environments

# Stop current environment
make down

# Start development
make up

# Or start production
make up-prod

View Logs

# Development
docker compose logs -f

# Production
docker compose -f docker-compose.prod.yml logs -f

πŸ—οΈ Production Deployment

Build Image

docker build -t epguides-api .

Run with Custom Redis

docker run -d -p 3000:3000 \
  -e REDIS_HOST=your-redis \
  -e REDIS_PORT=6379 \
  -e API_BASE_URL=https://your-domain.com/ \
  epguides-api

Dockerfile Features

Feature Description
πŸ—οΈ Multi-stage build Smaller final image
πŸ‘€ Non-root user Security best practice
πŸ’š Health check For orchestration
⚑ PYTHONOPTIMIZE=2 Optimized bytecode
πŸ“¦ Slim base Minimal attack surface

🀝 Contributing

1️⃣ Fork & Clone

gh repo fork frecar/epguides-api --clone
cd epguides-api

2️⃣ Create Branch

git checkout -b feature/amazing-feature

3️⃣ Make Changes

  • Write code
  • Add tests
  • Update docs

4️⃣ Test

make test

5️⃣ Commit

git commit -m "feat: add amazing feature"

Pre-commit hooks will auto-format

6️⃣ Push & PR

git push origin feature/amazing-feature

Then open a Pull Request on GitHub.


πŸ“ Code Style

Rule Standard
πŸ“ Line length 120 characters
🏷️ Type hints Required for all functions
⚑ Async Use for all I/O operations
πŸ“– Docstrings Required for public functions