Technical overview¶
MuseFlow is a Python backend with a CLI as its primary interface and a small FastAPI surface for the OAuth connection and user endpoints. It is organised as a hexagonal (ports and adapters) application. This section documents how it is built and why, with each claim traceable to code in the repository.
Stack¶
| Concern | Choice | Notes |
|---|---|---|
| Language / tooling | Python 3.14, uv |
Dependencies locked in uv.lock; Makefile wraps every workflow |
| Entrypoints | Typer (CLI), FastAPI (API) | Both are thin: parse, call a use case, render |
| Persistence | PostgreSQL, SQLAlchemy 2 async (asyncpg), Alembic |
PostgreSQL-specific features on purpose: JSONB, ARRAY, ON CONFLICT upserts |
| Validation | Pydantic v2, pydantic-settings |
External DTOs, structured LLM output, settings |
| HTTP | httpx (async) + tenacity |
One shared client mixin, per-adapter retry policies |
| LLM | OpenRouter gateway (OpenAI-compatible REST) | Any model it lists, one per pipeline step (see LLM pipeline) |
| Security | argon2-cffi, PyJWT, cryptography |
Password hashes, signed API tokens, provider tokens encrypted at rest (see Token encryption) |
| Matching | unidecode |
Text normalisation: fingerprints, and the strict artist match of discovery |
| Quality | pytest, polyfactory, WireMock, Ruff, mypy, deptry, pre-commit | See Quality & testing |
Size at a glance¶
Measured on the current HEAD of the branch this documentation was written on:
| Metric | Value |
|---|---|
Source (museflow/, Python lines) |
~12,100 |
Tests (tests/, Python lines) |
~21,300 |
| Test functions | 1,000 across 146 test files (721 unit, 279 integration) |
| Coverage gate | 100% branch, enforced by fail_under = 100 |
| Alembic migrations | 1 (a squashed initial migration, edited in place during V2 development, see Data model) |
Where to go next¶
-
Architecture
Layers, the dependency rule, ports and adapters, and a sequence diagram of
playlist discoverfrom CLI to Spotify. -
Why a unit of work
Who opens and closes transactions: the common patterns, why a session per command failed, and the short blocks that fixed it.
-
Data model
Tables, the fingerprint identity, per-track play aggregation, the genre and mood vocabularies.
-
LLM pipeline
Profiler, advisor and enricher; model choice per step; retries and self-healing of structured output.
-
Logging & output
stdout for results, stderr for diagnostics; the console, Rich and JSON handlers;
--verboseversusDEBUG. -
Privacy & data
What is stored, what is dropped at import, what leaves the machine, and the known gaps stated plainly.
-
Quality & testing
Integration-first testing, the 100% branch gate, static analysis and CI.
-
AI-assisted development
How conventions, an
AGENTS.mdcontract, review skills and agents were introduced and pruned, with dates and commits. -
Contributing
Make targets, commit conventions and the PR checklist.