Skip to content

Database Architecture

Derrik Diener edited this page Jul 16, 2026 · 1 revision

Database Architecture

Supernova utilizes SQLite3 running in WAL (Write-Ahead Logging) mode. This allows the server to handle concurrent read operations (like audio streaming to multiple devices) without locking up during write operations (like background library scanning or plugin tasks).

Core Tables

users

Tracks system users. Stores login credentials via bcrypt hashes. Passwords are theoretically safe even if the .db file is compromised.

artists & albums

Store library entities. They include musicbrainz_id for external API reconciliation and bio/image_url fields for UI richness.

tracks

The central hub for media.

  • Integrity: file_path is strictly enforced as UNIQUE NOT NULL to prevent scanning the same file multiple times.
  • Foreign Keys: Enforces ON DELETE CASCADE to the albums table. If an album is deleted, all tracks are purged from the DB automatically.

Junction Tables

Because a track can have multiple artists (e.g., featured artists), and an album can be a collaboration, Supernova uses many-to-many junction tables:

  • track_artists: Maps track_id -> artist_id.
  • album_artists: Maps album_id -> artist_id with a specific role (e.g., primary, featured, producer).

User Interaction Tables

hearts

Stores user favorites. Polymorphic mapping is handled via entity_type (track, album, artist, playlist) and entity_id.

playlists & playlist_tracks

Standard playlist implementation. playlist_tracks tracks the exact position of a song in the list.

scrobbles

An internal log of a user's listening history.

Performance Tuning

To ensure API responses return in milliseconds even with hundreds of thousands of tracks, Supernova applies critical indexes:

  • idx_tracks_album_id
  • idx_tracks_file_path
  • idx_artists_name
  • idx_scrobbles_user_id_time

Migration System

Supernova handles database migrations internally using the SQLite PRAGMA user_version. When the server starts, it checks this version and automatically applies delta SQL patches (e.g., migrating to version 4 to add file_modified_at or ignored_files).

Clone this wiki locally