# 🚀 Production Deployment & Operations Playbook

## 1. System Requirements

| Component | Minimum Specification | Recommended Production |
|---|---|---|
| **Operating System** | Ubuntu 22.04 LTS / Debian 12 / Windows Server | Ubuntu 24.04 LTS |
| **PHP Runtime** | PHP 8.2 or 8.3 | PHP 8.3+ with `php-fpm` |
| **PHP Extensions** | `bcmath`, `ctype`, `curl`, `dom`, `fileinfo`, `json`, `mbstring`, `openssl`, `pdo_sqlite` / `pdo_mysql`, `tokenizer`, `xml`, `zip`, `gd` | OPcache enabled |
| **Database** | SQLite 3.35+ or MySQL 8.0+ | MySQL 8.0+ with daily automated dumps |
| **Node.js** | Node.js 20.x LTS | Node.js 22.x LTS with npm |
| **Web Server** | Nginx 1.22+ or Apache 2.4+ with HTTPS | Nginx with HTTP/2 and Brotli/Gzip |

---

## 2. Step-by-Step Production Deployment

### Step 1: Clone and Configure Environment
```bash
git clone git@github.com:mr-creative-hmh/hilal-medical-visits.git /var/www/hilal-medical-visits
cd /var/www/hilal-medical-visits

cp .env.example .env
nano .env
```

Ensure the following variables are set in `.env`:
```env
APP_NAME="Al-Hilal Medical Visits"
APP_ENV=production
APP_DEBUG=false
APP_URL=https://visits.alhilal.sy

DB_CONNECTION=sqlite
# Or for MySQL:
# DB_CONNECTION=mysql
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=hilal_visits
# DB_USERNAME=hilal_user
# DB_PASSWORD=your_secure_password
```

### Step 2: Install PHP & Node Dependencies
```bash
# Install optimized production PHP packages
composer install --no-dev --optimize-autoloader

# Generate application key
php artisan key:generate --force

# Install frontend dependencies and compile static assets
npm ci
npm run build
```

### Step 3: Run Migrations and Seed Master Data
```bash
# Run domain migrations
php artisan migrate --force

# Seed master production dataset (14 Govs, 202 Areas, 23 Specialties, 816 Doctors, 897 Pharmacies)
php artisan db:seed --force
```

### Step 4: Cache Configuration, Routes, and Views
```bash
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
```

### Step 5: Configure Storage Link and Permissions
```bash
php artisan storage:link
sudo chown -R www-data:www-data storage bootstrap/cache database
sudo chmod -R 775 storage bootstrap/cache database
```

---

## 3. Initial Administrative Credentials

After running `php artisan db:seed`, the primary Super Admin account is available immediately:

- **Login URL**: `https://your-domain.com/login`
- **Email**: `admin@alhilal.sy`
- **Password**: `password`
- **Phone**: `0911111111`
- **Role**: `Super Admin` (Nationwide privileges)

> [!IMPORTANT]
> Immediately log in and update the Super Admin password under `/settings/security` upon first deployment.

---

## 4. Maintenance & Routine Operations

### Automated Database Backup
Set up a daily cron job to backup the SQLite database or MySQL schema:

```bash
# For SQLite:
0 3 * * * cp /var/www/hilal-medical-visits/database/database.sqlite /var/backups/hilal/backup_$(date +\%Y\%m\%d).sqlite

# For MySQL:
0 3 * * * mysqldump -u hilal_user -p'password' hilal_visits | gzip > /var/backups/hilal/db_$(date +\%Y\%m\%d).sql.gz
```

### Clearing and Rebuilding Caches
When deploying updates or modifying templates:
```bash
php artisan optimize:clear
php artisan optimize
npm run build
```

### Health Check Endpoint
The platform provides a built-in health probe at `/up` for load balancers and monitoring agents (Uptime Kuma, Datadog, AWS Route53).
