services:
  # --- FRONTEND (Next.js) ---
  client:
    container_name: resistencia-client
    build:
      context: .
      dockerfile: client/Dockerfile
    ports:
      - "3000:3000"
    volumes:
      - ./client:/app/client
      - ./shared:/app/shared
      - /app/client/node_modules
    environment:
      - NEXT_PUBLIC_API_URL=http://localhost:4000
    depends_on:
      - server
    networks:
      - resistencia-net

  # --- BACKEND (Node/Express + Socket.io) ---
  server:
    container_name: resistencia-server
    build:
      context: .
      dockerfile: server/Dockerfile
    ports:
      - "4000:4000"
    volumes:
      - ./server:/app/server
      - ./shared:/app/shared
      - /app/server/node_modules
    environment:
      - PORT=4000
      - DATABASE_URL=postgresql://postgres:password@db:5432/resistencia
      - CORS_ORIGIN=http://localhost:3000
    depends_on:
      - db
    networks:
      - resistencia-net

  # --- BASE DE DATOS (PostgreSQL) ---
  db:
    container_name: resistencia-db
    image: postgres:15-alpine
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_DB: resistencia
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - resistencia-net

networks:
  resistencia-net:
    driver: bridge

volumes:
  postgres_data:
