# Twenty CRM Deployment — commons-hub Lead Funnel

## 1. Deploy Twenty CRM Stack on Netcup

```bash
# SSH to server
ssh netcup-full

# Create directory and copy files
mkdir -p /opt/twenty-crm
# (copy docker-compose.yml and .env from this directory)

# Generate secrets
cd /opt/twenty-crm
cat > .env <<EOF
POSTGRES_PASSWORD=$(openssl rand -hex 16)
APP_SECRET=$(openssl rand -hex 32)
EOF

# Start the stack
docker compose up -d

# Wait for healthy status (may take 2-3 minutes on first boot for migrations)
docker compose ps
docker logs twenty-ch-server --tail 50
```

## 2. Create Admin Account

Once Twenty is healthy at `https://crm.rspace.online`:

1. Open `https://crm.rspace.online` in browser
2. Twenty will show the initial setup wizard
3. Create admin account: **jeff / jeffemmett@gmail.com**
4. Set workspace name: **commons-hub**

## 3. Generate API Token & Store in Infisical

1. In Twenty: Settings → Accounts → API Keys → Create API key
2. Copy the token
3. Store in Infisical:
   - Project: `rspace` (same project as rSpace secrets)
   - Secret name: `TWENTY_API_TOKEN`
   - Secret value: the API token from step 2
4. Restart rSpace to pick up the new token:
   ```bash
   cd /opt/rspace-online && docker compose restart rspace
   ```

## 4. Configure Lead Funnel Pipeline

In Twenty CRM UI: Settings → Data model → Opportunity → Edit stages

### Pipeline Stages (7)

| # | Stage | Color |
|---|-------|-------|
| 1 | New Lead | Blue |
| 2 | Contacted | Yellow |
| 3 | Qualified | Orange |
| 4 | Offer Sent | Purple |
| 5 | Confirmed | Teal |
| 6 | Won | Green |
| 7 | Lost / Not Now | Red |

### Custom Fields

Add via Settings → Data model → [Object] → Add field:

**On Opportunity:**
- Event Dates (preferred) — DATE
- Event Dates (flexible range) — TEXT
- Group Size — NUMBER
- Needs: Accommodation — BOOLEAN
- Needs: Catering — BOOLEAN
- Needs: Rooms — BOOLEAN
- Needs: AV — BOOLEAN
- Next Action Date — DATE (required)
- Follow-up Date — DATE
- Lost Reason — TEXT

**On Company:**
- Lead Source — SELECT (options: Website, Referral, Event, Cold Outreach, Partner, Other)
- Last Touch Date — DATE

### Saved Views

Create via the Opportunities list → Save view:

1. **My Pipeline** — Group by: Stage, Filter: Assigned to = current user
2. **Needs Follow-up** — Filter: Next Action Date <= today
3. **Stale Leads** — Filter: Next Action Date is empty

## 5. Create commons-hub Space

This will be done via the rSpace community store or directly:

- Space slug: `commons-hub`
- Visibility: `permissioned`
- Owner: jeff (jeffemmett@gmail.com)
- Enabled modules: `["rnetwork"]`

The CRM will then be accessible at: `commons-hub.rspace.online/rnetwork/crm`

## 6. Deploy rSpace Changes

```bash
ssh netcup-full
cd /opt/rspace-online
git pull
docker compose up -d --build
```

## Verification Checklist

- [ ] `docker compose ps` on Netcup — all Twenty containers healthy
- [ ] `curl https://crm.rspace.online` — Twenty CRM loads
- [ ] Navigate to `commons-hub.rspace.online/rnetwork/crm` — CRM embedded in rSpace shell
- [ ] Log in as jeff — admin access confirmed
- [ ] Open pipeline view — 7 stages visible
- [ ] Create test opportunity — all custom fields present
- [ ] Verify "Next Action Date" is required
- [ ] Check rNetwork graph view still works (`/rnetwork` default view)
