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.
| Field | Notes |
|---|---|
id | CUID primary key |
musicbrainzId | Unique when present; null for manual records |
title, artist | Display fields; updated by enrichment/refresh |
artistId | MusicBrainz artist MBID when known |
year | Parsed release year |
releaseDate | Date-ish string; date-only when known |
country | Release country |
label, catalogNumber, barcode | Release identifiers |
format | Normalized category: CD, Vinyl, Cassette, Digital, Other |
formatDetail | Raw MusicBrainz/Discogs format string |
coverUrl | Cover Art Archive URL or upload:<sha256>.<ext> for uploaded art, rendered through the matching proxy route |
notes | User-owned text |
rating | 1–5 or null |
condition | User-owned condition label |
purchaseDate | YYYY-MM-DD when known |
purchaseLocation | Shop/place |
purchasePrice | Number or null |
purchaseCurrency | ISO-style code, e.g. EUR |
genres | Comma-separated string |
trackCount | Cached count, also derived from tracks on import/refresh |
createdAt, updatedAt | Managed timestamps |
Indexes: artist, format, year, createdAt.
Track
Child of Release.
| Field | Notes |
|---|---|
id | CUID |
releaseId | FK, cascade delete |
position | Global ordering integer |
disc | Disc number when multi-disc |
number | Track number within disc |
title | Required |
duration | Seconds or null |
artist | Track 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.
| Column | Notes |
|---|---|
release_id | UNINDEXED; matches Release.id |
title, artist, label, catalog, genres | Mirrored release fields |
tracks | Space-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.
| Field | Notes |
|---|---|
id | CUID |
musicbrainzId | Unique when present; absent for release-group-only items |
releaseGroupId | Unique when present; set when adding a Discover release group |
title, artist, artistId | Same semantics as Release |
year, releaseDate, country, label, catalogNumber, barcode | Optional metadata |
format, formatDetail, coverUrl | Optional/display data |
notes | User notes |
targetPrice, targetCurrency | Optional target |
createdAt, updatedAt | Timestamps |
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.
| Field | Notes |
|---|---|
id | CUID |
releaseGroupId | Unique MusicBrainz release-group MBID |
title, artist, artistId | Display metadata |
year, releaseDate, coverUrl | Optional metadata |
type | Album, EP, etc. |
createdAt | Saved 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.
| Field | Notes |
|---|---|
artistId | MusicBrainz artist MBID, primary key |
name | Display name captured when followed |
createdAt | Follow 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.
| Field | Notes |
|---|---|
id | Always default |
defaultFormat | Default format for manual releases |
defaultCondition | Default condition on new entries |
defaultCurrency | Default purchase currency |
updatedAt | Last update |
Missing row means built-in defaults; the API returns defaults without creating a row.
MetadataCache
Persistent MusicBrainz payload cache.
| Field | Notes |
|---|---|
key | Primary key, e.g. mb:release:<mbid> |
payload | JSON string |
expiresAt | TTL expiry |
createdAt, updatedAt | Timestamps |
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.
| Field | Notes |
|---|---|
id | Always current |
payload | JSON discovery feed, including algorithm version |
generatedAt | Last generation time |
expiresAt | Feed TTL (7 days) |
?refresh=1 replaces this row immediately.
DiscoverySeen
Release groups already shown in Discover.
| Field | Notes |
|---|---|
releaseGroupId | MusicBrainz release-group MBID, primary key |
artistId | Optional artist MBID |
seenAt | Last 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.
| Field | Notes |
|---|---|
id | CUID |
releaseGroupId | Release group shown/opened |
artistId | Optional artist MBID |
artist | Artist display name fallback |
action | open, remove-save |
createdAt | Event 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/(orCOVER_CACHE_DIR) <sha256>.binimage +<sha256>.jsonmetadata (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/(orCOVER_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 inMetadataCache. - Discover state lives in
DiscoveryFeed/DiscoverySeen/DiscoveryEvent; clearing it must not affect the collection. ArtistFollowis a taste signal, not an acquisition state. It must not create wishlist or saved rows.AppSettingsstores library defaults only. Theme, accent, view and sort stay in browser storage.formatis always a normalized category. Keep the raw string informatDetail.genresis 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:
{
"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.
createdAtis preserved for releases, wishlist items, saved suggestions and follows.- If
musicbrainzIdexists, dedupe by MBID only. This permits separate editions. - If
musicbrainzIdis null, dedupe by normalizedtitle|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.
genresaccepts string or array.- Date strings are stored as provided; CSV mapping normalizes to date-only.
coverUrlvalues beginning withupload: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 dateDate Added→ purchase date3,50/3.50→ number- missing title/artist → row skipped