# ⚡ Quick Start Guide - BuzzTrail Backup System

## 🚀 Get Running in 5 Minutes

### Step 1: Setup (2 minutes)

```bash
# Navigate to project
cd /Users/lars/mycode/buzztrail/extension

# Install and build everything  
pnpm install && pnpm nx build shared-database && pnpm nx build accounts-backup && pnpm nx build backup-workflows

# Start the system
cd backup-workflows && npx motia dev --port 3002
```

### Step 2: Access the System (30 seconds)

- **Visual Interface**: http://localhost:3002/
- **API Ready**: System automatically initializes 16-table database with migrations

### Step 3: Perform Your First Backup (2 minutes)

```bash
# Trigger full backup (creates sample data if needed)
curl -X POST http://localhost:3002/backup/trigger \
  -H "Content-Type: application/json" \
  -d '{"backupType": "full", "retentionDays": 30}'

# Expected Response:
# {
#   "success": true, 
#   "message": "Backup workflow triggered successfully",
#   "timestamp": "2025-09-02T10:00:00.000Z"
# }
```

### Step 4: Monitor Progress (30 seconds)

1. Open **http://localhost:3002/**
2. Watch the visual workflow execute:
   - `BackupInit` ⏳ → ✅ (Customer discovery)  
   - `BackupExecution` ⏳ → ✅ (Data backup)
   - `BackupFinish` ⏳ → ✅ (Report generation)

🎉 **Done!** Your backup system is running with a complete enterprise-grade database supporting Tavus and Langfuse integration.

## 📋 What You Just Set Up

### **Database Schema (16 Tables)**
- **Tavus**: Conversations, personas, replicas, events, media (5 tables)
- **Langfuse**: Traces, observations, sessions, scores, datasets (6 tables)  
- **Management**: Schedules, jobs, policies, usage tracking (5 tables)

### **Capabilities Ready to Use**
- ✅ Visual workflow monitoring via Motia workbench
- ✅ REST API endpoints for backup/cleanup operations
- ✅ Automated database migrations with rollback support
- ✅ Performance-optimized queries (60+ indexes)
- ✅ Comprehensive logging and error handling

## 🎯 Next Steps

### Add Real Customer Data
```bash
# Connect to database
sqlite3 backup-workflows/backup-data.db

# Add a customer
INSERT INTO customers (customer_id, customer_name, created_at, updated_at) 
VALUES ('customer-123', 'Your Company', datetime('now'), datetime('now'));

# Exit and trigger backup for real data
.quit
curl -X POST http://localhost:3002/backup/trigger -H "Content-Type: application/json" -d '{"backupType": "full"}'
```

### Configure Service APIs
```bash
# Add to backup-workflows/.env
TAVUS_API_KEY=your-tavus-api-key
LANGFUSE_API_KEY=your-langfuse-api-key  
LANGFUSE_BASE_URL=https://your-langfuse-instance.com
```

### Setup Automated Backups
```bash
# Schedule daily backups (add to crontab)
0 2 * * * cd /path/to/backup-workflows && curl -X POST http://localhost:3002/backup/trigger -H "Content-Type: application/json" -d '{"backupType": "incremental"}'

# Schedule weekly cleanup
0 3 * * 0 curl -X POST http://localhost:3002/cleanup/trigger -H "Content-Type: application/json" -d '{"retentionDays": 30}'
```

## 📖 Complete Documentation

For detailed setup, operations, and management:

- **[SETUP_GUIDE.md](./SETUP_GUIDE.md)**: Complete installation and configuration
- **[BACKUP_OPERATIONS_GUIDE.md](./BACKUP_OPERATIONS_GUIDE.md)**: Step-by-step backup procedures
- **[DATABASE_MANAGEMENT_GUIDE.md](./DATABASE_MANAGEMENT_GUIDE.md)**: Database administration and monitoring
- **[README.md](./README.md)**: Full system overview and API documentation

## 🚨 Troubleshooting

### Port Issues
```bash
# If port 3002 is busy, use an alternative port
# NOTE: Port 3003 is reserved for slide-system (deployed on Railway)
npx motia dev --port 3004
```

### Build Issues
```bash
# Clean rebuild
pnpm nx reset && pnpm nx build shared-database && pnpm nx build accounts-backup
```

### Database Issues
```bash
# Test migrations
cd libs/accounts-backup && npx ts-node src/test-migrations.ts
```

Your enterprise-grade backup system is ready! 🎉