# Spin up just Postgres for local dev. Run backend & frontend natively
# against it (cargo run / npm run dev) for fast iteration.
services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: mangalord
      POSTGRES_PASSWORD: mangalord
      POSTGRES_DB: mangalord
    ports:
      - "5432:5432"
    volumes:
      - mangalord-postgres-dev:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U mangalord"]
      interval: 5s
      timeout: 5s
      retries: 10

  # Optional: TOR daemon for crawler dev. Ports bind to 127.0.0.1 only
  # — never the LAN — so a native `cargo run` on the host can reach
  # 127.0.0.1:9050 / 9051. Mirrors the prod tor service (see
  # docker-compose.yml), just with host-loopback ports and a default
  # password baked in for friction-free dev.
  tor:
    image: dockurr/tor:latest
    entrypoint: ["/bin/sh", "/usr/local/bin/mangalord-entrypoint.sh"]
    environment:
      PASSWORD: ${TOR_CONTROL_PASSWORD:-dev-tor-password}
    volumes:
      - ./tor/torrc:/etc/tor/torrc:ro
      - ./tor/entrypoint.sh:/usr/local/bin/mangalord-entrypoint.sh:ro
    ports:
      - "127.0.0.1:9050:9050"
      - "127.0.0.1:9051:9051"
    healthcheck:
      test: ["CMD-SHELL", "nc -z 127.0.0.1 9050 && nc -z 127.0.0.1 9051"]
      interval: 5s
      timeout: 5s
      retries: 20
      start_period: 30s

volumes:
  mangalord-postgres-dev:
