version: '3.8'

services:
  db:
    image: postgis/postgis:16-3.4
    container_name: keinasystem_db
    environment:
      POSTGRES_DB: keinasystem
      POSTGRES_USER: keinasystem
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U keinasystem -d keinasystem"]
      interval: 5s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: keinasystem_backend
    environment:
      DB_NAME: keinasystem
      DB_USER: keinasystem
      DB_PASSWORD: ${DB_PASSWORD}
      DB_HOST: db
      DB_PORT: 5432
      SECRET_KEY: ${SECRET_KEY}
      DEBUG: "True"
      MAIL_API_KEY: ${MAIL_API_KEY}
    ports:
      - "8000:8000"
    volumes:
      - ./backend:/app
    depends_on:
      db:
        condition: service_healthy
    command: python manage.py runserver 0.0.0.0:8000

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: keinasystem_frontend
    environment:
      NEXT_PUBLIC_API_URL: http://localhost:8000
      WATCHPACK_POLLING: "true"
    ports:
      - "3000:3000"
    volumes:
      - ./frontend:/app
      - /app/node_modules
    depends_on:
      - backend

volumes:
  postgres_data:
