services:
    app:
        build:
            context: .
            dockerfile: Dockerfile
        image: coachingms-app
        container_name: coachingms-app
        restart: unless-stopped
        working_dir: /var/www
        volumes:
            - .:/var/www
            - ./docker-compose/php/local.ini:/usr/local/etc/php/conf.d/local.ini # PHP config if needed
        networks:
            - coachingms-network
        depends_on:
            db:
                condition: service_healthy
        environment:
            SERVICE_NAME: app
            SERVICE_TAGS: dev

    db:
        image: mysql:8.0
        container_name: coachingms-db
        restart: unless-stopped
        environment:
            MYSQL_ROOT_PASSWORD: root
            MYSQL_DATABASE: coachingms
            MYSQL_USER: user
            MYSQL_PASSWORD: pass
        ports:
            - "3306:3306"
        volumes:
            - db-data:/var/lib/mysql
        networks:
            - coachingms-network
        healthcheck:
            test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
            interval: 10s
            retries: 5

    nginx:
        image: nginx:alpine
        container_name: coachingms-nginx
        restart: unless-stopped
        ports:
            - "80:80" # HTTP port
            # - "443:443" # Uncomment this for HTTPS (SSL) support
        volumes:
            - .:/var/www:cached
            - ./docker-compose/nginx:/etc/nginx/conf.d
        depends_on:
            - app
        networks:
            - coachingms-network

    node:
        # Optional platform flag for Mac Silicon (M1/M2/M3)
        platform: linux/amd64
        build:
            context: .
            dockerfile: Dockerfile.node
        image: coachingms-node
        container_name: coachingms-node
        ports:
            - "3000:3000"
            - "3001:3001"
        restart: unless-stopped
        working_dir: /var/www
        volumes:
            - ./:/var/www
            - /var/www/node_modules
        networks:
            - coachingms-network

networks:
    coachingms-network:
        driver: bridge

volumes:
    db-data: