version: "3.8"

services:
  springboot-app:
    build:
      context: ./api
      dockerfile: Dockerfile
    ports:
      - "127.0.0.1:8080:8080" 
    depends_on:
      - postgres-db
    environment:
      - DB_URL=${DB_URL}
      - DB_USERNAME=${DB_USERNAME}
      - DB_PASSWORD=${DB_PASSWORD}
      - SHARED_FOLDER=/shared
      - NEXT_SERVER_URL=${NEXT_SERVER_URL}
    volumes:
      - /root/storage:/shared 
    restart: always
    networks:
      - app-network

  postgres-db:
    image: postgres:15
    container_name: postgres-db
    environment:
      POSTGRES_DB: ${POSTGRES_DB} 
      POSTGRES_USER: ${POSTGRES_USER} 
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    ports:
      - "127.0.0.1:5432:5432" 
    volumes:
      - .postgres-data:/var/lib/postgresql/data
    restart: always
    networks:
      - app-network

  nextjs-app:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    ports:
      - "127.0.0.1:3050:3050"
    working_dir: /app
    command: "npm run start" 
    depends_on:
      - springboot-app 
    environment:
      - NEXT_SERVER_API_URL=${NEXT_SERVER_API_URL}
      - BILLBEE_PASSWORD=${BILLBEE_PASSWORD}
      - BILLBEE_USERNAME=${BILLBEE_USERNAME}
      - BILLBEE_API_KEY=${BILLBEE_API_KEY}
      - SESSION_SECRET=${SESSION_SECRET}
    restart: always
    networks:
      - app-network

volumes:
  postgres-data:

networks:
  app-network:
    driver: bridge
