services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: app_container
    ports:
      - 3000:3000
    environment:
      - NODE_ENV=development
      - POSTGRES_USER=app_db_user
      - POSTGRES_DB=app_db
      - POSTGRES_PASSWORD=app_db__user_password
    volumes:
      - .:/app
      - /app/node_modules
    networks:
      - app_network
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres
    container_name: postgres_container
    restart: always
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: app_db_user
      POSTGRES_DB: app_db
      POSTGRES_PASSWORD: app_db__user_password
    ports:
      - 5432:5432
    networks:
      - app_network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
      interval: 30s
      timeout: 10s
      retries: 5

  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin_container
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@example.com
      PGADMIN_DEFAULT_PASSWORD: admin
    ports:
      - 8080:80
    volumes:
      - pgadmin-data:/var/lib/pgadmin
    networks:
      - app_network

volumes:
  db-data:
  pgadmin-data:

networks:
  app_network: