services:
  db:
    image: postgres:16-alpine
    restart: always
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: muzick
    ports:
      - "127.0.0.1:5432:5432"
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
      - ./backend/src/db/schema.sql:/docker-entrypoint-initdb.d/schema.sql

  search:
    image: typesense/typesense:0.25.1
    restart: always
    ports:
      - "127.0.0.1:8108:8108"
    volumes:
      - ./data/typesense:/data
    command: --data-dir /data --api-key=${TYPESENSE_API_KEY}

  backend:
    build: ./backend
    restart: unless-stopped
    ports:
      - "127.0.0.1:3000:3000"
    environment:
      DATABASE_URL: postgresql://user:${DB_PASSWORD}@db:5432/muzick
      REDIS_URL: redis://:${REDIS_PASSWORD}@infra-redis:6379
      TYPESENSE_API_KEY: ${TYPESENSE_API_KEY}
      MUZICK_API_KEY: ${MUZICK_API_KEY}
      MUZICK_ADMIN_KEY: ${MUZICK_ADMIN_KEY}
      MUSIC_DIR: /music
    volumes:
      # READ-ONLY, deliberately. Nothing in the API request path may write to
      # the library. Hard deletion of disliked files happens only in the worker,
      # which is the sole service with an rw mount.
      - /mnt/hdd1/media/Music:/music:ro
    depends_on:
      - db
      - search
    networks:
      - default
      - infra-net

  frontend:
    build: ./frontend
    restart: unless-stopped
    ports:
      - "127.0.0.1:5174:80"
    environment:
      MUZICK_API_KEY: ${MUZICK_API_KEY}
      MUZICK_ADMIN_KEY: ${MUZICK_ADMIN_KEY}
    depends_on:
      - backend

  worker:
    build: ./workers
    restart: unless-stopped
    network_mode: host
    environment:
      DATABASE_URL: postgresql://user:${DB_PASSWORD}@127.0.0.1:5432/muzick
      REDIS_URL: redis://:${REDIS_PASSWORD}@127.0.0.1:6379
      MUSICBRAINZ_CONTACT: ${MUSICBRAINZ_CONTACT}
      LASTFM_API_KEY: ${LASTFM_API_KEY}
      LASTFM_SHARED_SECRET: ${LASTFM_SHARED_SECRET}
      DISCOGS_TOKEN: ${DISCOGS_TOKEN}
      SOCKS_PROXY_URL: ${SOCKS_PROXY_URL}
      MUSIC_DIR: /music
    volumes:
      - /mnt/hdd1/media/Music:/music:ro

networks:
  infra-net:
    external: true
    name: infra-net
