# Deployment Guide

## Prerequisites

Before deploying StartupLX:

- [ ] VPS server with Docker installed (Hetzner CX22 or equivalent)
- [ ] Domain registered (startuplx.com recommended)
- [ ] SSL certificate via Let's Encrypt (handled by Caddy)
- [ ] Stripe account with API keys
- [ ] Pipedrive account with API key
- [ ] Calendly account with Webhooks
- [ ] Notion account with API key and integration created
- [ ] n8n instance configured (Docker or cloud)
- [ ] Metabase account or self-hosted instance

## Deployment Steps

### 1. Server Setup

```bash
# Install Docker and Docker Compose
sudo apt update && sudo apt install docker.io docker-compose

# Create project directory
mkdir -p /opt/startuplx
cd /opt/startuplx

# Clone this repository
git clone <repo-url> .

# Set environment variables
cp .env.example .env
nano .env  # Add your secrets
```

### 2. Environment Configuration

Required environment variables in `.env`:

```bash
# Stripe
STRIPE_SECRET_KEY=sk_live_...
STRIPE_WEBHOOK_SECRET=whsec_...

# Pipedrive
PILEDRIVE_API_TOKEN=your-token

# Notion
NOTION_KEY=secret_...
NOTION_DATABASE_ID=...

# Calendly
CALENDLY_WEBHOOK_SECRET=...

# n8n
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=...

# Dashboard
METABASE_SITE_URL=https://dashboard.startuplx.com
```

### 3. Deploy Stack

```bash
# Start all services
docker-compose up -d

# Run database migrations (if any)
docker-compose exec app npm run migrate

# Verify all services running
docker-compose ps
```

### 4. Webflow Deployment

```bash
# Build website
npm run build

# Deploy via FTP or rsync
# For local: push to GitHub, then Netlify/Vercel
```

### 5. n8n Workflow Import

```bash
# Import workflow definitions
for file in workflows/*.json; do
  n8n import:workflow --separate --input "$file"
done
```

### 6. Webhook Setup

Set these URLs in your service dashboards:
- Stripe → `https://api.startuplx.com/webhook/stripe`
- Calendly → `https://api.startuplx.com/webhook/calendly`
- Typeform → `https://api.startuplx.com/webhook/typeform`

## Monitoring Checklist

After deployment:
- [ ] Dashboard showing live data
- [ ] First test booking completes successfully
- [ ] Invoice generated for test payment
- [ ] Email sequences send correctly
- [ ] All webhooks verified and logging

## Rollback Procedure

If something breaks:
1. `docker-compose down`
2. Restore database from latest backup
3. `git checkout <previous-stable-commit>`
4. Update .env if needed
5. `docker-compose up -d`

## Production Checklist

- [ ] SSL active on all domains
- [ ] Firewall rules configured
- [ ] Backup cron job running
- [ ] Monitoring alerts set up
- [ ] Error tracking enabled
- [ ] Log rotation configured
- [ ] Disaster recovery plan documented