# Port Assignments

**Last Updated**: 2025-10-15
**Version**: 1.0

## Overview

This document tracks all port assignments across the BuzzTrail monorepo to prevent conflicts.

## Port Registry

| Port | Application | Purpose | Status |
|------|-------------|---------|--------|
| 3003 | slide-system | Motia API backend (DEPRECATED - use Railway) | ⚠️ DEPRECATED |
| 3006 | voice-demo-ui | LiveKit voice + slides demo frontend | ✅ ACTIVE |
| 4200 | chatbot | Chatbot dev server | ✅ ACTIVE |
| 4200 | backup-manager | Backup manager dev server | ⚠️ CONFLICT |
| 4300 | chatbot | Chatbot preview server | ✅ ACTIVE |
| 4500 | demo-experience-ui | Tavus/Daily.co demo frontend | ✅ ACTIVE |
| 8080 | demos | Customer-facing demos | ✅ ACTIVE |

## Port Conflicts to Resolve

### Conflict 1: Port 4200 (chatbot vs backup-manager)
**Issue**: Both `chatbot` and `backup-manager` are configured to use port 4200.

**Impact**: Cannot run both apps simultaneously in dev mode.

**Resolution Options**:
1. Change `backup-manager` to port 4201 (recommended)
2. Change `chatbot` to another port
3. Use Nx task dependencies to ensure they never run together

### Conflict 2: RESOLVED - Port 3006
**Previous Issue**: Port 3005 was in use by another process.

**Resolution**: ✅ Changed `voice-demo-ui` to port 3006.

## Port Assignment Rules

### Development Ports (localhost only)
- **3000-3099**: Backend APIs and services
  - 3003: slide-system API (primary backend, Motia dev server)
  - 3001-3010: Reserved for future backend services

- **4000-4999**: Frontend applications
  - 4200-4299: Primary dev servers
  - 4300-4399: Preview servers
  - 4500-4599: Additional frontends

- **8000-8999**: Special purpose servers
  - 8080: Customer-facing demos
  - 8081-8089: Reserved for additional demo variations

### Production Ports
- slide-system: Railway at https://slide-system-production-5813.up.railway.app (managed by Railway)
- LiveKit: WSS via LiveKit Cloud (wss://buzztrail-fifa4bj6.livekit.cloud)
- Supabase: Cloud (https://dwdytxxqcvlrmyemonxz.supabase.co)

## Configuration Files

### Applications with Port Configuration

**voice-demo-ui**
- File: `voice-demo-ui/vite.config.ts`
- Dev Port: 3006
- Preview Port: 3006

**chatbot**
- File: `apps/chatbot/vite.config.ts`
- Dev Port: 4200
- Preview Port: 4300

**backup-manager**
- File: `apps/backup-manager/vite.config.ts`
- Dev Port: 4200 ⚠️ (CONFLICT with chatbot)
- Preview Port: 4200

**demo-experience-ui**
- File: `apps/demo-experience-ui/vite.config.ts`
- Dev Port: 4500
- Preview Port: 4500

**demos**
- File: `apps/demos/vite.config.ts`
- Dev Port: 8080
- Preview Port: 8080

## How to Check Port Usage

```bash
# Check all ports in use by node processes
lsof -i -P | grep LISTEN | grep node

# Check if specific port is in use
lsof -i :3006

# Find process using a port and kill it
lsof -ti :3006 | xargs kill
```

## Environment Variables

Applications reference ports in their environment configurations:

### voice-demo-ui
```bash
# voice-demo-ui/.env.local
# RECOMMENDED: Use Railway production backend for all development
VITE_API_BASE_URL=https://slide-system-production-5813.up.railway.app

# DEPRECATED: Local backend (no longer recommended)
# VITE_API_BASE_URL=http://localhost:3003

# LiveKit WebSocket URL
VITE_LIVEKIT_URL=wss://buzztrail-fifa4bj6.livekit.cloud
```

### slide-system (Railway)
```bash
# Production environment variables (Railway)
LIVEKIT_URL=wss://buzztrail-xxx.livekit.cloud
LIVEKIT_API_KEY=<from-cloud.livekit.io>
LIVEKIT_API_SECRET=<from-cloud.livekit.io>
DEEPGRAM_API_KEY=<deepgram-api-key>
ELEVENLABS_API_KEY=<elevenlabs-api-key>
OPENAI_API_KEY=<openai-api-key>
SUPABASE_URL=https://dwdytxxqcvlrmyemonxz.supabase.co
SUPABASE_SERVICE_KEY=<supabase-service-key>
```

## Notes

- All dev servers use `localhost` as host
- Production services use cloud providers (Railway, Vercel, LiveKit Cloud, Supabase Cloud)
- When adding new applications, update this document first to reserve a port
- Use `pnpm nx dev <app-name>` to start development servers
- Check for port conflicts before committing new vite.config.ts files
