name: ccodit

services:
  api:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: ccodit_api
    ports:
      - "8080:8080"
    environment:
      APP_ENV: local
      APP_DEBUG: "true"
      APP_KEY: ${APP_KEY:-base64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=}
      APP_URL: http://localhost:8080
      FRONTEND_URL: http://localhost:5173
      CORS_ALLOWED_ORIGINS: http://localhost:5173
      DATABASE_URL: postgres://ccodit:ccodit@db:5432/ccodit
      REDIS_URL: redis://redis:6379
      CACHE_STORE: redis
      QUEUE_CONNECTION: redis
      SESSION_DRIVER: redis
      MAIL_MAILER: log
      RUN_MIGRATIONS: "true"
      RUN_SEEDERS: "true"
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started
    volumes:
      - ./backend:/var/www/html
      - vendor:/var/www/html/vendor

  db:
    image: postgres:16-alpine
    container_name: ccodit_db
    environment:
      POSTGRES_DB: ccodit
      POSTGRES_USER: ccodit
      POSTGRES_PASSWORD: ccodit
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ccodit -d ccodit"]
      interval: 5s
      timeout: 5s
      retries: 10

  redis:
    image: redis:7-alpine
    container_name: ccodit_redis
    ports:
      - "6379:6379"

  web:
    image: node:20-alpine
    container_name: ccodit_web
    working_dir: /app
    ports:
      - "5173:5173"
    environment:
      VITE_API_URL: http://localhost:8080/api/v1
    command: sh -c "npm install && npm run dev -- --host 0.0.0.0"
    volumes:
      - ./frontend:/app
      - web_node_modules:/app/node_modules

volumes:
  pgdata:
  vendor:
  web_node_modules:
