version: '3.8'

services:
  postgres:
    image: postgres:15
    container_name: live_casino_postgres
    environment:
      POSTGRES_DB: live_casino
      POSTGRES_USER: casino_user
      POSTGRES_PASSWORD: casino_pass
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./scripts/init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - casino_network

  redis:
    image: redis:7-alpine
    container_name: live_casino_redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - casino_network

  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: live_casino_pgadmin
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: admin
    ports:
      - "5050:80"
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    networks:
      - casino_network
    depends_on:
      - postgres

  redis-commander:
    image: rediscommander/redis-commander:latest
    container_name: live_casino_redis_commander
    environment:
      REDIS_HOSTS: local:redis:6379
    ports:
      - "8081:8081"
    networks:
      - casino_network
    depends_on:
      - redis

  backend:
    build:
      context: ./apps/backend
    container_name: live_casino_backend
    env_file:
      - .env
    environment:
      - DATABASE_URL=postgresql://casino_user:casino_pass@postgres:5432/live_casino
      - REDIS_URL=redis://redis:6379
    depends_on:
      - postgres
      - redis
    command: sh -c "npx prisma migrate deploy && node dist/src/main.js"
    ports:
      - "4000:4000"
    networks:
      - casino_network

  frontend:
    build:
      context: ./apps/frontend
    container_name: live_casino_frontend
    env_file:
      - .env
    depends_on:
      - backend
    ports:
      - "3000:4000"
    networks:
      - casino_network

volumes:
  postgres_data:
  redis_data:
  pgadmin_data:

networks:
  casino_network:
    driver: bridge 