services:
  php:
    build:
      context: .
      dockerfile: ./docker/php/Dockerfile
    container_name: crm_php
    volumes:
      - ./backend:/var/www/html
    depends_on:
      - pgsql
      - redis
    networks:
      - crm_network

  nginx:
    image: nginx:alpine
    container_name: crm_nginx
    ports:
      - "8000:80"
    volumes:
      - ./backend:/var/www/html
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
    networks:
      - crm_network

  pgsql:
    image: postgres:16-alpine
    container_name: crm_pgsql
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: crm
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - pgsql-data:/var/lib/postgresql/data
    networks:
      - crm_network
    healthcheck:
      test: ["CMD", "pg_isready", "-q", "-d", "crm", "-U", "postgres"]
      interval: 10s
      timeout: 5s
      retries: 3

  redis:
    image: redis:7-alpine
    container_name: crm_redis
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    networks:
      - crm_network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 3

networks:
  crm_network:
    driver: bridge

volumes:
  pgsql-data:
  redis-data:
