Privacy & data¶
MuseFlow handles a sensitive dataset: years of listening behaviour. This page states what is stored, what is discarded, what leaves the machine, and where the design falls short. It is a description of the code as it stands, not a compliance statement.
flowchart LR
EXP["Spotify export files<br/>(JSON on disk)"] -->|"parse: keep 5 fields"| IMP["Import"]
IMP --> DB[("Local PostgreSQL<br/>tracks, ratings, profiles,<br/>playlists, OAuth tokens (encrypted)")]
DB -->|"artist - title, dates, play counts,<br/>ratings, tags, profile, blacklist"| ORT["OpenRouter gateway"]
ORT -->|"same prompt, ZDR endpoints only"| LLM["Model provider<br/>(Google, OpenAI, Anthropic...)"]
LLM --> ORT
ORT -->|"profile, suggestions, tags"| DB
DB -->|"search queries, playlist writes,<br/>playback control"| SPO["Spotify Web API"]
SPO -->|"catalogue matches,<br/>playlist id"| DB
U["User"] -->|"email, password hash,<br/>OAuth consent"| DB
Everything runs on the user's own machine; the only outbound traffic is to OpenRouter (which forwards the prompts to one model provider) and to Spotify. There is no MuseFlow-operated server and no telemetry.
What is stored locally¶
| Data | Where | Notes |
|---|---|---|
| Tracks: name, artists, album, provider id, aggregated play stats, rating, tags | museflow_track |
One row per track, not per play (Data model) |
| Taste profiles | museflow_taste_profile |
LLM-generated JSON, including a narrative summary of the listener |
| Playlists and membership | museflow_playlist, museflow_playlist_track |
Includes the reasoning and the prompt used |
| Blacklist | museflow_blacklisted_* |
Artists and tracks the user excluded |
| LLM usage | museflow_llm_usage |
Calls, tokens and cost per command run, step and model; no prompt or reply content |
| User | museflow_user |
Email and Argon2 password hash |
| Spotify OAuth tokens | museflow_auth_token |
Access and refresh token, encrypted (see Token encryption) |
| Raw export files | Wherever the user keeps them; a copy in the file storage (MUSEFLOW_FILE_STORAGE_DIR, .storage/ by default) during an import |
tracks history copies the history files under the user's own directory, imports them, then deletes the copy, also when the import fails. The originals are never modified |
What is dropped at import¶
A Spotify extended streaming-history export contains much more than listening data. Each entry carries fields such as ip_addr, conn_country, platform, reason_start, reason_end, shuffle, skipped, offline, incognito_mode, and episode and audiobook fields. The importer (providers/spotify/history.py) reads only:
| Kept | Used for |
|---|---|
ts |
Play timestamp, aggregated into first / last played |
ms_played |
Only to apply the minimum-duration filter; not stored |
spotify_track_uri |
Track id (entries without a valid spotify:track: URI are skipped, which also drops podcast episodes and audiobooks) |
master_metadata_track_name |
Track name |
master_metadata_album_artist_name |
Artist |
master_metadata_album_album_name |
Album |
IP address, country, device platform and playback behaviour are never read into the application's data structures (StreamingHistoryEntryInput has five fields), so they cannot reach the database, a prompt or a log. Individual play timestamps are reduced to a count plus first and last timestamp per track.
What leaves the machine¶
To OpenRouter and the model provider¶
Requests go to OpenRouter, authenticated with an API key sent in the Authorization: Bearer header. OpenRouter forwards each prompt to one provider endpoint serving the requested model, so two parties see it: the gateway and the provider. Every request asks for:
zdr: true(OPENROUTER_ZDR, on by default): only route to endpoints with a Zero Data Retention policy, which neither store prompts and completions nor train on them;data_collection: deny, always: never route to an endpoint whose provider declares collecting user data (for instance to train on it), even with ZDR turned off.
A model with no compliant endpoint is refused rather than routed to a retaining one: each command checks the public ZDR endpoint list before its first paid call, and OpenRouter answers 404 if a request gets through anyway. No user id, email, IP address or Spotify identifier appears in any prompt builder (advisors, profilers and enrichers under museflow/infrastructure/adapters/).
| Call | Content sent |
|---|---|
| Profile segment | Up to --track-limit tracks (default 3,000), one line each: first-played date, last-played date, play count, rating if any, artists and title |
| Profile merge, reflect | The profile JSON built so far (tags, weights, eras, traits) |
| Advisor | Text summaries derived from the profile, up to 200 highly rated and 50 low-rated tracks (artist and title), the exclusion and already-known lists for the session, blacklisted artists and tracks, and the prompt the user typed, if any |
| Enricher | A list of {index, title, primary_artist} |
Two properties to be aware of. First, the listening history itself is sent (as artist-and-title lines with dates), because that is the input the profile is built from; a taste profile is also a behavioural summary of its owner. Second, the playlist discover prompt is free text forwarded verbatim, so what the user writes there leaves the machine too.
To Spotify¶
| Interaction | Content |
|---|---|
| OAuth | Client id and secret, authorisation code exchange, token refresh. Scopes requested: playlist-modify-public, playlist-modify-private, user-modify-playback-state, user-library-modify |
| Search | track:"..." artist:"..." queries built from LLM suggestions |
| Playlist writes | Create a playlist (private by default, description Auto-generated by museflow), add tracks in batches of 100, delete a playlist |
| Playback | Start a track on the user's active device (used by the interactive rating command) |
The listening history is not read from Spotify's API; it comes only from the export file. No read scope on the user profile or email is requested.
Secrets handling¶
- Configuration comes from environment variables and an optional
.env, loaded bypydantic-settings(SPOTIFY_*,OPENROUTER_*,DATABASE_*,MUSEFLOW_*)..envis git-ignored;.env.exampleholds placeholders.MUSEFLOW_JWT_SIGNING_KEY(signs the API's JWT) andMUSEFLOW_PROVIDER_TOKEN_ENCRYPTION_KEY(encrypts the provider tokens) are two distinct keys of at least 32 characters each. The secrets (OPENROUTER_API_KEY,SPOTIFY_CLIENT_SECRET,MUSEFLOW_JWT_SIGNING_KEY,MUSEFLOW_PROVIDER_TOKEN_ENCRYPTION_KEY) areSecretStr, masked in anyrepror dump of the settings, andOPENROUTER_BASE_URLonly acceptshttps, since every request carries the key and the listening history. - Passwords are hashed with Argon2. OAuth
statevalues come fromrandom.SystemRandom, are single-use and expire after 10 minutes. - An OAuth flow ends only for the user who started it (#101). The provider never calls the API: it sends the browser back to the client (a web page or a mobile app registered in
SPOTIFY_REDIRECT_URIS), which hands the code and the state toPOST /api/v1/{provider}/connect/completewith its own Bearer token, and the API accepts the code only when the state was issued to that user. Otherwise someone could start a flow on their own account and get another person to consent, which would store that person's Spotify tokens on the first account.provider connectgets the same check: the provider redirects to a loopback address (127.0.0.1), whose URL the user pastes into the terminal, so the code never leaves the machine that started the flow. Each flow, step by step: OAuth flows. - Logging policy forbids secrets (tokens, passwords, API keys); logs carry user ids, not emails. A grep of the logging calls finds no token or key being logged. This is enforced by convention and review, not by a redaction layer. The validation errors of a Spotify token response hide their input, as the OAuth code exchange logs them. When an LLM reply is unusable, the warning carries the failure kind only; the start of the reply, which may quote the user's taste, is logged at DEBUG.
- The tests use dummy credentials set in
pyproject.toml; WireMock stands in for both APIs, so the test suite never sends real data anywhere.
Known gaps¶
Stated plainly
These are real limitations of the current implementation. None is hidden by the design; each is a conscious scope decision for a single-user showcase project, and each would need work before a hosted, multi-user service.
- Email is the user identifier. The CLI selects a user by
--emailorMUSEFLOW_CLI_DEFAULT_EMAIL, and email is stored in clear inmuseflow_user. It is never sent to OpenRouter or Spotify, but it is the key people type into shell history unless they use the setting. A random handle or the internal UUID would be a better key. - Data retention rests on declared policies. ZDR and
data_collection: denyare routing filters applied by OpenRouter to the policies providers declare; MuseFlow cannot verify them. OpenRouter's own prompt logging is an account setting, outside the code, and nothing in MuseFlow detects or warns about it. SettingOPENROUTER_ZDR=falsewidens the routing to endpoints without a ZDR policy;data_collection: denystill excludes those that declare collecting user data. - OAuth tokens are encrypted, the key rotated by hand.
museflow_auth_tokenholds the access and refresh tokens encrypted with AES-SIV (#250), decrypted only when read; the rest of the database has no application-level encryption. The key sits in the environment next to the database credentials, so the encryption protects against a leaked dump or backup, not against a compromised host. The key rotates without a reconnect (#286): the former key stays a fallback that still decrypts untilprovider reencrypt-tokensencrypts every token again with the new one; nothing checks that the command ran before the fallback is dropped. Theprovider infocommand masks the tokens unless--show-tokensis passed, which asks for a confirmation first. Details: Token encryption. - No retention policy. Data stays until deleted by hand. The CLI provides deletes (
tracks delete,playlist delete,blacklist remove/purge), andusers deleteerases everything about a user in the database, as foreign keys cascade from the user row. Nothing expires data. - Commands commit step by step, not as one transaction. Use cases open one short transaction (a unit of work block) per step, deliberately: most flows (profile build, enrichment, history import, rating import) produce a partial state that is incomplete but valid, and keeping that progress (often paid LLM work) beats rolling it back; a re-run completes it. Remote side effects run first:
playlist discovercreates the Spotify playlist before writing anything locally, so a provider failure leaves no trace. Where a partial state would be wrong, the local writes share one transaction:discoversaves its tracks and its playlist together, or neither. What remains: a database failure right after a remote call leaves an orphan remote playlist (or, forplaylist delete --remote, a local row whose remote playlist is gone). A purge of orphans is a possible follow-up. - Fixtures should be synthetic. Sample export files under
tests/assets/history/mirror the real export layout, includingip_addr. Some values in them are not obvious placeholders; test data in a public repository should be fully synthetic. - The API reveals which emails have an account (accepted risk).
/users/loginanswers the same way, in the same time, for an unknown email and a wrong password, but/users/registerandPATCH /users/mestill answerEmail already registered. A neutral answer would need an email verification step: registration returns an access token straight away, and the application sends no email. This risk is accepted while MuseFlow is a local, single-user app in development: whoever can call the API already has the machine, and the priority is the recommendations, not a full user system. A hosted service would need that verification step, and rate limiting on these routes.