# Routers (app/routers/) ## OVERVIEW 11 FastAPI APIRouter modules, each owning a URL prefix. All registered in `main.py:118-144`. ## WHERE TO LOOK | Router | File | Prefix | Purpose | |--------|------|--------|---------| | root_router | `router_root.py` | `/`, `/web` | Index page, web UI | | auth_router | `router_auth.py` | `/api/auth` | Register, login, JWT tokens | | downloads_router | `router_downloads.py` | `/api/download` | Task CRUD, pause/resume, file serve | | anime_router | `router_anime.py` | `/api/anime`, `/api/series` | Search, metadata, episodes, season download | | favorites_router | `router_favorites.py` | `/api/favorites` | Favorites toggle, list | | recommendations_router | `router_recommendations.py` | `/api/recommendations`, `/api/releases` | Personalized + latest releases | | watchlist_router | `router_watchlist.py` | `/api/watchlist` | Watchlist CRUD, scheduler, auto-download | | sonarr_router | `router_sonarr.py` | `/api/sonarr`, `/api/webhook/sonarr` | Webhook receiver, mappings | | player_router | `router_player.py` | `/player`, `/watch` | Video player pages | | static_router | `router_static.py` | `/static`, `/video` | Static files, video streaming (Range) | | settings_router | `router_settings.py` | `/api/settings` | User app settings | ## CONVENTIONS **Adding endpoints**: Identify the correct router by URL prefix → add to that file → import in `app/routers/__init__.py` (if new router) → register in `main.py`. **Shared dependencies** (via FastAPI `Depends`): - `download_manager: DownloadManager = Depends(lambda: download_manager)` — singleton from main.py - `current_user: User = Depends(get_current_user_from_token)` — JWT auth - `templates: Jinja2Templates = Depends(lambda: templates)` — Jinja2 renderer **Router registration** in `main.py` uses `app.include_router(router)`. Tags set per-router for OpenAPI. ## ANTI-PATTERNS - Do NOT create a new router for a single endpoint — add to existing matching router - Do NOT use `Depends()` with direct module imports that create circular references - Do NOT duplicate URL prefixes across routers