How miguelkolli/helsinki-music works
1. Overall shape
- The main application is a single-process Node.js server started from server/index.js.
- That process owns the HTTP API, scheduled crawls, normalization, enrichment triggers, and the admin UI.
- A separate workers/ tree can offload queued jobs when REDIS_URL is present; otherwise the app falls back to in-process cron-style execution.
2. Primary request boundary
- The main public surface is the Express API under src/routes/.
- Key route groups are events, feed, places, users, sources, boosts, saves, uploads, auth, analytics, admin, and ai.
- Middleware layers in src/middleware/ enforce auth, rate limits, request validation, SSRF protection, logging, CORS, and error handling before requests reach route handlers.
3. Data ingestion boundary
- Inbound event data comes from source-specific crawlers in src/crawlers/ and a smaller set in src/scrapers/.
- These crawlers talk to external event providers such as LinkedEvents, Ticketmaster, Meteli, Dice, Tiketti, Tavastia, and others.
- The crawler layer is source-specific and intentionally separated from the rest of the domain logic so each source can fail independently.
4. Normalization and quality pipeline
- Raw crawl results are pushed through src/pipeline/normalizer.js and related service modules.
- The pipeline handles event validation, deduplication, slug/fingerprint generation, score calculation, and enrichment preparation.
- This is the main transformation boundary between “scraped raw data” and the canonical event record used by the rest of the system.
5. Persistence model
- Database access is centralized in src/db/ and src/database/.
- The app supports PostgreSQL in production and SQLite as fallback, selected by configuration.
- SQL is organized by domain in src/database/statements/, with a repository layer such as events.repo.js owning batch upserts and bulk operations.
- Schema/migration files exist for both SQLite and Postgres, which means the storage layer is a first-class abstraction rather than a thin ORM wrapper.
6. Search, ranking, and merchandising
- Search and listing behavior lives mostly in src/services/search.js, ranking.js, scoring.js, trending.js, boost.js, and feed.js.
- These services shape the public event list by combining deterministic scores, editorial boosts, trending signals, and filters.
- RSS and iCal feeds are generated from the same canonical event store, so the feed endpoints are downstream consumers of the main event dataset rather than a separate source.
7. Background processing
- workers/ contains optional BullMQ-based workers for enrichment, scoring, trending, and scraping jobs.
- When Redis is unavailable, the same workload is handled by cron/scheduler logic in-process via src/cron/ and workers/scheduler.js.
- This means the system has two execution modes: single-process all-in-one for simplicity, and split worker processes for heavier production deployments.
8. External enrichment services
- The app integrates with services such as Claude/Anthropic for text enrichment and natural-language search, Google Places for place data, Last.fm and image search/fallbacks for artist images, and R2 for object storage.
- Email/Gmail support is also present for auth/token workflows and operational scripts.
- These integrations sit behind service modules in src/services/, which keeps external API volatility away from route handlers and crawlers.
9. Authentication, admin, and operational control
- JWT-based auth is handled by src/routes/auth.js and middleware in src/middleware/auth.js.
- Roles (admin, editor, viewer) gate access to admin functions like crawl triggering, boosts, user management, uploads, and log inspection.
- public/admin.html serves the admin SPA, so operational control is embedded in the same deployment as the public API.
10. Analytics and privacy
- src/analytics/ is a separate subsystem for privacy-safe usage tracking.
- It persists to the database and optionally syncs via Redis.
- The analytics middleware captures request-level signals without leaking raw IPs, using a salt-based hashing approach configured through environment variables.
11. Secondary package boundaries
- The repo also contains an older or parallel API surface under api/, with its own routes, middleware, and helper libs.
- packages/bar/ is a separate package with its own schema, DB pool, routes, and Google Places service, suggesting a bounded sub-service focused on place/venue data.
- For an architecture diagram, treat these as adjacent subsystems or legacy/auxiliary services rather than the main runtime path.
12. Deployment model
- The project is designed for Railway/Node PaaS deployment, with Procfile support and environment-driven behavior.
- Startup behavior is config-heavy: required secrets, optional Postgres/Redis integrations, and feature flags determine whether the app runs in lightweight local mode or full production mode.
- The most important architectural implication is that the same codebase can run as a self-contained monolith or as a monolith plus workers, depending on infrastructure.
Main entry points: services Domain services · index.js Server start · routes API routes · db DB core
Components 20
Main app
Primary monolith runtime under server/ and src/
- Server start · Bootstraps the main HTTP process and runtime mode
server/index.js - Config · Environment-driven feature flags, secrets, and mode selection
src/config/index.js - API routes · Primary public request surface for events, feeds, auth, admin, and AI
src/routes - Middleware · Auth, rate limits, validation, SSRF protection, logging, CORS, and errors
src/middleware - Crawlers · Source-specific event crawlers for external providers
src/crawlers - Scrapers · Additional scraping entrypoints for a smaller set of sources
src/scrapers - Normalizer · Validates, deduplicates, fingerprints, scores, and prepares enrichment
src/pipeline/normalizer.js - Domain services · Search, ranking, scoring, trending, feed, enrichment, and integrations
src/services - Analytics · Request-level usage tracking with DB persistence and optional Redis sync
src/analytics - Admin UI · Embedded admin interface served from the same deployment
public/admin.html - Public app · Public-facing web app bundle and entry page
public/app/index.html - Email · Gmail-based auth and operational email workflows
src/email/gmail.js
Background jobs
Optional BullMQ and cron execution paths
Auxiliary subsystems
Adjacent API and package boundaries
- Legacy API · Older or parallel API surface with its own routes, middleware, and helpers
api/index.js - Bar package · Separate package focused on place and venue data with its own DB and routes
packages/bar/src/index.js
Storage
Database and persistence abstractions
- DB core · Database selection and connection management for SQLite or PostgreSQL
src/db - Event repo · Batch upserts and bulk persistence for canonical events
src/database/repositories/events.repo.js - SQL statements · Domain-organized SQL for events, places, users, saves, boosts, uploads, logs, and visitors
src/database/statements
Connections 27
- Server start → Config: loads · Startup reads configuration to choose runtime mode and integrations
- Server start → Middleware: mounts · HTTP pipeline applies shared middleware before route handlers
- Server start → API routes: serves · Main process exposes the Express API
- Server start → Analytics: tracks · Request middleware emits privacy-safe analytics events
- Server start → Cron: schedules · Fallback in-process scheduling when Redis workers are unavailable
- Server start → Job queue: enqueues · Hands off heavier background work when queue infrastructure is enabled
- API routes → Crawlers: triggers · Admin and operational endpoints can start source crawls
- API routes → Domain services: uses · Route handlers delegate search, feed, boost, and enrichment behavior
- Crawlers → Scrapers: covers · Some ingestion paths are implemented as scraper-style source modules
- Crawlers → Normalizer: emit raw data · Source-specific results flow into normalization
- Scrapers → Normalizer: emit raw data · Scraped payloads are normalized into canonical records
- Normalizer → Domain services: prepares · Normalization produces data consumed by scoring, search, and enrichment
- Normalizer → Event repo: persists · Canonical event records are written through repository upserts
- Domain services → Event repo: reads/writes · Search, ranking, trending, and feed logic consult the repository layer
- Event repo → SQL statements: executes · Repository calls domain-specific SQL statements
- DB core → Event repo: provides · Repository uses the selected database backend
- DB core → Config: selects · Configuration chooses SQLite or PostgreSQL and related connection settings
- Analytics → DB core: stores · Analytics events persist through the same database abstraction
- Workers → Job queue: consumes · Worker processes drain queued enrichment, scoring, trending, and scraping jobs
- Workers → Domain services: executes · Background tasks reuse domain services for enrichment and ranking
- Cron → Domain services: runs · Single-process scheduling invokes the same service logic
- Legacy API → DB core: uses · Adjacent API surface maintains its own request path into storage
- Bar package → DB core: uses · Separate package has its own pool and statements but same architectural role
- Bar package → Domain services: enriches · Place-specific logic relies on Google Places service integration
- API routes → Admin UI: serves · Admin endpoints and UI live in the same deployment
- API routes → Public app: serves · Public web app is shipped alongside the API
- Domain services → Email: integrates · Auth and operational workflows depend on Gmail support