From df83a1b9fbada24b62e071eb2899727a8e89b3fc Mon Sep 17 00:00:00 2001 From: orfelorfel23 Date: Wed, 18 Nov 2026 00:56:13 +0100 Subject: [PATCH] docs: unify bilingual README/LIESMICH, logo, and repo cleanup --- LIESMICH.md | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 214 ++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 390 insertions(+), 30 deletions(-) create mode 100644 LIESMICH.md diff --git a/LIESMICH.md b/LIESMICH.md new file mode 100644 index 0000000..620ee61 --- /dev/null +++ b/LIESMICH.md @@ -0,0 +1,206 @@ +

+ KeySelector Logo +

+ +

KeySelector

+

Ein browserbasierter harmonischer DJ-Assistent mit Live-Audio-Erkennung, interaktivem Camelot Wheel und PostgreSQL-Track-Katalog.

+ +

+ πŸ‡¬πŸ‡§ English Β· πŸ‡©πŸ‡ͺ Deutsch +

+ +--- + +## Überblick + +**KeySelector** ist eine leichtgewichtige, Local-First-Webanwendung fΓΌr DJs, die laufende Tracks erkennt, deren musikalische Tonart (als **Camelot-Code** sowie klassische Tonart) und **BPM** bestimmt und direkt harmonisch sowie rhythmisch passende Folge-Tracks vorschlΓ€gt. + +```text +β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” HTTP / REST β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” +β”‚ Browser (Vanilla JS SPA) β”‚ ◄───────────────────► β”‚ Node.js / Express (:3000) β”‚ +β”‚ β€’ System- / Mikro-Audio β”‚ β”‚ β€’ /api/recognize (ACR/AudD) β”‚ +β”‚ β€’ Interaktives SVG-Wheel β”‚ β”‚ β€’ /api/metadata (ffmpeg) β”‚ +β”‚ β€’ Live-Suche & Filter β”‚ β”‚ β€’ /api/suggestions β”‚ +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β€’ /api/search, /cover β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + β”‚ pg Pool + β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” + β”‚ PostgreSQL (26.000+ Tracks) β”‚ + β”‚ + In-Memory-Fallback β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +``` + +--- + +## Funktionen + +- **Live-Audio-Erkennung (`POST /api/recognize`):** Erfasst wahlweise **PC- / System-Audio** (via `getDisplayMedia` fΓΌr VLC, DJ-Software, Browser-Tabs, YouTube), **Mikrofon** oder ein **spezifisches EingabegerΓ€t**, zeigt einen Live-Eingangspegel und erkennt Songs ΓΌber **ACRCloud** oder **AudD**. +- **Mehrstufige Metadaten- & Audioanalyse (`GET /api/metadata`):** Ermittelt Tonart, BPM, Genre-Tags, Dauer, Cover und 30-Sekunden-HΓΆrprobe ΓΌber PostgreSQL (Exakt- und Fuzzy-Suche), **Deezer API**, **SongBPM**, **GetSongBPM**, **Last.fm** sowie eine integrierte **FFmpeg**-Preview-Analyse (Onset-Autokorrelation fΓΌr BPM + Goertzel-Chroma-Analyse fΓΌr den Camelot-Key). +- **Harmonische Mix-VorschlΓ€ge (`GET /api/suggestions`):** Nutzt die Mixed-In-Key-/Camelot-Regeln (`Perfect`, `Quinte -1`, `Quinte +1`, `Energy`, `Scale`, `Diagonal`, `Jaw's`, `Mood`) mit schrittweiser BPM-Toleranz-Erweiterung (`Β±6%`, `Β±12%`, `Β±20%`, bis `50–220 BPM`) sowie UI-Filtern fΓΌr Mix-Typ und Pitch-Toleranz (`Β±4% (DJ)`, `Β±8%`, `Alle BPM`). +- **Interaktives Camelot Wheel (`public/wheel.js`):** Zeichnet ein 24-teiliges SVG-Camelot-Wheel (Γ€ußerer Dur-Ring `B`, innerer Moll-Ring `A`), hebt kompatible Tonarten hervor und lΓ€sst sich per Klick vergrâßern. +- **Hybride Live-Suche (`GET /api/search`):** Durchsucht zuerst die lokale PostgreSQL-Datenbank und ergΓ€nzt Treffer aus der **Deezer Search API** inklusive 30s-Audio-Vorschau und Direktlinks zu Spotify, Deezer und YouTube. +- **Dauerhafte Key- & BPM-Korrekturen (`POST /api/tracks/correct`):** Ein Klick auf die Key- oder BPM-Kachel ΓΆffnet ein Korrektur-Modal; gespeicherte Werte erhalten `is_corrected = TRUE` in PostgreSQL und haben bei kΓΌnftigen Suchen Vorrang. +- **Audio-Attribute & Cover-Zoom:** Zeigt Tunebat-Γ€hnliche Werte (Dauer, Energy, Danceability, Mood) an und unterstΓΌtzt Cover-Zoom sowie 30s-Vorschau-Wiedergabe. +- **Dark / Light Mode:** Nahtloser Theme-Wechsel ΓΌber CSS Custom Properties. +- **26.000+ Track-Seed:** Initialisiert beim Start automatisch 24-Key-Referenzdaten (`db/schema.sql`) und importiert `db/spotify_songs.csv` (`server/importer.js`), sobald weniger als 5.000 Tracks in der Datenbank liegen. + +--- + +## Funktionsweise & Tech-Stack + +Das Frontend (`public/`) benΓΆtigt **keinen Build-Schritt** und wird zusammen mit den Modulen in `shared/` direkt von Express (`server/index.js`) ausgeliefert. Die gemeinsamen JavaScript-Dateien in `shared/` funktionieren sowohl in Node.js (`require`) als auch im Browser (`window.*`), sodass Camelot-Geometrie, Farben und Harmonieregeln identisch bleiben. Ist PostgreSQL beim Start nicht erreichbar, schaltet `server/db.js` automatisch auf einen In-Memory-Fallback (`Map`) um. + +| Komponente | Technologie / Details | +|---|---| +| Frontend | Reines HTML5, CSS3 (Custom Properties), Vanilla JavaScript (`public/`) | +| Backend | Node.js 22 (`node:22-alpine` im Docker-Image), Express `^4.18.2`, Multer `^2.2.0`, Axios `^1.19.0` | +| Audioverarbeitung | `ffmpeg` & `chromaprint` (im Docker-Image enthalten), eigene PCM-BPM- & Key-Analyse | +| Datenbank | PostgreSQL (`postgres:15-alpine`, `pg` `^8.23.0`) mit In-Memory-Fallback | +| Externe APIs | ACRCloud, AudD, Deezer, SongBPM, GetSongBPM, Last.fm, iTunes Search API | +| Ports | Backend lauscht auf `3000` (in `docker-compose.yml` auf `3030:3000` gemappt); PostgreSQL auf `5432` | + +--- + +## Voraussetzungen & Installation + +### Voraussetzungen + +- **Docker & Docker Compose** (empfohlen, enthΓ€lt PostgreSQL, `ffmpeg` und `chromaprint`), **oder** +- **Node.js** (18/22+), **PostgreSQL** und **`ffmpeg`** im `PATH` fΓΌr den lokalen Start + +### Lokale Installation + +1. Repository klonen: + ```bash + git clone https://git.orfel.de/Jannik/KeySelector.git + cd KeySelector + ``` +2. `.env.example` nach `.env` (bzw. `server/.env`) kopieren und Datenbank- sowie API-Daten eintragen: + ```bash + cp .env.example server/.env + ``` +3. AbhΓ€ngigkeiten im Server-Ordner installieren und starten: + ```bash + cd server + npm install + npm start + ``` +4. Anwendung im Browser unter `http://localhost:3000` ΓΆffnen. + +### Docker & Produktions-Setup + +App und PostgreSQL gemeinsam mit Docker Compose starten: + +```bash +docker compose up -d --build +``` + +Die WeboberflΓ€che ist danach unter `http://localhost:3030` erreichbar (Container-Port `3000`). + +In der **Jannik-Cloud** lΓ€uft KeySelector als integrierter Service unter `keyselector.orfel.de` (konfiguriert im Infrastruktur-Repository unter `services/keyselector`). + +--- + +## Konfiguration + +Umgebungsvariablen aus `.env.example`, `docker-compose.yml` und `server/`: + +| Variable | Standardwert | Beschreibung | +|---|---|---| +| `PORT` | `3000` | Port, auf dem Express lokal / im Container lauscht | +| `DATABASE_URL` | β€” | Optionaler PostgreSQL-Connection-String (ΓΌberschreibt `DB_*`) | +| `DB_HOST` | `localhost` (`postgres` in Compose) | PostgreSQL-Host | +| `DB_PORT` | `5432` | PostgreSQL-Port | +| `DB_USER` | `postgres` | PostgreSQL-Benutzername | +| `DB_PASSWORD` | `postgres` | PostgreSQL-Passwort | +| `DB_NAME` | `keyselector` | PostgreSQL-Datenbankname | +| `ACRCLOUD_HOST` | `identify-eu-west-1.acrcloud.com` | ACRCloud-Erkennungs-Host | +| `ACRCLOUD_ACCESS_KEY` | β€” | ACRCloud Access Key | +| `ACRCLOUD_ACCESS_SECRET` | β€” | ACRCloud Access Secret | +| `ACRCLOUD_CONSOLE_TOKEN` | β€” | Optionaler ACRCloud-Console-Token in `.env.example` | +| `AUDD_API_TOKEN` | β€” | AudD API-Token (`AUDD_API_KEY` wird ebenfalls unterstΓΌtzt) | +| `GETSONGBPM_API_KEY` | β€” | Optionaler GetSongBPM API-Key fΓΌr Key-/BPM-Abfragen | +| `LASTFM_API_KEY` | β€” | Optionaler Last.fm API-Key fΓΌr Genre-Tags | +| `MINIMAX_API_KEY` | β€” | Optionaler MiniMax-Key aus `.env.example` / `docker-compose.yml` | +| `NTFY_URL` | β€” | Optionaler ntfy-Endpunkt fΓΌr `server/workers/poll-quota.js` | + +### Volumes + +- `pgdata:/var/lib/postgresql/data` (in `docker-compose.yml`) speichert den PostgreSQL-Track-Katalog und manuelle Korrekturen dauerhaft. + +--- + +## Nutzung + +### Ablauf in der WeboberflΓ€che + +1. **Audio-Erkennung:** WΓ€hle oben links eine Audioquelle (**PC / System-Audio**, **Mikrofon** oder **Spezifisches EingabegerΓ€t**) und klicke auf das Mikrofon-Badge (`Bereit`), um die Erkennung zu starten oder zu pausieren. Hinweis: Bei System-Audio im Browser-Dialog unbedingt **β€žAudio teilenβ€œ** aktivieren. +2. **Manuelle Suche:** Gib Artist oder Songtitel in die Suchleiste ein, um gleichzeitig in der lokalen PostgreSQL-Datenbank und bei Deezer zu suchen. +3. **Details & Vorschau:** Klicke auf das Cover zum Vergrâßern, auf das Play-Symbol fΓΌr eine 30s-HΓΆrprobe oder auf das Camelot Wheel rechts unten fΓΌr die Vollansicht. +4. **Key / BPM korrigieren:** Klicke auf die **Key**- oder **BPM**-Statistik-Box, um korrigierte Werte dauerhaft in PostgreSQL zu speichern. +5. **Folge-Tracks filtern:** Nutze ΓΌber den VorschlΓ€gen die Filter-Pills fΓΌr **Mix** (`Alle`, `Exakt`, `Quinte (Β±1)`, `Relativ (A↔B)`, `Energy (+2)`) und **Pitch** (`Β±4% (DJ)`, `Β±8%`, `Alle BPM`). + +### API-Endpunkte + +| Methode & Pfad | Beschreibung | +|---|---| +| `POST /api/recognize` | Nimmt `multipart/form-data` (`audio`) entgegen, erkennt per ACRCloud/AudD und reichert aus DB an | +| `GET /api/metadata?track=...&artist=...` | Ermittelt Camelot-Key, BPM, Cover, Preview-URL, Tags & Audio-Attribute | +| `GET /api/suggestions?key=4B&bpm=120&artist=...&title=...` | Liefert harmonisch passende Tracks sortiert nach KompatibilitΓ€tsstufe | +| `GET /api/search?q=...` | Durchsucht lokale PostgreSQL-DB + Deezer API | +| `POST /api/tracks/correct` | Speichert manuelle `artist`, `title`, `camelotKey`, `bpm`-Korrekturen (`is_corrected = TRUE`) | +| `GET /api/cover?q=...` | Proxy fΓΌr die iTunes Search API (`300x300` Album-Cover) | + +--- + +## Projektstruktur + +```text +KeySelector/ +β”œβ”€β”€ db/ +β”‚ β”œβ”€β”€ schema.sql # PostgreSQL-Schema + kuratierte 24-Key-Seed-Tracks +β”‚ β”œβ”€β”€ seed-acousticbrainz.sh # Mock-Skript fΓΌr AcousticBrainz-Seed +β”‚ └── spotify_songs.csv # 26.000+ Track-Katalog (Auto-Import beim Start) +β”œβ”€β”€ docs/ +β”‚ β”œβ”€β”€ Camelot-Wheel-Chart.png +β”‚ β”œβ”€β”€ Camelot-Wheel-Mixed-In-Key-Harmonic-Mixing.png +β”‚ └── KeySelector_SPEC.md # UrsprΓΌngliche Spezifikation +β”œβ”€β”€ public/ +β”‚ β”œβ”€β”€ app.js # Audio-Capture, UI-Logik & API-Steuerung +β”‚ β”œβ”€β”€ cover.js # Cover-Loader & Zoom-Toggle +β”‚ β”œβ”€β”€ favicon.png +β”‚ β”œβ”€β”€ index.html # Single-Page-Frontend +β”‚ β”œβ”€β”€ search.js # Live-Suchfeld & Deezer-Integration +β”‚ β”œβ”€β”€ styles.css # Dark/Light-Theme-Styling +β”‚ └── wheel.js # Interaktives 24-Segment-SVG-Camelot-Wheel +β”œβ”€β”€ server/ +β”‚ β”œβ”€β”€ routes/ +β”‚ β”‚ β”œβ”€β”€ cover.js # iTunes-Cover-Proxy +β”‚ β”‚ β”œβ”€β”€ metadata.js # Multi-Source-Metadaten + ffmpeg-Audioanalyse +β”‚ β”‚ β”œβ”€β”€ recognize.js # ACRCloud- & AudD-Audio-Erkennung +β”‚ β”‚ β”œβ”€β”€ search.js # Hybride Suche (PostgreSQL + Deezer) +β”‚ β”‚ β”œβ”€β”€ suggestions.js # Camelot-Harmonie-Matching-Engine +β”‚ β”‚ └── tracks.js # Endpunkt fΓΌr Key-/BPM-Korrekturen +β”‚ β”œβ”€β”€ workers/ +β”‚ β”‚ └── poll-quota.js # TΓ€glicher Quota-Check-Stub (ntfy) +β”‚ β”œβ”€β”€ db.js # PostgreSQL-Pool, Schema-Init & In-Memory-Fallback +β”‚ β”œβ”€β”€ importer.js # CSV-Katalog-Importer +β”‚ β”œβ”€β”€ index.js # Express-Einstiegspunkt +β”‚ └── package.json +β”œβ”€β”€ shared/ +β”‚ β”œβ”€β”€ camelot-angle.js # Camelot-Code β†’ SVG-Winkel +β”‚ β”œβ”€β”€ camelot-to-musickey.js # Camelot-Code β†’ Standard-Tonart +β”‚ β”œβ”€β”€ color-matrix.js # Camelot-Farbpalette +β”‚ └── mixing-rules.js # Mixed-In-Key-Regeln & KompatibilitΓ€tslabels +β”œβ”€β”€ .env.example +β”œβ”€β”€ docker-compose.yml +β”œβ”€β”€ Dockerfile +β”œβ”€β”€ LIESMICH.md +└── README.md +``` + +--- + +## Lizenz + +Privates / Internes Projekt. diff --git a/README.md b/README.md index a1b6b94..a381647 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,206 @@ -# KeySelector +

