FROM node:24.11.0-alpine AS base
WORKDIR /app

# 1) Install dependencies (cached until package files change)
COPY package*.json ./
RUN npm ci

# 2) Build the React client (only re-run when client sources change)
COPY public ./public
COPY src ./src
RUN npm run build

# 3) Copy server-side files (changes here skip the expensive client build layer)
COPY server.js ./
COPY services ./services
COPY data ./data
RUN mkdir -p config

ENV NODE_ENV=production
EXPOSE 3000
CMD ["node", "server.js"]
