# Deployment Guide - Customer Support Ticketing System

## 🚀 Quick Deployment Options

### Option 1: Heroku (Recommended for Quick Demo)

1. **Install Heroku CLI and login**
2. **Create Heroku app:**

    ```bash
    heroku create your-support-system
    ```

3. **Add PostgreSQL addon:**

    ```bash
    heroku addons:create heroku-postgresql:mini
    ```

4. **Set environment variables:**

    ```bash
    heroku config:set APP_ENV=production
    heroku config:set APP_DEBUG=false
    heroku config:set APP_KEY=$(php artisan --no-ansi key:generate --show)
    heroku config:set BROADCAST_CONNECTION=pusher
    heroku config:set PUSHER_APP_ID=your_pusher_app_id
    heroku config:set PUSHER_APP_KEY=your_pusher_key
    heroku config:set PUSHER_APP_SECRET=your_pusher_secret
    heroku config:set PUSHER_APP_CLUSTER=mt1
    ```

5. **Create Procfile:**

    ```bash
    echo "web: vendor/bin/heroku-php-apache2 public/" > Procfile
    echo "worker: php artisan queue:work --sleep=3 --tries=3" >> Procfile
    ```

6. **Deploy:**
    ```bash
    git add .
    git commit -m "Deploy to Heroku"
    git push heroku main
    heroku run php artisan migrate --force
    heroku run php artisan db:seed --class=AdminSeeder --force
    ```

### Option 2: Railway

1. **Connect GitHub repository to Railway**
2. **Set environment variables in Railway dashboard**
3. **Deploy automatically via GitHub integration**

### Option 3: Vercel + PlanetScale

1. **Frontend (React) on Vercel**
2. **Backend API on Railway/Heroku**
3. **Database on PlanetScale**

## 🔧 Environment Configuration for Production

### Required Environment Variables

```env
APP_NAME="Support Ticket System"
APP_ENV=production
APP_KEY=your_generated_app_key
APP_DEBUG=false
APP_URL=https://your-domain.com

# Database (PostgreSQL for production)
DB_CONNECTION=pgsql
DB_HOST=your_db_host
DB_PORT=5432
DB_DATABASE=your_db_name
DB_USERNAME=your_db_user
DB_PASSWORD=your_db_password

# Pusher (Required for real-time features)
BROADCAST_CONNECTION=pusher
PUSHER_APP_ID=your_app_id
PUSHER_APP_KEY=your_app_key
PUSHER_APP_SECRET=your_app_secret
PUSHER_APP_CLUSTER=mt1

# Session and Cache
SESSION_DRIVER=database
CACHE_STORE=database
QUEUE_CONNECTION=database

# Mail (Optional - for notifications)
MAIL_MAILER=smtp
MAIL_HOST=your_smtp_host
MAIL_PORT=587
MAIL_USERNAME=your_email
MAIL_PASSWORD=your_email_password
MAIL_ENCRYPTION=tls
```

## 📦 Pre-deployment Checklist

-   [ ] Set up Pusher account and get credentials
-   [ ] Configure production database
-   [ ] Set all environment variables
-   [ ] Test local production build
-   [ ] Set up error monitoring (optional)

## 🌐 Pusher Setup (Required for Real-time Features)

1. **Create Pusher account:** https://pusher.com
2. **Create new app**
3. **Get credentials:**
    - App ID
    - Key
    - Secret
    - Cluster
4. **Add to environment variables**

## 🔒 Security Considerations

-   Set `APP_DEBUG=false` in production
-   Use strong `APP_KEY`
-   Configure CORS properly
-   Use HTTPS in production
-   Set secure session cookies
-   Regular security updates

## 📊 Performance Optimization

```bash
# Cache configurations
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Optimize autoloader
composer install --optimize-autoloader --no-dev

# Build production assets
npm run build
```

## 🔍 Testing Deployment

1. **Access the deployed URL**
2. **Test login with default accounts:**
    - Admin: admin@example.com / password
    - Customer: customer@example.com / password
3. **Create test ticket**
4. **Test real-time chat**
5. **Verify all CRUD operations**

## 🚨 Troubleshooting

### Common Issues:

1. **500 Error:** Check logs, ensure APP_KEY is set
2. **Database Connection:** Verify DB credentials
3. **Real-time not working:** Check Pusher configuration
4. **Assets not loading:** Run `npm run build`

### Debug Commands:

```bash
# Check logs
heroku logs --tail

# Run migrations
heroku run php artisan migrate

# Clear caches
heroku run php artisan cache:clear
```

## 📱 Mobile Responsiveness

The application is fully responsive and works on:

-   Desktop browsers
-   Tablets
-   Mobile devices
-   Progressive Web App capabilities

## 🎯 Post-Deployment

1. **Test all features thoroughly**
2. **Set up monitoring**
3. **Configure backups**
4. **Document admin procedures**
5. **Train users**

---

**Your Support Ticket System will be live and ready to handle customer support requests with real-time chat capabilities! 🎉**
