# 🚀 IntelliCodeMCP Deployment Guide

## Quick Deployment

### Option 1: Automated Installation
```bash
# Run the automated installer
node install.js

# Test the system
npm test
```

### Option 2: Manual Installation
```bash
# Install dependencies
npm install

# Build the project
npm run build

# Test the system
npm run test:quick
```

## 📦 Package Distribution

### Creating a Distribution Package
```bash
# Clean and build
npm run clean
npm run build

# Create distribution archive
tar -czf intellicode-mcp-v1.0.0.tar.gz \
  --exclude=node_modules \
  --exclude=.git \
  --exclude=*.log \
  .
```

### Installing from Package
```bash
# Extract package
tar -xzf intellicode-mcp-v1.0.0.tar.gz
cd mcp-project

# Install and setup
npm install
npm run build
npm test
```

## 🌐 Production Deployment

### System Requirements
- **Node.js**: v16.0.0 or higher
- **npm**: v8.0.0 or higher
- **Memory**: 512MB minimum, 1GB recommended
- **Storage**: 100MB for application, additional space for data
- **OS**: Windows, macOS, Linux

### Environment Setup
```bash
# Set production environment
export NODE_ENV=production

# Optional: Set custom data directory
export INTELLIMCP_DATA_DIR=/path/to/data

# Optional: Set log level
export INTELLIMCP_LOG_LEVEL=info
```

### Production Installation
```bash
# Clone/download project
git clone <repository-url>
cd mcp-project

# Install production dependencies only
npm ci --only=production

# Build for production
npm run build

# Verify installation
npm test
```

## 🔧 Configuration for Production

### 1. Performance Tuning
Edit `.roo/code-intelligence.yaml`:
```yaml
performance:
  max_processing_time_ms: 5000
  max_tokens_per_task: 4000
  quality_threshold: 0.98
  
  logging:
    log_level: "WARN"  # Reduce logging in production
    max_log_files: 50
    
  resources:
    cpu_usage_limit: 8
    memory_limit_mb: 1024
```

### 2. Security Settings
```yaml
security:
  enable_file_validation: true
  max_file_size_mb: 10
  allowed_file_types: ["ts", "js", "json", "md", "txt", "yaml"]
```

### 3. Data Management
```yaml
data:
  auto_cleanup: true
  max_search_results: 100
  retention_days: 30
```

## 🐳 Docker Deployment

### Dockerfile
```dockerfile
FROM node:18-alpine

WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm ci --only=production

# Copy source code
COPY . .

# Build application
RUN npm run build

# Create data directory
RUN mkdir -p /app/data/intelliMemoryHub

# Set permissions
RUN chown -R node:node /app

USER node

EXPOSE 3000

CMD ["npm", "start"]
```

### Docker Compose
```yaml
version: '3.8'
services:
  intellicode-mcp:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - ./data:/app/data
    environment:
      - NODE_ENV=production
      - INTELLIMCP_DATA_DIR=/app/data
    restart: unless-stopped
```

### Build and Run
```bash
# Build Docker image
docker build -t intellicode-mcp:latest .

# Run container
docker run -d \
  --name intellicode-mcp \
  -p 3000:3000 \
  -v $(pwd)/data:/app/data \
  intellicode-mcp:latest

# Or use docker-compose
docker-compose up -d
```

## ☁️ Cloud Deployment

### AWS EC2
```bash
# Launch EC2 instance (Ubuntu 20.04 LTS)
# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

# Deploy application
git clone <repository-url>
cd mcp-project
npm install
npm run build
npm test

# Setup as service (systemd)
sudo cp deployment/intellicode-mcp.service /etc/systemd/system/
sudo systemctl enable intellicode-mcp
sudo systemctl start intellicode-mcp
```

### Google Cloud Platform
```bash
# Use Cloud Run for serverless deployment
gcloud run deploy intellicode-mcp \
  --source . \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated
```

### Azure Container Instances
```bash
# Deploy to Azure
az container create \
  --resource-group myResourceGroup \
  --name intellicode-mcp \
  --image intellicode-mcp:latest \
  --cpu 1 \
  --memory 1 \
  --ports 3000
```

## 📊 Monitoring & Maintenance

### Health Checks
```bash
# System health check
npm test

# Performance check
node dist/main/cli.js --tool performance_orchestrator --task '{"id":"health","input":"system check","priority":"low"}'

# Storage check
du -sh intelliMemoryHub/
```

### Log Management
```bash
# View recent logs
tail -f intelliMemoryHub/technical/performance_logs/*.json

# Rotate logs (add to cron)
find intelliMemoryHub/technical/performance_logs/ -name "*.json" -mtime +30 -delete
```

### Backup Strategy
```bash
# Backup data
tar -czf backup-$(date +%Y%m%d).tar.gz intelliMemoryHub/

# Restore data
tar -xzf backup-20250612.tar.gz
```

## 🔄 Updates & Upgrades

### Update Process
```bash
# Backup current data
npm run backup  # If implemented

# Pull updates
git pull origin main

# Install new dependencies
npm install

# Rebuild
npm run clean
npm run build

# Test
npm test

# Restart service
sudo systemctl restart intellicode-mcp
```

### Version Management
```bash
# Check current version
npm list intellicode-mcp

# Update to specific version
npm install intellicode-mcp@1.1.0

# Rollback if needed
npm install intellicode-mcp@1.0.0
```

## 🚨 Troubleshooting

### Common Issues

**Build Failures:**
```bash
npm run clean
rm -rf node_modules package-lock.json
npm install
npm run build
```

**Permission Issues:**
```bash
sudo chown -R $USER:$USER .
chmod +x dist/main/cli.js
```

**Memory Issues:**
```bash
# Increase Node.js memory limit
export NODE_OPTIONS="--max-old-space-size=2048"
npm start
```

**Port Conflicts:**
```bash
# Find process using port
lsof -i :3000
kill -9 <PID>
```

### Support
- Check logs in `intelliMemoryHub/technical/`
- Run system test: `npm test`
- Review configuration files
- Check GitHub issues for known problems

---

**IntelliCodeMCP** - Ready for production deployment! 🚀
