services:
  db:
    image: postgres:15
    environment:
      POSTGRES_DB: portas_game
      POSTGRES_USER: portas_user
      POSTGRES_PASSWORD: portas_password
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - "5432:5432"
    restart: always

  backend:
    build:
      context: .
      dockerfile: Dockerfile.backend
    environment:
      DATABASE_URL: postgresql://portas_user:portas_password@db:5432/portas_game
      NODE_ENV: development
    ports:
      - "3000:3000"
    depends_on:
      - db
    volumes:
      - ./backend:/app
      - /app/node_modules
    restart: always

  frontend:
    build:
      context: .
      dockerfile: Dockerfile.frontend
    ports:
      - "8080:80"
    volumes:
      - ./frontend:/usr/share/nginx/html
    restart: always

volumes:
  postgres_data:
