10 KiB
10 KiB
🗺️ MagNetFlix — Reconciled Implementation Roadmap
This roadmap breaks down the completion of MagNetFlix into clear, dependency-ordered milestones. Each milestone includes explicit prerequisites, work items, and verifiable exit criteria.
🎯 Milestones Dependency Graph
flowchart TD
M1["Milestone 1: Contracts, Toolchain & DB Hardening\n(GAP-1, GAP-2, TD-1, TD-2, TD-3)"]
M2["Milestone 2: Pipeline Domain Engine & Filesystem Safety\n(GAP-3, GAP-4, GAP-5)"]
M3["Milestone 3: Transmission Integration & Worker Coordinator\n(GAP-6, GAP-7)"]
M4["Milestone 4: FastAPI BFF Gateway, SSE & Web UI\n(GAP-8)"]
M5["Milestone 5: Multi-Container Stack & Deployment Verification\n(Traefik, SSO, Compose)"]
M1 --> M2
M2 --> M3
M3 --> M4
M4 --> M5
📌 Milestone 1: Contracts, Toolchain & Database Hardening
- Objective: Fix broken gRPC stub imports, ensure 100% reproducible offline container builds, eliminate the active-job deduplication race, and establish database schema invariants.
- Dependencies: None.
- Requirements Satisfied:
REQ-1,REQ-2. - Work Items:
M1.1: Createservices/contractsworkspace package (pyproject.toml,module-name = "magnetflix").M1.2: Reconfigurebuf.gen.yamlto output stubs intoservices/contracts/src; generate and track stubs +docs/api_spec.mdin Git (DEC-1).M1.3: Update dependencies inservices/workerandservices/bffto includemagnetflix-contracts = { workspace = true }.M1.4: Updatepyproject.tomlto includetests/inpyright, remove exclusions that masked broken imports, and addtest:target toMakefile.M1.5: Updateservices/worker/Dockerfileandservices/bff/Dockerfileto copyservices/contracts, and includealembic.iniandalembic/in the Worker image.M1.6: Create Alembic migration002_add_info_hash_and_partial_unique_index.pyaddinginfo_hashcolumn anduq_download_jobs_active_imdb_idindex (DEC-2).M1.7: UpdateDownloadJobmodel and add unit tests intests/test_db.pyverifying duplicate active insertion rejection.M1.8(Architecture Review Follow-up): Normalize Base32btihinfo_hashto 40-char lowercase hex inDownloadJoband add partial unique indexuq_download_jobs_active_info_hashvia Alembic migration003.
- Verifiable Exit Criteria:
uv run python -c "from magnetflix.v1 import pipeline_pb2, pipeline_pb2_grpc"succeeds with 0 errors.uv run ruff check .anduv run pyrightpass cleanly across the entire workspace including contracts and tests.uv run pytest tests/test_db.pypasses all tests including partial unique index verification.
📌 Milestone 2: Pipeline Domain Engine & Filesystem Safety
- Objective: Implement core business logic and security boundary modules: untrusted payload sanitization, metadata verification, and cross-volume publication.
- Dependencies: Milestone 1.
- Requirements Satisfied:
REQ-3,REQ-4,REQ-5. - Work Items:
M2.1: Implement Media Sanitizer (services/worker/src/worker/sanitizer.py) adhering toDEC-3:- Hard-fail on symlinks, hard links,
..traversal, special files, and dangerous extensions (case-insensitive:.exe,.bat,.cmd,.sh,.scr,.vbs,.ps1,.lnk,.iso,.zip,.rar,.7z). - Safely ignore unlisted non-dangerous files (such as
.nfo,.txt,.jpg,.sfv). - Discard samples (
< 100 MBor case-insensitive word-boundary"sample"token /Sampledirectory); select largest primary video and allowlisted subtitles (.srt,.vtt,.sub,.ass).
- Hard-fail on symlinks, hard links,
M2.2: Write unit tests intests/test_sanitizer.pyverifying all security, allowlist, and sample discard rules.M2.3: Implement TMDB Client & Token Verifier (services/worker/src/worker/metadata.py) adhering toDEC-4:- Early resolution via
GET /find/{imdb_id}?external_source=imdb_idusinghttpx.AsyncClientwith bounded timeouts/retries. - Validates IMDb ID format, validates movie entity type, extracts
(title, year). - Post-download normalized token comparison between cached
(title, year)and primary video filename.
- Early resolution via
M2.4: Write unit tests intests/test_metadata.pywith mocked TMDB HTTP responses (match, 404, non-movie, mismatch).M2.5: Implement Library Relocator (services/worker/src/worker/relocator.py) adhering toDEC-5:- Deterministic
<Title>path sanitization (stripping/replacing/,\,:,*,?,",<,>,|,..). - Multi-track subtitle format preservation (
.srt,.vtt,.sub,.ass) with language/forced tags, untagged fallback (<SanitizedTitle> (<Year>).<ext>), and disambiguation indices. - Free-space pre-check + two-stage copy-and-swap: copy to
/media/movies/.staging_<job_id>/, pre-check destination directory existence, and atomically swap viaos.replace.
- Deterministic
M2.6: Write unit tests intests/test_relocator.pyasserting destination file layout and atomic swap error handling.
- Verifiable Exit Criteria:
uv run pytest tests/test_sanitizer.py tests/test_metadata.py tests/test_relocator.pypasses 100%.- Zero filesystem breakout vulnerabilities possible under synthetic traversal fixtures.
📌 Milestone 3: Transmission Integration & Worker Coordinator
- Objective: Wrap Transmission RPC, coordinate the pipeline finite state machine, implement startup crash recovery, and expose the gRPC service.
- Dependencies: Milestone 2.
- Requirements Satisfied:
REQ-6,REQ-7,REQ-8. - Work Items:
M3.1: Implement Transmission RPC Client Wrapper (services/worker/src/worker/transmission.py) adhering toDEC-6:add_torrent(magnet_uri, download_dir=/data/staging/<job_id>).get_progress(info_hash)returning progress percentage and download speed.remove_torrent(info_hash, delete_data=True)for terminal cleanup.
M3.2: Write unit tests intests/test_transmission.pywith mocked RPC client.M3.3: Implement Pipeline Coordinator & State Machine (services/worker/src/worker/pipeline.py) adhering toDEC-6&DEC-7:- State progression:
QUEUED\rightarrowDOWNLOADING\rightarrowSCANNING\rightarrowVERIFYING_METADATA\rightarrowORGANIZING\rightarrowCOMPLETED(withFAILEDreachable from any active state). - 15-minute zero-progress-delta stalled torrent timeout.
- Startup crash recovery: query non-terminal jobs, fail DB rows, purge staging directories, remove torrents from Transmission (with bounded startup retry/backoff).
- Dedicated bounded relocation executor isolated from lightweight
transmission-rpcand scan offloading. - In-memory
asyncio.Queuebroadcaster (subscribe-before-snapshot + bounded per-subscriber coalescing) for real-time status streaming.
- State progression:
M3.4: Implement gRPC Server Servicer (services/worker/src/worker/service.py&main.py) adhering topipeline.proto:- Implements
SubmitDownload,GetJob,ListJobs, andStreamJobStatusplus gRPC health check. - Maps application errors to proper gRPC status codes (
ALREADY_EXISTS,NOT_FOUND,INVALID_ARGUMENT).
- Implements
M3.5: Write integration tests intests/test_pipeline.pyandtests/test_grpc_service.py.
- Verifiable Exit Criteria:
uv run pytest tests/test_pipeline.py tests/test_grpc_service.pypasses 100%.- Worker process cleanly starts, handles startup reconciliation, and shuts down gracefully with
SIGTERM.
📌 Milestone 4: FastAPI BFF Gateway, SSE & Web UI
- Objective: Implement the user-facing web gateway, pluggable SSO identity adapter, server-side TMDB search proxy, real-time SSE stream, and single-origin UI.
- Dependencies: Milestone 3.
- Requirements Satisfied:
REQ-9,REQ-10. - Work Items:
M4.1: Implement Pluggable Identity Adapter Middleware in FastAPI (DEC-8):- Configurable via
AUTH_ENABLED,AUTH_HEADER_USER, andCORS_ALLOWED_ORIGINS; fails closed with401whenAUTH_ENABLED=trueand falls back tolocal_useronly whenAUTH_ENABLED=false.
- Configurable via
M4.2: Implement BFF gRPC Client Wrapper (services/bff/src/bff/grpc_client.py):- Channels calls to Worker (
SubmitDownload,GetJob,ListJobs,StreamJobStatus).
- Channels calls to Worker (
M4.3: Implement REST Endpoints & Schemas (services/bff/src/bff/main.py):- Dual route bindings:
POST /api/v1/downloadsandPOST /downloadwith Pydantic aliases (magnet/magnet_uri,imdbid/imdb_id). - Server-side TMDB movie search proxy:
GET /api/v1/movies/search?q=.... - Server-Sent Events stream:
GET /api/v1/movies/events.
- Dual route bindings:
M4.4: Embed Hosted Web UI (services/bff/src/bff/templates/&static/):- Clean, responsive dashboard (adapted from extension prototype
app.html/app.css). - Movie search autocomplete with poster previews, magnet input, and live progress bars.
- Clean, responsive dashboard (adapted from extension prototype
M4.5: Write API tests intests/test_bff_routes.pycovering auth extraction, dual routes, search proxy, and SSE streams.
- Verifiable Exit Criteria:
uv run pytest tests/test_bff_routes.pypasses 100%.- BFF connects to gRPC worker, serves Web UI, and streams live download progress without browser CORS errors.
📌 Milestone 5: Multi-Container Stack & Deployment Verification
- Objective: Deliver production-ready containerization, Docker Compose stack, Traefik integration, and end-to-end slice verification.
- Dependencies: Milestone 4.
- Requirements Satisfied:
REQ-11. - Work Items:
M5.1: Finalizeservices/worker/Dockerfileandservices/bff/Dockerfile.M5.2: Author canonicaldocker-compose.ymldefiningbff,worker, andtransmissionservices, volume mounts (./data,/media/movies), and internal/external networks.M5.3: Configure health probes: BFFGET /healthz, Worker gRPC standard health check.M5.4: Execute end-to-end integration test with a small public domain/legal torrent:- Verify full lifecycle: Form submission
\rightarrowTransmission download\rightarrowSanitizer scan\rightarrowMetadata token check\rightarrowTwo-stage atomic relocation into Jellyfin/Plex format\rightarrowLive SSE completion update.
- Verify full lifecycle: Form submission
- Verifiable Exit Criteria:
docker compose buildsucceeds with zero errors from a fresh checkout.- Full end-to-end vertical slice runs to completion with media appearing in
/media/movies/<Title> (<Year>) [imdbid-<IMDbID>]/.