services:
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: trekr
      POSTGRES_USER: trekr
      POSTGRES_PASSWORD: trekr
    volumes:
      - db_data:/var/lib/postgresql/data
      - ./db-scripts/ddl.sql:/docker-entrypoint-initdb.d/ddl.sql:ro
      - ./db-scripts/dml.sql:/docker-entrypoint-initdb.d/dml.sql:ro
      - ./db-scripts/docker-init/01-init.sql:/docker-entrypoint-initdb.d/01-init.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U trekr -d trekr"]
      interval: 5s
      timeout: 5s
      retries: 10
    ports:
      - "5432:5432"

  backend:
    build: ./backend
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/trekr
      SPRING_DATASOURCE_USERNAME: trekr
      SPRING_DATASOURCE_PASSWORD: trekr
      SPRING_JPA_HIBERNATE_DDL_AUTO: none
      JWT_SECRET: ${JWT_SECRET:-change-me-in-production-min-32-chars}
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "8080:8080"

  frontend:
    build: ./frontend
    ports:
      - "3000:80"
    depends_on:
      - backend

volumes:
  db_data:
