version: '3.9'

services:
  postgres:
    image: postgres:17.2
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${DB_NAME:-code_journey}
      POSTGRES_USER: ${DB_USER:-postgres}
      POSTGRES_PASSWORD: ${DB_PASS:-postgres}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - app_net

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    restart: unless-stopped
    depends_on:
      - postgres
    environment:
      DB_URL: jdbc:postgresql://${DB_HOST:-postgres}:${DB_PORT:-5432}/${DB_NAME:-code_journey}
      DB_USER: ${DB_USER:-postgres}
      DB_PASS: ${DB_PASS:-postgres}
    ports:
      - "8080:8888"
    networks:
      - app_net

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    restart: unless-stopped
    depends_on:
      - backend
    environment:
      NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-http://backend:8888}
      NODE_ENV: production
    ports:
      - "3000:3000"
    networks:
      - app_net

volumes:
  postgres_data:

networks:
  app_net:
    driver: bridge
