π» 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¶
- π’ Update version - Increments build number
- π§ Format & lint - Runs
make fix
Setup¶
Skip (Not Recommended)¶
π·οΈ 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 |
π§ͺ 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¶
ποΈ 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¶
Features:
- π Hot reload (code changes apply instantly)
- π Debug logging
- πΎ 256MB Redis cache
- π Volume mount for live code editing
Production Mode¶
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¶
View Logs¶
ποΈ Production Deployment¶
Build Image¶
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¶
2οΈβ£ Create Branch¶
3οΈβ£ Make Changes¶
- Write code
- Add tests
- Update docs
4οΈβ£ Test¶
5οΈβ£ Commit¶
Pre-commit hooks will auto-format
6οΈβ£ Push & PR¶
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 |