FROM node:20-alpine

WORKDIR /app

# better-sqlite3's prebuilt binary coverage for musl/Alpine is inconsistent
# across Node versions; these let its node-gyp fallback build from source
# when no prebuilt matches. No sqlite-dev needed — it bundles its own SQLite.
RUN apk add --no-cache python3 make g++

# Install dependencies first (better layer caching).
COPY package.json package-lock.json ./
RUN npm ci --omit=dev

# App source.
COPY server ./server
COPY public ./public
COPY shared ./shared

ENV NODE_ENV=production
ENV PORT=3000
ENV DATA_DIR=/app/data

EXPOSE 3000
CMD ["node", "server/index.js"]
