services:
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    ports:
      - "3000:80"
    networks:
      - public

  fastapi:
    build:
      context: ./backend
      dockerfile: Dockerfile
    ports:
      - "8000:8000"
    env_file:
      - ./backend/.env
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - public
      - internal

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: nims
      POSTGRES_PASSWORD: nims_dev
      POSTGRES_DB: nims
    ports:
      - "5432:5432"      # exposed so local FastAPI (Option B) can reach it
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U nims"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - internal

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"      # exposed so local FastAPI (Option B) can reach it
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5
    networks:
      - internal

volumes:
  postgres_data:

networks:
  internal:
  public: