Backend Architecture β
The TuneCamp backend is a Node.js application built with Express, designed to be federated, decentralized, and music-content oriented.
Tech Stack β
- Framework: Express.js (TypeScript)
- Database: SQLite3 (
better-sqlite3) - Social Protocol: ActivityPub (via Fedify)
- Instance Discovery: Gossip over HTTP (federated discovery and NodeInfo crawling)
- Multimedia: FFmpeg for transcoding and metadata
Core Components β
1. Federated Discovery (modules/network/federated-discovery.service.ts) β
TuneCamp discovers other instances via gossip over HTTP β there is no central relay or shared registry.
- The instance crawls starting from a set of seeds (the TuneCamp instances followed via ActivityPub plus
TUNECAMP_FEDERATION_SEEDS). - Evaluates if each peer is an active TuneCamp instance via NodeInfo and stores reachable instances in the local SQLite database (
federated_instancestable). - Catalogs are then read and synced directly via HTTP REST.
2. ActivityPub Federation (modules/fedify/, modules/activitypub/) β
Allows TuneCamp to interact with other instances in the Fediverse (such as Mastodon, Funkwhale, or other TuneCamp instances).
- Implements ActivityPub Actor, Note, and other objects.
- Handles message delivery and retrieval of remote content.
3. Catalog Module (modules/catalog/) β
Responsible for scanning and organizing local music.
- Scanner: Scans folders for new audio files. To ensure granular control, the scanner creates albums in Draft mode in the local library. This content is not publicly visible until manually promoted to a Formal Release via the Admin Dashboard.
- Metadata: Extracts tags (ID3, Vorbis), generates waveforms, and integrates external providers (MusicBrainz, Discogs, iTunes, Lyrics.ovh) to enrich data and lyrics.
4. Security & Authentication (modules/auth/auth.service.ts, middleware/auth.ts) β
- Manages local users with bcrypt passwords.
- Authentication via JWT (secret from env,
.jwt-secretfile, or generated at first startup). - Role-Based Access Control (RBAC): Instance Owner, Manager, Curator, Listener (see ROLES.md).
5. Community: Live (modules/live/) β
- Live: In-memory registry of live sessions (
live.service.ts); media passes through the server. The artist's browser captures audio withMediaRecorderand sends webm chunks, whichHlsLiveService(hls.service.ts) feeds to a persistent FFmpeg process. FFmpeg produces a rolling HLS playlist (AAC segments) served to all listeners: a single shared encoding, not a copy per listener as in the legacy WebRTC mesh.
6. Blockchain Integration (modules/publishing/, routes api/payments.ts) β
Interfaces with smart contracts to handle prices, payments, and content unlocking.
Data Model β
TuneCamp uses SQLite as its relational database engine for managing music metadata, users, and social interactions. The database is initialized and updated automatically in src/server/core/database.ts, which contains DDL scripts for table creation and idempotent migrations (ALTER TABLE ... ADD COLUMN) executed at application startup.
Core Entities (Music Library) β
artists: Stores information about artists (name, biography, image, federated identifiers).artist_events: Upcoming live dates, concerts, and tour events for artists.albums: Represents releases (title, artist, year, cover art).tracks: Individual audio tracks (title, album, track number, duration, file path, bitrate,genre,fingerprintfor internal deduplication). Genre is a column ontracks, not a separate table.album_ownership/track_ownership: On-chain ownership (NFT) of albums and tracks.
Users & Social β
admin: Table of all local accounts (all roles, not just admin: the name is historical). Includesrole,password_hash,artist_id, storage quotas.password_reset_tokens: Time-limited cryptographic tokens for Brevo-powered email password resets.zen_users: FID/Zen identity profile cache (pub key, alias, avatar), kept in sync withadmin.zen_pubfor cross-instance SSO login.zen_cache: Legacy table from the removed ZEN sync layer β retained for schema compatibility but no longer written to.fid_registry: Federation identity passports and cryptographic claim verification registry.followers/following: Follow relations between local users and remote ActivityPub actors.posts/ap_notes: Messages and activities in the Fediverse.board_messages: Community pinboard / public bulletin board messages.starred_items/item_ratings: User favorites and track ratings.comments: User comments on tracks and releases.reports: Copyright and content abuse reports awaiting moderation in the admin panel.bookmarks: Personal user bookmarks.
Retired: chat tables β
Peer chat was removed; peer_chat_messages, peer_chat_bans, peer_chat_mutes, chat_rooms, chat_room_members and chat_room_messages are still created for rollback safety but nothing reads or writes them. Dropping them is a pending migration.
P2P Peer Sharing (Sidecamp) β
peer_sessions: Active daemon connection sessions authenticated over/ws/peer.peer_tracks/peer_tracks_new: Ephemeral track manifests shared by active Sidecamp daemons.peer_catalog_cache: SQLite cache of remote instances' peer catalogs for federated network browsing.
Federation (ActivityPub & Discovery) β
remote_actors: Cache of remote user profiles discovered via ActivityPub.remote_content: Local copy of metadata for federated content (e.g., posts from other servers).ap_interactions/ap_replies/ap_following/ap_delivery_queue/fedify_kv: ActivityPub state, actor signatures, and outbound delivery queue.federated_instances: Discovered network peers tracked by the HTTP gossip discovery service.
Advanced Features β
playlists/playlist_tracks: User playlist management and track order.play_history: Listens log for stats, scrobbling, and recommendations.unlock_codes: Access codes for protected or paid content.torrents: File sharing integrations for retrieving content (P2P acquisition itself lives in the companion Sidecamp app).assets/storage_accounts: Store assets and connected cloud storage accounts (e.g., Google Drive).track_stats/release_stats: Aggregated play counters and listening time analytics.settings: Instance configuration key/value store.api_tokens/oauth_clients/oauth_links: Personal API tokens (e.g. MCP) and OAuth linkages.system_plugins: State (enabled/disabled) of modular plugin providers.samples/sample_packs: Free (non-store) sample uploads β BPM, key, license, moderation status. A sample optionally belongs to a pack viasamples.pack_id.collab_projects/collab_versions/collab_stems: Multi-artist collaborative track building with append-only versions and audio stem uploads.
Key Relationships β
- One-to-Many: An
artisthas manyalbums. Analbumhas manytracks. - Many-to-Many: A
playlistcontains manytracksvia theplaylist_trackspivot table. - Federation: A local
postcan be linked to an actor inremote_actors.
Data Access β
Data access logic is encapsulated in Repositories (src/server/repositories/), which use direct SQL queries or lightweight query builders to interact with better-sqlite3.
Reliability & Monitoring β
- The
GET /healthendpoint is registered before the federation middleware, so a blocked integration cannot shadow it (used by the DockerHEALTHCHECK). - Opt-in Sentry crash reporting via
SENTRY_DSN(see monitoring.md).
Data Flows β
- Scanning: The
Scannerdetects a file -> the metadata service extracts the data -> the repository saves it to the DB. - Streaming: API request -> verify permissions -> file stream (with FFmpeg transcoding if necessary).
- Social: New post -> the ActivityPub service creates the object -> Fedify delivers it to remote actors.
REST API β
Endpoints are split into thematic routes in src/server/routes/:
/api/tracks,/api/albums,/api/artists: Library management./api/admin: Administration features./api/ap: Endpoints for ActivityPub federation./api/live: Live sessions./rest: Compatibility with the Subsonic/OpenSubsonic protocol./health: Health check.