+ KeySelector Logo +

-KeySelector ist ein browserbasiertes DJ-Tool, das dir dabei hilft, harmonisch passende Tracks fΓΌr dein nΓ€chstes Set zu finden. Es nutzt Audio-Fingerprinting (ΓΌber das Mikrofon), um laufende Songs zu erkennen, analysiert deren BPM sowie die musikalische Tonart (ausgedrΓΌckt als Camelot-Code) und schlΓ€gt darauf basierend harmonisch kompatible Nachfolgetracks vor. +

KeySelector

+

A browser-based harmonic DJ assistant with live audio recognition, interactive Camelot Wheel, and PostgreSQL track catalog.

-## 🌟 Features +

+ πŸ‡¬πŸ‡§ English Β· πŸ‡©πŸ‡ͺ Deutsch +

-- **🎀 Live Audio Recognition**: Erkennt den aktuell laufenden Track in der Umgebung (via AcoustID / Mock). -- **πŸŽ›οΈ Harmonic Mixing Suggestions**: Nutzt die "Mixed In Key"-Regeln, um perfekte ÜbergΓ€nge (Perfect, Quinte, Energy, Scale etc.) vorzuschlagen. -- **🎑 Interaktives Camelot Wheel**: Visualisiert die aktuelle Tonart und hebt kompatible Tonarten direkt im Wheel hervor. -- **πŸ” Manueller Fallback**: Song nicht erkannt? Die manuelle Suche findet Tracks ΓΌber Metadaten. -- **πŸŒ“ Dark/Light Mode**: Nahtloser Wechsel zwischen verschiedenen Farbschemata. +--- -## πŸ—οΈ Architektur +## Overview -Das Projekt ist bewusst leichtgewichtig aufgebaut und auf Dauerbetrieb in der Cloud ausgelegt: -- **Frontend (`public/`)**: Pures Vanilla JS, HTML und CSS. Kein Build-Schritt, schnelle Ladezeiten. -- **Backend (`server/`)**: Node.js mit Express. Handhabt das Audio-Fingerprinting, ruft Metadaten ab (GetSongBPM, Last.fm) und liefert Cover via iTunes-API (umgeht Frontend-CORS). -- **Shared (`shared/`)**: Geteilte Logik fΓΌr Camelot-Geometrie und Harmonie-Regeln. -- **Datenbank (`db/`)**: PostgreSQL (via Jannik-Cloud bereitgestellt) fΓΌr einen massiven Seed aus AcousticBrainz-Daten. +**KeySelector** is a lightweight, local-first web application designed for DJs to identify currently playing tracks, inspect their musical key (in **Camelot** and standard musical notation) and **BPM**, and immediately discover harmonically and rhythmically compatible follow-up tracks. -## πŸš€ Installation & Setup (Lokale Entwicklung) +```text +β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” HTTP / REST β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” +β”‚ Browser (Vanilla JS SPA) β”‚ ◄───────────────────► β”‚ Node.js / Express (:3000) β”‚ +β”‚ β€’ System / Mic Capture β”‚ β”‚ β€’ /api/recognize (ACR/AudD) β”‚ +β”‚ β€’ Interactive SVG Wheel β”‚ β”‚ β€’ /api/metadata (ffmpeg) β”‚ +β”‚ β€’ Live Search & Filters β”‚ β”‚ β€’ /api/suggestions β”‚ +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β€’ /api/search, /cover β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + β”‚ pg Pool + β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” + β”‚ PostgreSQL (26,000+ tracks) β”‚ + β”‚ + In-Memory Fallback β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +``` -Voraussetzungen: [Node.js](https://nodejs.org/) +--- -1. **Repository klonen** +## Features + +- **Live Audio Recognition (`POST /api/recognize`):** Captures **PC / System Audio** (via `getDisplayMedia` for VLC, DJ software, browser tabs, YouTube), **Room Microphone**, or a **specific audio input device**, includes a live input level meter, and identifies songs via **ACRCloud** or **AudD**. +- **Multi-Source Metadata & Audio Analysis (`GET /api/metadata`):** Resolves key, BPM, genre tags, duration, cover art, and 30-second audio previews using PostgreSQL lookup (exact + fuzzy matching), **Deezer API**, **SongBPM**, **GetSongBPM**, **Last.fm**, and built-in **FFmpeg** preview audio analysis (BPM onset autocorrelation + Goertzel chroma key detection). +- **Harmonic Mixing Suggestions (`GET /api/suggestions`):** Applies Mixed In Key / Camelot compatibility rules (`Perfect`, `Quinte -1`, `Quinte +1`, `Energy`, `Scale`, `Diagonal`, `Jaw's`, `Mood`) with progressive BPM tolerance widening (`Β±6%`, `Β±12%`, `Β±20%`, up to `50–220 BPM`) and UI filters for Mix Type and Pitch Tolerance (`Β±4% (DJ)`, `Β±8%`, `All BPM`). +- **Interactive Camelot Wheel (`public/wheel.js`):** Renders a 24-segment SVG Camelot Wheel (outer `B` Major ring, inner `A` Minor ring) that highlights compatible keys and expands inline on click. +- **Live Hybrid Search (`GET /api/search`):** Searches local PostgreSQL tracks first and merges live results from the **Deezer Search API** with 30-second audio previews and quick links to Spotify, Deezer, and YouTube. +- **Persistent Key & BPM Corrections (`POST /api/tracks/correct`):** Click on the Key or BPM stat card to correct values in a modal; corrections are saved with `is_corrected = TRUE` in PostgreSQL and take precedence in future lookups. +- **Audio Attributes & Cover Zoom:** Displays Tunebat-style attributes (Duration, Energy, Danceability, Mood) and supports inline cover expansion and 30-second preview playback. +- **Dark / Light Theme:** Instant theme switching via CSS custom properties. +- **26,000+ Track Catalog Seed:** Automatically seeds curated Camelot reference tracks (`db/schema.sql`) and imports `db/spotify_songs.csv` (`server/importer.js`) on startup when the database has fewer than 5,000 tracks. + +--- + +## How It Works & Tech Stack + +The frontend (`public/`) requires **no build step** and is served statically alongside `/shared` modules by Express (`server/index.js`). Shared JavaScript files in `shared/` work identically in both Node.js (`require`) and the browser (`window.*`) to guarantee consistent Camelot geometry, colors, and mixing rules. If PostgreSQL is unavailable at startup, `server/db.js` automatically falls back to an in-memory `Map`. + +| Component | Technology / Details | +|---|---| +| Frontend | Vanilla HTML5, CSS3 (Custom Properties), JavaScript (`public/`) | +| Backend | Node.js 22 (`node:22-alpine` in Docker), Express `^4.18.2`, Multer `^2.2.0`, Axios `^1.19.0` | +| Audio Processing | `ffmpeg` & `chromaprint` (installed in Docker image), custom PCM BPM & key analyzer | +| Database | PostgreSQL (`postgres:15-alpine`, `pg` `^8.23.0`) with in-memory fallback | +| External APIs | ACRCloud, AudD, Deezer, SongBPM, GetSongBPM, Last.fm, iTunes Search API | +| Ports | Backend listens on `3000` (mapped to `3030:3000` in `docker-compose.yml`); PostgreSQL on `5432` | + +--- + +## Prerequisites & Installation + +### Prerequisites + +- **Docker & Docker Compose** (recommended, includes PostgreSQL, `ffmpeg`, and `chromaprint`), **or** +- **Node.js** (18/22+), **PostgreSQL**, and **`ffmpeg`** in `PATH` for local execution + +### Local Installation + +1. Clone the repository: ```bash git clone https://git.orfel.de/Jannik/KeySelector.git cd KeySelector ``` - -2. **Backend starten (Node.js)** +2. Copy `.env.example` to `.env` (or `server/.env`) and configure your database and API keys: + ```bash + cp .env.example server/.env + ``` +3. Install backend dependencies and start the server: ```bash cd server npm install - - # Umgebungsvariablen (wie API Keys) exportieren oder in eine .env Datei in server/ schreiben npm start ``` - Die App ist danach unter `http://localhost:3000` erreichbar. +4. Open `http://localhost:3000` in your browser. -## ☁️ Deployment (Jannik-Cloud) +### Docker & Production Setup -KeySelector ist als nativer Service in die **Jannik-Cloud** integriert. -Die Deployment-Files (wie z.B. das Caddy-Routing und das Produktions-`docker-compose.yml`) befinden sich im zentralen Cloud-Infrastruktur-Repository unter `services/keyselector`. +Start both the KeySelector app and PostgreSQL database via Docker Compose: -Sobald Code auf den `main`-Branch dieses Repos gepusht wird, kann der Service in der Jannik-Cloud hochgezogen werden. Er zieht sich automatisch den neuesten Code, baut den Container und geht online unter `keyselector.orfel.de`. +```bash +docker compose up -d --build +``` -## πŸ“š Dokumentation +The web UI will be available at `http://localhost:3030` (container port `3000`). -Weitere technische Details und Spezifikationen (sowie die initiale Konzept-Idee) findest du im `docs/` Ordner: -- `docs/KeySelector_SPEC.md` -- `docs/Camelot-Wheel-Chart.png` +In **Jannik-Cloud**, KeySelector runs as an integrated service under `keyselector.orfel.de` (configured in the central infrastructure repo under `services/keyselector`). + +--- + +## Configuration + +Environment variables defined in `.env.example`, `docker-compose.yml`, and `server/`: + +| Variable | Default | Description | +|---|---|---| +| `PORT` | `3000` | Port Express listens on inside the container / locally | +| `DATABASE_URL` | β€” | Optional full PostgreSQL connection string (overrides `DB_*` vars) | +| `DB_HOST` | `localhost` (`postgres` in Compose) | PostgreSQL host | +| `DB_PORT` | `5432` | PostgreSQL port | +| `DB_USER` | `postgres` | PostgreSQL user | +| `DB_PASSWORD` | `postgres` | PostgreSQL password | +| `DB_NAME` | `keyselector` | PostgreSQL database name | +| `ACRCLOUD_HOST` | `identify-eu-west-1.acrcloud.com` | ACRCloud identification host | +| `ACRCLOUD_ACCESS_KEY` | β€” | ACRCloud project access key | +| `ACRCLOUD_ACCESS_SECRET` | β€” | ACRCloud project access secret | +| `ACRCLOUD_CONSOLE_TOKEN` | β€” | Optional ACRCloud console token in `.env.example` | +| `AUDD_API_TOKEN` | β€” | AudD API token (`AUDD_API_KEY` also accepted as fallback) | +| `GETSONGBPM_API_KEY` | β€” | Optional GetSongBPM API key for key/BPM lookups | +| `LASTFM_API_KEY` | β€” | Optional Last.fm API key for genre tag enrichment | +| `MINIMAX_API_KEY` | β€” | Optional MiniMax key listed in `.env.example` / `docker-compose.yml` | +| `NTFY_URL` | β€” | Optional ntfy endpoint used by `server/workers/poll-quota.js` | + +### Volumes + +- `pgdata:/var/lib/postgresql/data` (in `docker-compose.yml`) persists the PostgreSQL track catalog and user corrections. + +--- + +## Usage + +### Web UI Workflow + +1. **Audio Recognition:** Select an audio source in the top bar (**System Audio**, **Microphone**, or **Specific Device**) and click the microphone status badge (`Bereit`) to start or pause listening. Note: For System Audio, check **"Share audio"** in the browser's screen/tab picker. +2. **Manual Search:** Type an artist or track title in the search bar to query the local catalog and Deezer simultaneously. +3. **Inspect & Play:** Click the album cover to zoom in, click the play icon on the cover for a 30-second audio preview, or click the Camelot Wheel in the bottom-right of the hero card to expand it full-size. +4. **Correct Key / BPM:** Click the **Key** or **BPM** stat box to open the correction modal and save verified values to PostgreSQL. +5. **Filter Follow-Up Tracks:** Use the **Mix** pills (`Alle`, `Exakt`, `Quinte (Β±1)`, `Relativ (A↔B)`, `Energy (+2)`) and **Pitch** pills (`Β±4% (DJ)`, `Β±8%`, `Alle BPM`) above the suggestions grid. + +### API Endpoints + +| Method & Path | Description | +|---|---| +| `POST /api/recognize` | Accepts `multipart/form-data` (`audio` file), identifies via ACRCloud/AudD, enriches from DB | +| `GET /api/metadata?track=...&artist=...` | Resolves Camelot key, BPM, cover, preview URL, tags & audio features | +| `GET /api/suggestions?key=4B&bpm=120&artist=...&title=...` | Returns harmonically compatible tracks sorted by compatibility level | +| `GET /api/search?q=...` | Searches local PostgreSQL + Deezer API | +| `POST /api/tracks/correct` | Saves manual `artist`, `title`, `camelotKey`, `bpm` corrections (`is_corrected = TRUE`) | +| `GET /api/cover?q=...` | Proxies iTunes Search API for `300x300` album artwork | + +--- + +## Project Structure + +```text +KeySelector/ +β”œβ”€β”€ db/ +β”‚ β”œβ”€β”€ schema.sql # PostgreSQL schema + 24-key curated seed tracks +β”‚ β”œβ”€β”€ seed-acousticbrainz.sh # Placeholder/mock AcousticBrainz seed script +β”‚ └── spotify_songs.csv # 26,000+ track catalog auto-imported on init +β”œβ”€β”€ docs/ +β”‚ β”œβ”€β”€ Camelot-Wheel-Chart.png +β”‚ β”œβ”€β”€ Camelot-Wheel-Mixed-In-Key-Harmonic-Mixing.png +β”‚ └── KeySelector_SPEC.md # Original design specification +β”œβ”€β”€ public/ +β”‚ β”œβ”€β”€ app.js # Audio capture, UI state & API orchestration +β”‚ β”œβ”€β”€ cover.js # Album cover loading & zoom toggle +β”‚ β”œβ”€β”€ favicon.png +β”‚ β”œβ”€β”€ index.html # Single-page frontend +β”‚ β”œβ”€β”€ search.js # Live search dropdown & Deezer integration +β”‚ β”œβ”€β”€ styles.css # Dark/Light theme styling +β”‚ └── wheel.js # Interactive 24-segment SVG Camelot Wheel +β”œβ”€β”€ server/ +β”‚ β”œβ”€β”€ routes/ +β”‚ β”‚ β”œβ”€β”€ cover.js # iTunes cover proxy +β”‚ β”‚ β”œβ”€β”€ metadata.js # Multi-source metadata + ffmpeg audio analyzer +β”‚ β”‚ β”œβ”€β”€ recognize.js # ACRCloud & AudD audio recognition +β”‚ β”‚ β”œβ”€β”€ search.js # Local DB + Deezer hybrid search +β”‚ β”‚ β”œβ”€β”€ suggestions.js # Camelot harmonic matching engine +β”‚ β”‚ └── tracks.js # User key/BPM correction endpoint +β”‚ β”œβ”€β”€ workers/ +β”‚ β”‚ └── poll-quota.js # Daily quota check stub (ntfy) +β”‚ β”œβ”€β”€ db.js # PostgreSQL pool, schema init & in-memory fallback +β”‚ β”œβ”€β”€ importer.js # Bulk CSV catalog importer +β”‚ β”œβ”€β”€ index.js # Express app entrypoint +β”‚ └── package.json +β”œβ”€β”€ shared/ +β”‚ β”œβ”€β”€ camelot-angle.js # Camelot code to SVG angle mapping +β”‚ β”œβ”€β”€ camelot-to-musickey.js # Camelot to standard musical key mapping +β”‚ β”œβ”€β”€ color-matrix.js # Camelot color palette +β”‚ └── mixing-rules.js # Mixed In Key compatibility rules & labels +β”œβ”€β”€ .env.example +β”œβ”€β”€ docker-compose.yml +β”œβ”€β”€ Dockerfile +β”œβ”€β”€ LIESMICH.md +└── README.md +``` + +--- + +## License + +Private / Internal Project.