services:
    caddy:
        image: caddy:2-alpine
        container_name: caddy
        restart: unless-stopped
        environment:
            - FRONTEND_UPSTREAM=frontend-dev:4321
            - BACKEND_UPSTREAM=backend-dev:8081
        ports:
            - "8080:80"
        volumes:
            - ./Caddyfile:/etc/caddy/Caddyfile
        depends_on:
            - postgres-dev
            - backend-dev
            - frontend-dev

    backend-dev:
        image: boost-ai/demo-backend-dev:${DEV_TAG:?error DEV_TAG environment variable not set}
        container_name: backend-dev
        restart: unless-stopped
        env_file:
            - ./.env.runtime
        volumes:
            - ./Backend:/app
        command: ["air"]
        environment:
            - GO_ENV=development
            - BACKEND_INTERNAL_PORT=8081
            - ALLOWED_ORIGINS=http://localhost:3000,http://localhost:4321,http://localhost:8080,http://windows-wsl:8080
            - DATABASE_URL=postgres://boostai:boostai_dev_password@postgres-dev:5432/boostai?sslmode=disable
            - JWT_SECRET=boostai-dev-jwt-secret-change-me
            - SESSION_COOKIE_NAME=boostai_session
        depends_on:
            postgres-dev:
                condition: service_healthy
        ports:
            - "8081:8081"

    frontend-dev:
        image: boost-ai/demo-frontend-dev:${DEV_TAG:?error DEV_TAG environment variable not set}
        container_name: frontend-dev
        restart: unless-stopped
        volumes:
            - ./Frontend:/app
            - ./Mock-Data:/Mock-Data
            - BoostAI_node_modules:/app/node_modules
        command: ["pnpm", "dev", "--host", "0.0.0.0", "--port", "4321"]
        environment:
            - NODE_ENV=development
            - ALLOWED_HOSTS=windows-wsl

    postgres-dev:
        image: postgres:16-alpine
        container_name: postgres-dev
        restart: unless-stopped
        environment:
            - POSTGRES_DB=boostai
            - POSTGRES_USER=boostai
            - POSTGRES_PASSWORD=boostai_dev_password
        ports:
            - "5439:5432"
        volumes:
            - BoostAI_postgres_data:/var/lib/postgresql/data
        healthcheck:
            test: ["CMD-SHELL", "pg_isready -U boostai -d boostai"]
            interval: 5s
            timeout: 5s
            retries: 10

volumes:
    BoostAI_postgres_data:
    BoostAI_node_modules:
