FROM node:22-slim

WORKDIR /app

# Dependencies first (better layer caching): copy manifests, install from lock.
COPY package.json package-lock.json ./
RUN npm ci

# Runtime state directory (mounted as a volume in production).
RUN mkdir -p data

# Source + TS config, then compile to build/.
COPY tsconfig.json ./
COPY src/ src/
RUN npm run build

# Drop dev dependencies (typescript, tsx, vitest) to slim the runtime image.
RUN npm prune --omit=dev

CMD ["node", "build/index.js"]
