How danztee/shazam-build works
1. Top-level shape
This repo is a two-part system: a Go backend that performs audio ingestion, fingerprinting, and matching; and a React frontend that records microphone audio and displays match results. The backend owns all recognition logic and persistence. The frontend is just a thin capture/display client.
2. Backend entrypoints
The Go service starts from cmd/main.go and cmd/api.go. These files are the composition root for the API server: they load configuration, wire services, connect to PostgreSQL, and register HTTP routes. The presence of chi in the README suggests the backend is organized as a small REST API rather than a large framework app.
3. Core recognition pipeline
internal/audio is the heart of the system. It contains the DSP stages needed to recreate Shazam-style fingerprints:
- WAV decoding / normalization
- FFT-based spectrogram generation
- peak detection in the spectrogram
- combinatorial fingerprint generation
This subsystem is pure processing logic and is the main computational boundary in the repo.
4. Ingestion flow
Song ingestion starts in internal/songs/handler.go, flows through internal/songs/service.go, and then fans out to Spotify and download/audio processing. The API accepts a Spotify URL, fetches metadata through internal/spotify, downloads or normalizes the source audio through internal/download, then runs it through internal/audio to extract fingerprints before storing everything in PostgreSQL.
5. Matching flow
Recognition likely uses the same audio pipeline in reverse: recorded audio is submitted from the frontend to the backend, converted into fingerprints, and compared against stored fingerprints in the database. Matching then uses time-offset coherency / diagonal alignment logic to score candidate songs. The match result is returned to the frontend as a selected song or “no match.”
6. Persistence layer
internal/database contains the database boundary. The generated SQLC code in internal/database/queries shows that persistence is strongly typed and query-driven rather than ORM-based. The schema is managed by Goose migrations under migrations/, with a songs table for metadata and a fingerprints table for the high-cardinality hash index that powers matching.
7. External integrations
The only external service explicitly integrated is Spotify. internal/spotify handles talking to Spotify APIs for metadata and source lookup during song ingestion. FFmpeg is another important external dependency, but it acts as a local processing tool for audio normalization rather than a remote service.
8. API surface
internal/songs/handler.go and internal/spotify/handler.go indicate the backend exposes resource-oriented HTTP endpoints. The README documents at least POST /api/v1/songs for ingestion. The API is therefore split by domain: song management/matching, and Spotify-related ingestion support.
9. Frontend architecture
The frontend/ app is a Vite + React + TypeScript client. Its main functional pieces are:
- AudioRecorder.tsx for browser microphone capture via the MediaRecorder API
- MatchResult.tsx for rendering recognition output
- App.tsx as the UI coordinator
The frontend does not implement recognition itself; it packages audio and sends it to the backend.
10. Deployment and local infrastructure
docker-compose.yml, .air.toml, and the Makefile indicate a developer workflow built around local services and hot reloading. PostgreSQL is expected to run in Docker, while the Go backend likely uses Air for live reload. The frontend is a separate Node/pnpm project with its own build pipeline, so the system is split into independently runnable services.
11. Data boundaries
The main data boundary is between raw audio and fingerprints. Audio enters as either Spotify-sourced tracks during ingestion or microphone recordings during recognition. Everything downstream of that boundary is represented as spectrogram peaks, hashes, and time offsets, which are the values persisted and queried for matching.
12. What to draw in an architecture diagram
The cleanest diagram is:
frontend microphone capture → HTTP request to Go API → audio normalization / FFT / peak / fingerprint pipeline → PostgreSQL fingerprint lookup → match scoring → JSON response back to frontend.
In parallel, a song-ingestion path should show: Spotify URL → Spotify API/download → audio pipeline → database insert of song metadata plus fingerprints.
Main entry points: songs/service.go Songs service · audio/service.go Audio pipeline · handler.go Songs API · api.go API setup
Components 17
Backend
Go API, ingestion, recognition, and integration logic
- Main · Bootstraps the service process
cmd/main.go - API setup · Loads config, wiring, and HTTP routes
cmd/api.go - Songs API · Song ingestion and recognition endpoints
internal/songs/handler.go - Songs service · Coordinates ingestion, matching, and persistence
internal/songs/service.go - Spotify API · Support endpoints for Spotify-backed ingestion
internal/spotify/handler.go - Spotify service · Fetches Spotify metadata and source info
internal/spotify/service.go - Downloader · Retrieves and prepares source audio for processing
internal/download/service.go - WAV decode · Loads and normalizes audio samples
internal/audio/wav.go - Spectrogram · Builds frequency-time representations
internal/audio/spectrogram.go - Peak detect · Finds salient spectral peaks
internal/audio/peaks.go - Fingerprints · Generates combinatorial audio hashes
internal/audio/fingerprint.go - Audio pipeline · Coordinates the full fingerprinting flow
internal/audio/service.go
Frontend
React client for recording and displaying matches
- App · Coordinates recording and results UI
frontend/src/App.tsx - Recorder · Captures microphone audio in the browser
frontend/src/components/AudioRecorder.tsx - Result view · Renders recognition outcomes
frontend/src/components/MatchResult.tsx
Persistence
Database schema and query layer
- SQLC queries · Typed persistence for songs and fingerprints
internal/database/queries/db.go - Schema · Creates songs and fingerprint tables
migrations/20251221032923_create_schema.sql
Connections 18
- Main → API setup: starts · Process entry delegates to API wiring
- API setup → Songs API: registers · Binds song routes and handlers
- API setup → Spotify API: registers · Binds Spotify support routes
- Songs API → Songs service: calls · HTTP requests are handled by domain logic
- Songs service → Spotify service: uses · Looks up Spotify metadata during ingestion
- Songs service → Downloader: uses · Fetches or prepares source audio
- Songs service → Audio pipeline: uses · Extracts fingerprints from audio
- Songs service → SQLC queries: stores/reads · Persists songs and fingerprint rows
- Spotify API → Spotify service: calls · HTTP support endpoints delegate to integration logic
- Audio pipeline → WAV decode: decodes · Begins with waveform normalization
- Audio pipeline → Spectrogram: builds · Transforms samples into spectrograms
- Audio pipeline → Peak detect: detects · Finds spectral peaks
- Audio pipeline → Fingerprints: hashes · Produces matchable fingerprints
- SQLC queries → Schema: depends on · Queries operate over the migrated schema
- App → Recorder: composes · App hosts capture UI
- App → Result view: composes · App renders match output
- Recorder → Songs API: POST audio · Recorded audio is sent to the backend API
- Songs API → Result view: returns · Match response is surfaced to the UI