# Frontend Development - Backend built from local source
#
# Usage:
#   1. docker compose -f docker-compose.dev.yml up -d
#   2. cd web && bun install && bun run dev
#   3. Open http://localhost:3001 (Rsbuild dev server, API auto-proxied to :3000)
#
# Rebuild backend after Go code changes:
#   docker compose -f docker-compose.dev.yml up -d --build new-api
#
# Stop:
#   docker compose -f docker-compose.dev.yml down
#
# Reset data:
#   docker compose -f docker-compose.dev.yml down -v

services:
  new-api:
    build:
      context: .
      dockerfile: Dockerfile.dev
    image: new-api-dev:local
    container_name: new-api-dev
    restart: unless-stopped
    ports:
      - "3000:3000"
    volumes:
      - dev_data:/data
    environment:
      - SQL_DSN=postgresql://root:123456@postgres:5432/new-api
      - REDIS_CONN_STRING=redis://redis
      - TZ=Asia/Shanghai
      - BATCH_UPDATE_ENABLED=true
    depends_on:
      redis:
        condition: service_started
      postgres:
        condition: service_healthy
    networks:
      - dev-network

  redis:
    image: redis:7-alpine
    container_name: new-api-dev-redis
    restart: unless-stopped
    networks:
      - dev-network

  postgres:
    image: postgres:15-alpine
    container_name: new-api-dev-pg
    restart: unless-stopped
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: 123456
      POSTGRES_DB: new-api
    volumes:
      - dev_pg_data:/var/lib/postgresql/data
    networks:
      - dev-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U root -d new-api"]
      interval: 5s
      timeout: 3s
      retries: 5

volumes:
  dev_data:
  dev_pg_data:

networks:
  dev-network:
    driver: bridge
