# Build stage
FROM node:18-alpine AS builder

WORKDIR /app

# Copy package files
COPY package*.json ./
COPY apps/ ./apps/
COPY packages/ ./packages/

# Install dependencies
RUN npm ci

# Build all packages
RUN npm run build

# Production stage
FROM node:18-alpine AS production

WORKDIR /app

# Copy package files
COPY package*.json ./
COPY apps/ ./apps/
COPY packages/ ./packages/

# Copy built artifacts from builder
COPY --from=builder /app/apps/web/dist ./apps/web/dist
COPY --from=builder /app/apps/api/dist ./apps/api/dist

# Install production dependencies only
RUN npm ci --production

# Expose port
EXPOSE 3000

# Start the API server
CMD ["node", "apps/api/dist/index.js"]
