FROM node:18-alpine

WORKDIR /app

# Copy package files
COPY backend/package*.json ./
COPY shared/ ../shared/

# Install dependencies
RUN npm install

# Copy source code
COPY backend/ .

# Build TypeScript
RUN npm run build

# Expose port
EXPOSE 3001

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD wget --no-verbose --tries=1 --spider http://localhost:3001/health || exit 1

# Start the application
CMD ["npm", "start"]