# SEEN - Quick Reference Card

## 🚀 Quick Commands

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

# View logs
docker compose logs -f

# Stop services
docker compose down

# Rebuild
docker compose up -d --build
```

### Production
```bash
# Deploy
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build

# View logs
docker compose -f docker-compose.yml -f docker-compose.prod.yml logs -f

# Stop
docker compose -f docker-compose.yml -f docker-compose.prod.yml down
```

## 🔐 Security Setup

### Generate Secrets
```bash
./scripts/generate-secrets.sh
```

### Configure Environment
```bash
cp backend/.env.production backend/.env.production.local
nano backend/.env.production.local
```

Required:
- `SEEN_AUTH_JWT_SECRET` - From generate-secrets.sh
- `POSTGRES_PASSWORD` - From generate-secrets.sh
- `SEEN_TMDB_API_KEY` - From https://www.themoviedb.org/settings/api

## 🏥 Health Checks

```bash
# Backend
curl http://localhost:8081/api/v1/health/live
curl http://localhost:8081/api/v1/health/ready

# Frontend
curl http://localhost:8080/health

# Database
docker exec seen-postgres pg_isready -U seen

# Cache
docker exec seen-dragonfly redis-cli ping
```

## 💾 Backup & Restore

### Manual Backup
```bash
docker exec seen-postgres pg_dump -U seen seen | gzip > backup.sql.gz
```

### Restore
```bash
docker exec -i seen-backup /restore.sh /backups/backup.sql.gz
```

### List Backups
```bash
ls -lh backups/
```

## 📊 Monitoring

### Container Stats
```bash
docker stats
```

### View Logs
```bash
# All services
docker compose logs -f

# Specific service
docker compose logs -f seen-backend
docker compose logs -f seen-frontend
docker compose logs -f postgres
docker compose logs -f dragonfly

# Last 100 lines
docker compose logs --tail=100 seen-backend
```

### Database Stats
```bash
# Database size
docker exec seen-postgres psql -U seen -d seen -c "SELECT pg_size_pretty(pg_database_size('seen'));"

# Table sizes
docker exec seen-postgres psql -U seen -d seen -c "SELECT schemaname, tablename, pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS size FROM pg_tables WHERE schemaname = 'public' ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;"

# Vacuum
docker exec seen-postgres psql -U seen -d seen -c "VACUUM ANALYZE;"
```

### Cache Stats
```bash
# Memory usage
docker exec seen-dragonfly redis-cli INFO memory

# Stats
docker exec seen-dragonfly redis-cli INFO stats

# Keys
docker exec seen-dragonfly redis-cli KEYS "seen:*"

# Clear cache (if needed)
docker exec seen-dragonfly redis-cli FLUSHDB
```

## 🔧 Maintenance

### Update Application
```bash
git pull
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build
docker image prune -f
```

### Restart Services
```bash
# All services
docker compose restart

# Specific service
docker compose restart seen-backend
docker compose restart seen-frontend
```

### Clean Up
```bash
# Remove stopped containers
docker container prune -f

# Remove unused images
docker image prune -f

# Remove unused volumes (CAREFUL!)
docker volume prune -f

# Full cleanup (CAREFUL!)
docker system prune -af
```

## 🌐 URLs

### Development
- Frontend: http://localhost:8080
- Backend API: http://localhost:8081
- Database: localhost:5432
- Cache: localhost:6379

### Production
- Frontend: https://yourdomain.com
- Backend API: https://yourdomain.com/api
- Health: https://yourdomain.com/health

## 📝 API Endpoints

### Authentication
```bash
# Register
curl -X POST http://localhost:8081/api/v1/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email":"user@example.com","password":"SecurePass123!","displayName":"User"}'

# Login
curl -X POST http://localhost:8081/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"user@example.com","password":"SecurePass123!"}'

# Get current user
curl http://localhost:8081/api/v1/auth/me \
  -H "Authorization: Bearer YOUR_TOKEN"
```

### Catalog
```bash
# Dashboard
curl http://localhost:8081/api/v1/dashboard \
  -H "Authorization: Bearer YOUR_TOKEN"

# Discover
curl http://localhost:8081/api/v1/discover

# Search
curl "http://localhost:8081/api/v1/search?q=matrix"

# Games
curl http://localhost:8081/api/v1/games
```

### Watch Later
```bash
# List
curl http://localhost:8081/api/v1/watch-later \
  -H "Authorization: Bearer YOUR_TOKEN"

# Add
curl -X POST http://localhost:8081/api/v1/watch-later \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"mediaId":123}'

# Remove
curl -X DELETE http://localhost:8081/api/v1/watch-later/123 \
  -H "Authorization: Bearer YOUR_TOKEN"
```

### Downloads
```bash
# Create
curl -X POST http://localhost:8081/api/v1/downloads \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"sourceType":"magnet","source":"magnet:?xt=...","title":"Movie"}'

# List
curl http://localhost:8081/api/v1/downloads \
  -H "Authorization: Bearer YOUR_TOKEN"

# Cancel
curl -X DELETE http://localhost:8081/api/v1/downloads/JOB_ID \
  -H "Authorization: Bearer YOUR_TOKEN"
```

## 🐛 Troubleshooting

### Backend won't start
```bash
# Check logs
docker compose logs seen-backend

# Check database connection
docker exec seen-postgres psql -U seen -d seen -c "SELECT 1;"

# Check environment
docker exec seen-backend env | grep SEEN_
```

### Frontend shows errors
```bash
# Check logs
docker compose logs seen-frontend

# Check nginx config
docker exec seen-frontend nginx -t

# Rebuild
docker compose up -d --build seen-frontend
```

### Database issues
```bash
# Check status
docker compose ps postgres

# Check logs
docker compose logs postgres

# Connect to database
docker exec -it seen-postgres psql -U seen -d seen
```

### Cache issues
```bash
# Check status
docker compose ps dragonfly

# Test connection
docker exec seen-dragonfly redis-cli ping

# Check logs
docker compose logs dragonfly
```

## 📚 Documentation

- **README.md** - Project overview
- **DEPLOYMENT_GUIDE.md** - Full deployment guide
- **SECURITY.md** - Security guidelines
- **PRODUCTION_CHECKLIST.md** - Pre-deployment checklist
- **PRODUCTION_READY_SUMMARY.md** - What was done

## 🆘 Emergency Commands

### Stop Everything
```bash
docker compose down
```

### Restore from Backup
```bash
docker exec -i seen-backup /restore.sh /backups/BACKUP_FILE.sql.gz
```

### Reset Database (DESTRUCTIVE!)
```bash
docker compose down -v
docker compose up -d
```

### View All Containers
```bash
docker ps -a
```

### Check Disk Space
```bash
df -h
docker system df
```

## 📞 Support

- GitHub Issues: Report bugs
- Documentation: Check docs folder
- Security: See SECURITY.md

---

**Quick Reference Version**: 1.0.0  
**Last Updated**: April 6, 2026
