services:
  postgres:
    image: postgres:16-alpine
    container_name: econ-postgres
    environment:
      POSTGRES_USER: ${DB_USER:-econ_user}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-econ_pass}
      POSTGRES_DB: ${DB_NAME:-econ_db}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-econ_user} -d ${DB_NAME:-econ_db}"]
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: econ-backend
    environment:
      DB_HOST: econ-postgres
      DB_PORT: 5432
      DB_USER: ${DB_USER:-econ_user}
      DB_PASSWORD: ${DB_PASSWORD:-econ_pass}
      DB_NAME: ${DB_NAME:-econ_db}
      JWT_SECRET: ${JWT_SECRET:-your-secret-key-change-in-production}
      SERVER_PORT: 8080
    ports:
      - "8080:8080"
    networks:
      - caddy
    depends_on:
      postgres:
        condition: service_healthy

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: econ-frontend
    ports:
      - "3002:80"
    networks:
      - caddy
    depends_on:
      - backend

volumes:
  postgres_data:

networks:
  caddy:
    external: true
