Skip to content

Data model ​

SQLite database: prisma/dev.db. Prisma schema: prisma/schema.prisma.

This project keeps Prisma migrations in prisma/migrations. Production applies them automatically on start when AUTO_MIGRATE is not false; local development can apply them with bun run db:deploy or continue using bun run db:push for schema-only changes.

Release ​

Owned release/edition.

FieldNotes
idCUID primary key
musicbrainzIdUnique when present; null for manual records
title, artistDisplay fields; updated by enrichment/refresh
artistIdMusicBrainz artist MBID when known
yearParsed release year
releaseDateDate-ish string; date-only when known
countryRelease country
label, catalogNumber, barcodeRelease identifiers
formatNormalized category: CD, Vinyl, Cassette, Digital, Other
formatDetailRaw MusicBrainz/Discogs format string
coverUrlCover Art Archive URL or upload:<sha256>.<ext> for uploaded art, rendered through the matching proxy route
notesUser-owned text
rating1–5 or null
conditionUser-owned condition label
purchaseDateYYYY-MM-DD when known
purchaseLocationShop/place
purchasePriceNumber or null
purchaseCurrencyISO-style code, e.g. EUR
genresComma-separated string
trackCountCached count, also derived from tracks on import/refresh
createdAt, updatedAtManaged timestamps

Indexes: artist, format, year, createdAt.

Track ​

Child of Release.

FieldNotes
idCUID
releaseIdFK, cascade delete
positionGlobal ordering integer
discDisc number when multi-disc
numberTrack number within disc
titleRequired
durationSeconds or null
artistTrack artist if different from release artist

Display/order rule: disc, then number, then position. On refresh/enrichment, tracks are deleted and recreated in one transaction.

ReleaseSearch (FTS5) ​

SQLite FTS5 virtual table maintained by triggers, not Prisma models. Not part of exports.

ColumnNotes
release_idUNINDEXED; matches Release.id
title, artist, label, catalog, genresMirrored release fields
tracksSpace-joined track titles

Migration: prisma/migrations/20261111190000_search_fts. Triggers rebuild the row on release and track insert/update/delete. If the table is missing (dev DB not migrated), /api/search falls back to Prisma contains queries.

WishlistItem ​

Separate from owned releases.

FieldNotes
idCUID
musicbrainzIdUnique when present; absent for release-group-only items
releaseGroupIdUnique when present; set when adding a Discover release group
title, artist, artistIdSame semantics as Release
year, releaseDate, country, label, catalogNumber, barcodeOptional metadata
format, formatDetail, coverUrlOptional/display data
notesUser notes
targetPrice, targetCurrencyOptional target
createdAt, updatedAtTimestamps

No tracklist, condition, rating or purchase fields: wishlist items are not owned copies. Wishlist means buy intent only.

SavedSuggestion ​

Lightweight Discover bookmark, kept out of Wishlist until the user decides to buy.

FieldNotes
idCUID
releaseGroupIdUnique MusicBrainz release-group MBID
title, artist, artistIdDisplay metadata
year, releaseDate, coverUrlOptional metadata
typeAlbum, EP, etc.
createdAtSaved timestamp

Promoting a saved suggestion creates a WishlistItem and deletes the saved row. Saved suggestions are not part of wishlist counts or target totals.

Wishlist is not part of collection stats.

ArtistFollow ​

Explicit “show me more from this artist” signal. It is not a wishlist or saved item and does not imply ownership.

FieldNotes
artistIdMusicBrainz artist MBID, primary key
nameDisplay name captured when followed
createdAtFollow timestamp

Index: name. Follows feed Discover affinity and similar-artist seeds. Unfollowing only removes the signal; it creates no negative event. Followed artists are never excluded from Discover.

AppSettings ​

Single-row table for library defaults that must survive browser storage loss and be included in backups.

FieldNotes
idAlways default
defaultFormatDefault format for manual releases
defaultConditionDefault condition on new entries
defaultCurrencyDefault purchase currency
updatedAtLast update

Missing row means built-in defaults; the API returns defaults without creating a row.

MetadataCache ​

Persistent MusicBrainz payload cache.

FieldNotes
keyPrimary key, e.g. mb:release:<mbid>
payloadJSON string
expiresAtTTL expiry
createdAt, updatedAtTimestamps

Index: expiresAt.

TTL tiers (see server/musicbrainz.ts):

  • search/artist search/genre search: 30 minutes
  • release detail/artist detail/group pages: 7 days
  • empty search result: 10 minutes

Expired rows are deleted on access and opportunistically pruned. Clearing this table does not touch the collection.

DiscoveryFeed ​

Single cached Discover payload.

FieldNotes
idAlways current
payloadJSON discovery feed, including algorithm version
generatedAtLast generation time
expiresAtFeed TTL (7 days)

?refresh=1 replaces this row immediately.

DiscoverySeen ​

Release groups already shown in Discover.

FieldNotes
releaseGroupIdMusicBrainz release-group MBID, primary key
artistIdOptional artist MBID
seenAtLast time shown

Rows older than 30 days are pruned. Seen items are deprioritised when building a new feed, not hard-excluded, so sparse collections still get suggestions.

DiscoveryEvent ​

Implicit Discover interaction log. No UI prompt creates these rows.

FieldNotes
idCUID
releaseGroupIdRelease group shown/opened
artistIdOptional artist MBID
artistArtist display name fallback
actionopen, remove-save
createdAtEvent time

Indexes: releaseGroupId, artistId, createdAt. Rows older than 180 days are pruned. Opens add a small positive affinity signal; removing a saved suggestion adds a small decaying negative signal. See Discovery.

