Development
The source is on GitHub. It’s Python 3.12 with Streamlit 1.67, pandas 3 and Plotly 7, plus FastAPI for the mobile API (since 0.7.0).
Project layout
Section titled “Project layout”app.py # Streamlit shell: navigation, sidebar, sign-in gatingsonarr_analyzer/ analysis.py # Streamlit-free analysis pipeline (metrics, outliers, re-encode estimates) sonarr_client.py # Sonarr API client (URL validation, retries, parallel fetching) media.py # Codec names, runtimes and disk usage from Sonarr media info forecast.py # Storage trend, R², disk runway overview.py # Dashboard/sidebar numbers built from saved history storage.py, db.py # History database and schema migrations auth.py, security.py # Users (bcrypt, lockout) and encrypted Sonarr credentials scheduler.py # Scheduled analyses (thread or `python -m sonarr_analyzer.scheduler`) dashboard.py # Which candidates, outliers and changes the Dashboard lists (web and API) api.py # Mobile API (FastAPI, served by uvicorn on port 8502) tls.py # Self-signed certificate and its fingerprint (`python -m sonarr_analyzer.tls`) healthcheck.py # Container health check, http or https config.py # Environment variables ui/ # Shared components, session state and one module per pagetests/ # pytest suite fixtures/api/ # Example API responses: the contract the mobile apps code againstspec/, tasks/ # Specs and task lists for the mobile API and appsdocs/design/ # UI design reference (direction C, "dense console").streamlit/config.toml # Light and dark themeRun it locally
Section titled “Run it locally”pip install -r requirements.txtstreamlit run app.pyThe mobile API is a separate process. Run it next to the web app (both read the same data/ folder):
uvicorn sonarr_analyzer.api:app --port 8502 --reloadcurl http://localhost:8502/api/v1/healthRun it with a single worker (uvicorn’s default): the sign-in rate limit is kept in memory, per process.
pip install -r requirements-dev.txtpytest -vpytest --cov=sonarr_analyzer --cov-report=htmlTo run them in the same environment as the image:
docker run --rm -v "$PWD":/src -w /src python:3.12-slim \ sh -c "pip install -q -r requirements-dev.txt && pytest -q"The suite covers authentication, token encryption, storage, schema migrations from v0.3/v0.4/v0.6, the analysis pipeline, media metadata, the forecast and dashboard overview, the Sonarr client, the scheduler, the mobile API, the self-signed certificate, the health check, and UI tests for every page (Streamlit AppTest).
API contract fixtures
Section titled “API contract fixtures”tests/test_api.py compares the API’s responses with the JSON files in tests/fixtures/api/. The mobile apps copy these files into their own tests, so they are the contract between the server and the apps. When you change a response on purpose, regenerate them and review the diff:
UPDATE_API_FIXTURES=1 pytest tests/test_api.pygit diff tests/fixtures/api/Floats are compared rounded to 6 decimals, because numpy’s least-squares fit differs in the last digits between arm64 and amd64 (CI).
Build the image
Section titled “Build the image”docker build -t sonarr-analyzer:local .Releases are published for both architectures, as vX.Y.Z and latest:
docker buildx build --platform linux/amd64,linux/arm64 \ -t martitoci/sonarr-analyzer:vX.Y.Z -t martitoci/sonarr-analyzer:latest --push .Contributing
Section titled “Contributing”- Fork the repository and create a feature branch.
- Install the dev tools:
pip install -r requirements-dev.txt && pre-commit install. - Add tests for new features.
- Run
pytestand make sure everything passes. CI also runs pre-commit,pip-auditand a Docker smoke test. - Open a pull request.
The project is MIT-licensed.