# Copy .env.docker.example to .env.docker and adjust (optional).
# Defaults below are for local development only.

services:
  postgres:
    image: postgres:15-alpine
    container_name: dyolink_db_container
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-postgres}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-dyolink_dev_change_me}
      POSTGRES_DB: ${POSTGRES_DB:-dyolink_db}
    ports:
      - "5433:5432"
    volumes:
      - postgres_data_dev:/var/lib/postgresql/data
      - ./database/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
      - ./database/backups:/backups
    networks:
      - dyolink_network
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    build: ../backend
    container_name: dyolink_backend_container
    depends_on:
      postgres:
        condition: service_healthy
    env_file:
      - ../backend/.env
    environment:
      - DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-dyolink_dev_change_me}@postgres:5432/${POSTGRES_DB:-dyolink_db}
      - FRONTEND_URL=http://localhost:4000
      - PORT=3000
    ports:
      - "4001:3000"
    volumes:
      - ../backend:/app:rw
      - /app/node_modules
    networks:
      - dyolink_network
    command: npm run start:dev
    restart: unless-stopped

  frontend:
    build: ../frontend
    container_name: dyolink_frontend_container
    depends_on:
      - backend
    env_file:
      - ../frontend/.env.local
    environment:
      - NEXT_PUBLIC_API_URL=http://localhost:4001/api
      - NEXT_PUBLIC_APP_URL=http://localhost:4000
    ports:
      - "4000:3001"
    volumes:
      - ../frontend:/app:rw
      - /app/node_modules
      - /app/.next
    networks:
      - dyolink_network
    command: npm run dev
    restart: unless-stopped

  nginx:
    build: ./nginx
    container_name: dyolink_nginx_container
    depends_on:
      - backend
      - frontend
    ports:
      - "8080:80"
    volumes:
      - ./nginx/http-only.dev.conf:/etc/nginx/conf.d/default.conf:ro
      - ./logs/nginx:/var/log/nginx
    networks:
      - dyolink_network
    restart: unless-stopped

networks:
  dyolink_network:
    driver: bridge
    name: dyolink_network

volumes:
  postgres_data_dev:
    name: dyolink_postgres_data_dev