Cover cache ​

Not in SQLite. Cover Art Archive images are cached on disk:

  • directory: data/covers/ (or COVER_CACHE_DIR)
  • <sha256>.bin image + <sha256>.json metadata (contentType, size, url)
  • ignored by git
  • 5MB per image limit

Uploaded covers ​

User-uploaded art is stored outside the prunable cache:

  • directory: data/uploads/covers/ (or COVER_UPLOAD_DIR)
  • filename: <sha256>.<jpg|png|webp|gif>, content-addressed and deduplicated
  • database value: coverUrl = upload:<filename>
  • served by /api/covers/upload/<filename>
  • 8MB upload limit after browser-side downscale to max 1600px WebP
  • uploaded art is user-owned: metadata refresh and apply-match keep it, and only the release edit form clears or replaces it
  • the UI offers MusicBrainz art or an upload, with no cover URL entry; legacy non-CAA URLs still render and are preserved
  • cleanup has three layers: editor close deletes an unreferenced upload it created, release update/delete and replace imports delete the exact files they orphan, and an hourly sweep plus startup sweep remove stale leftovers older than one hour
  • prune removes files that no release, wishlist item or saved suggestion references

The cover cache at data/covers/ remains disposable CAA cache and is never used for uploads.

Settings ​

Hybrid storage:

Browser localStorage, key sleeve:settings:v1:

  • theme
  • accent palette
  • default view (grid / list)
  • default sort

SQLite AppSettings:

  • default format
  • default condition
  • default currency

UI preferences stay device-local and load synchronously before paint. Library defaults are part of app data, survive browser storage loss and are included in JSON export/import.

Invariants ​

  • Owned data lives in Release/Track; remote MusicBrainz payloads only in MetadataCache.
  • Discover state lives in DiscoveryFeed/DiscoverySeen/DiscoveryEvent; clearing it must not affect the collection.
  • ArtistFollow is a taste signal, not an acquisition state. It must not create wishlist or saved rows.
  • AppSettings stores library defaults only. Theme, accent, view and sort stay in browser storage.
  • format is always a normalized category. Keep the raw string in formatDetail.
  • genres is comma-separated; ingestion dedupes case-insensitively.
  • MB IDs are unique, but multiple null values are allowed.
  • Preserve user-owned fields on refresh/enrichment: condition, rating, notes, purchase date/location/price/currency, chosen format and uploaded cover.
  • An uploaded cover is user-owned even when enrichment has a CAA image.
  • Dates are date-only strings where possible; prices are numbers.
  • Deleting a release must cascade-delete tracks.
  • Wishlist and library are independent; an item can exist in both unless application logic prevents it.

Export format ​

GET /api/export:

json
{
  "app": "sleeve",
  "version": 1,
  "exportedAt": "2026-11-09T…",
  "releases": [
    {
      "id": "…",
      "musicbrainzId": "…",
      "title": "…",
      "artist": "…",
      "tracks": [{ "id": "…", "releaseId": "…", "position": 1, "title": "…" }],
      "…": "all Release fields"
    }
  ],
  "wishlist": [
    { "id": "…", "title": "…", "artist": "…", "…": "all WishlistItem fields" }
  ],
  "saved": [
    { "id": "…", "title": "…", "artist": "…", "…": "all SavedSuggestion fields" }
  ],
  "follows": [
    { "artistId": "…", "name": "…", "createdAt": "…" }
  ],
  "settings": {
    "defaultFormat": "CD",
    "defaultCondition": "Near Mint",
    "defaultCurrency": "EUR"
  }
}

JSON is the collection export format. When uploaded covers exist, export is a zip containing this library.json plus covers/<filename>; import reads the zip and sends library.json with the cover files to /api/import/upload. Discogs CSV is import-only.

Database snapshots ​

Automatic pre-import-*.db snapshots live in data/backups (or BACKUP_DIR); the last 5 are kept. Exact restore is CLI-only and requires the server stopped. See Operations § Backups.

Import rules ​

POST /api/import?mode=merge accepts JSON exports or a bare releases array. mode=replace requires a full Sleeve JSON object.

  • IDs from the payload are ignored; new CUIDs are generated.
  • createdAt is preserved for releases, wishlist items, saved suggestions and follows.
  • If musicbrainzId exists, dedupe by MBID only. This permits separate editions.
  • If musicbrainzId is null, dedupe by normalized title|artist|format.
  • Wishlist uses the same rules.
  • Saved suggestions dedupe by releaseGroupId.
  • Followed artists dedupe by artistId.
  • Settings patch current library defaults when present.
  • Invalid rows are counted and skipped; the rest still import.
  • Tracks are created with the release in the same transaction.
  • genres accepts string or array.
  • Date strings are stored as provided; CSV mapping normalizes to date-only.
  • coverUrl values beginning with upload: must have a matching cover file in the backup; missing files reject the restore before any write.

Replace mode also clears DiscoveryFeed, DiscoverySeen and DiscoveryEvent so the next Discover build reflects the restored collection. Metadata and cover caches are kept. If the backup has no settings, library defaults reset to built-in values.

Every import creates a pre-import-*.db snapshot first. If snapshot creation fails, nothing is written.

Discogs CSV mapping ​

The browser maps CSV columns to Sleeve fields. Normalization before hitting /api/import:

  • format string → normalized category; raw string → formatDetail
  • rating 0 → null; 1–5 kept
  • condition strings → Sleeve labels (Near Mint, Very Good Plus, …)
  • released → year and date-only release date
  • Date Added → purchase date
  • 3,50 / 3.50 → number
  • missing title/artist → row skipped