version: '3.8'

services:
  # PostgreSQL database for development
  postgres:
    image: postgres:16-alpine
    container_name: placebo-postgres-dev
    environment:
      POSTGRES_USER: placebo_user
      POSTGRES_PASSWORD: placebo_password
      POSTGRES_DB: placebo_backend_db
    volumes:
      - postgres_data_dev:/var/lib/postgresql/data
      - ./scripts/init-postgres-dev.sql:/docker-entrypoint-initdb.d/init-postgres-dev.sql
    ports:
      - "5432:5432"
    networks:
      - placebo-network-dev

  # Backend API (NestJS) - Development with hot reload
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile.dev
    container_name: placebo-backend-dev
    env_file:
      - ./backend/.env.docker  # Use the .env.docker file for Docker configuration
    environment:
      # Only override if needed, most config is in .env.docker file
      NODE_ENV: development
    ports:
      - "3000:3000"
    depends_on:
      - postgres
    volumes:
      - ./backend/src:/app/src
      - ./backend/package.json:/app/package.json
      - ./backend/package-lock.json:/app/package-lock.json
      - ./backend/.env.docker:/app/.env  # Mount .env.docker file as .env in container
    command: npm run dev:docker
    networks:
      - placebo-network-dev

  # Frontend (TanStack React) - Development with hot reload
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile.dev
    container_name: placebo-frontend-dev
    env_file:
      - ./frontend/.env  # Use the .env file for configuration
    environment:
      NODE_ENV: development
    ports:
      - "5173:5173"
    depends_on:
      - backend
    volumes:
      - ./frontend/src:/app/src
      - ./frontend/public:/app/public
      - ./frontend/package.json:/app/package.json
      - ./frontend/package-lock.json:/app/package-lock.json
      - ./frontend/index.html:/app/index.html
      - ./frontend/vite.config.ts:/app/vite.config.ts
      - ./frontend/tsconfig.json:/app/tsconfig.json
      - ./frontend/tsconfig.node.json:/app/tsconfig.node.json
      - ./frontend/tailwind.config.js:/app/tailwind.config.js
      - ./frontend/.env:/app/.env
    command: npm run dev:docker
    networks:
      - placebo-network-dev

  # CMS (Strapi) - Development with hot reload
  cms:
    build:
      context: ./cms/cms
      dockerfile: Dockerfile.dev
    container_name: placebo-cms-dev
    environment:
      NODE_ENV: development
      DATABASE_CLIENT: postgres
      DATABASE_HOST: postgres
      DATABASE_PORT: 5432
      DATABASE_NAME: placebo_cms_db
      DATABASE_USERNAME: placebo_user
      DATABASE_PASSWORD: placebo_password
      DATABASE_SSL: "false"
      JWT_SECRET: dev-jwt-secret
      ADMIN_JWT_SECRET: dev-admin-jwt-secret
      APP_KEYS: dev-app-keys
      API_TOKEN_SALT: dev-api-token-salt
      TRANSFER_TOKEN_SALT: dev-transfer-token-salt
      CORS_ORIGIN: http://localhost:5173
      PORT: 1337
    ports:
      - "1337:1337"
    depends_on:
      - postgres
    volumes:
      - ./cms/cms/src:/app/src
      - ./cms/cms/config:/app/config
      - ./cms/cms/public:/app/public
      - ./cms/cms/package.json:/app/package.json
      - ./cms/cms/package-lock.json:/app/package-lock.json
    command: npm run develop
    networks:
      - placebo-network-dev

volumes:
  postgres_data_dev:
    driver: local

networks:
  placebo-network-dev:
    driver: bridge