services:
    frontend: # frontend (React) container
        container_name: shipme_frontend
        build:
            context: ./frontend
            dockerfile: Dockerfile
        environment:
            CHOKIDAR_USEPOLLING: "true" # auto-reload container
            VITE_APP_URL: ${VITE_APP_URL}
            VITE_API_URL: ${VITE_API_URL}
            VITE_MSAL_CLIENT_ID: ${VITE_MSAL_CLIENT_ID}
            VITE_MSAL_AUTHORITY_URL: ${VITE_MSAL_AUTHORITY_URL}
        volumes:
            - /app/node_modules
            - ./frontend:/app
        ports:
            - "5173:5173"
        networks:
            - app-network
        depends_on:
            - backend

    backend: # backend (Express) container
        container_name: shipme_backend
        build:
            context: ./backend
            dockerfile: Dockerfile
        environment:
            CHOKIDAR_USEPOLLING: "true" # auto-reload container
            POSTGRES_USER: ${POSTGRES_USER}
            POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
            POSTGRES_DB: ${POSTGRES_DB}
            POSTGRES_HOST: ${POSTGRES_HOST}
            POSTGRES_PORT: ${POSTGRES_PORT}
            VITE_APP_URL: ${VITE_APP_URL}
            AWS_REGION: ${AWS_REGION}
            IAM_USER: ${IAM_USER}
            SMTP_PORT: ${SMTP_PORT}
            SMTP_USER: ${SMTP_USER}
            SMTP_PASSWORD: ${SMTP_PASSWORD}
        volumes:
            - /app/node_modules
            - ./backend:/app
        ports:
            - "3000:3000"
        networks:
            - app-network
        depends_on:
            - db

    db: # database (PostgreSQL) container
        container_name: shipme_database
        build:
            context: ./db
            dockerfile: Dockerfile
        environment: # use .env variables
            POSTGRES_USER: ${POSTGRES_USER}
            POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
            POSTGRES_DB: ${POSTGRES_DB}
        volumes:
            - postgres_data:/var/lib/postgresql/data # persistent data storage
            - ./db:/docker-entrypoint-initdb.d # Mounts init scripts
        ports:
            - "5432:5432"
        networks:
            - app-network
        restart: on-failure:3

networks:
    app-network:
        driver: bridge

volumes:
    postgres_data:
