# El Captain ERP — Rebranding & Deployment Plan

## Overview

El Captain is a white-label sports/social club ERP, forked from the "نادي النادي" (THE CLUB Sheraton) system. This instance serves as the **demo link** given to all prospective clients to try before buying.

---

## Architecture

```
┌─────────────────────────────────────────────────────────┐
│  GitLab (gitlab.caprover.al-arcade.com/root/el-captain) │
│  Push to main → triggers CI/CD                          │
└──────────────────────────┬──────────────────────────────┘
                           │ .gitlab-ci.yml
                           ▼
┌─────────────────────────────────────────────────────────┐
│  CapRover (captain.al-arcade.com)                       │
│  App: el-captain                                        │
│  Dockerfile build → container restart                   │
└──────────────────────────┬──────────────────────────────┘
                           │
              ┌────────────┴────────────┐
              ▼                         ▼
┌──────────────────────┐  ┌──────────────────────────────┐
│  MySQL (same server) │  │  Apache + PHP 8.2 container  │
│  DB: el_captain_demo │  │  El Captain ERP app          │
└──────────────────────┘  └──────────────────────────────┘
```

---

## What Was Done

### 1. Repo Setup
- Copied clubphp codebase to `~/el-captain` (git remote: gitlab.caprover.al-arcade.com/root/el-captain)
- Excluded vendor, .git, sensitive files, temp data

### 2. Config Rebranding
- `config/app.php`: name_ar/name_en now read from `APP_NAME_AR` / `APP_NAME_EN` env vars (defaults: "الكابتن" / "El Captain")
- `config/database.php`: default DB name → `el_captain_demo`
- `.env`: fresh env file with El Captain defaults
- `Dockerfile`: updated env defaults, renamed php.ini conf

### 3. Code Rebranding (47 files processed)
- All hardcoded "نادي النادي شيراتون" / "THE CLUB Sheraton" replaced with dynamic config() or BrandingService calls
- Seed files updated with El Captain defaults
- SMS templates updated
- Layout/auth views use BrandingService dynamically
- Branch names (Sheraton/October/Capital) kept as geographic identifiers — these are physical locations, not brand names

### 4. Demo Data
- `Phase_99_001_seed_demo_data.php`: 15 fake members with subscriptions and receipts
- Admin credentials: `admin` / `ElCaptain2024`
- Data is seeded automatically on first boot via `docker/boot.php`

### 5. Deployment Pipeline
- `.gitlab-ci.yml`: pushes tarball to CapRover API on main branch push
- `captain-definition`: standard Dockerfile-based deploy
- `docker/entrypoint.sh`: writes .env from CapRover env vars, runs migrations + seeds

---

## Deployment Steps

### First Time (CapRover Setup)

1. **Create the app on CapRover:**
   - Go to captain.al-arcade.com → Apps → Create New App → `el-captain`
   - Enable HTTPS, set custom domain (e.g., `demo.elcaptain.com`)

2. **Create the database:**
   ```sql
   CREATE DATABASE el_captain_demo CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
   ```

3. **Set environment variables in CapRover app:**
   ```
   APP_URL=https://demo.elcaptain.com
   APP_DEBUG=false
   APP_ENV=production
   APP_NAME_AR=الكابتن
   APP_NAME_EN=El Captain
   DB_HOST=srv-captain--mysql-db
   DB_PORT=3306
   DB_NAME=el_captain_demo
   DB_USER=root
   DB_PASS=<password>
   ```

4. **Set GitLab CI/CD variables:**
   - `CAPROVER_URL`: `https://captain.al-arcade.com`
   - `CAPROVER_APP_TOKEN`: (generate from CapRover app deployment tab)
   - `CAPROVER_APP`: `el-captain`
   - `DEMO_URL`: `https://demo.elcaptain.com`

5. **Push to main** → CI/CD builds and deploys automatically

### Subsequent Deploys

Just push to `main`. The pipeline handles everything:
- Builds Docker image
- Pushes to CapRover
- Container starts → writes .env → waits for MySQL → runs migrations → seeds → Apache starts

---

## White-Label Strategy

The system is now fully white-label capable:

| Setting | Where it lives | How clients customize |
|---------|---------------|----------------------|
| Club name (AR/EN) | CapRover env vars + Settings UI | Admin → Settings → Branding |
| Logo | Settings UI → stored in DB (base64) | Admin → Settings → Branding |
| Carnet design | Settings UI → stored in DB (JSON) | Admin → Settings → Branding |
| Receipt design | Settings UI → stored in DB (JSON) | Admin → Settings → Branding |
| Colors/theme | Branding service | Admin → Settings → Branding |
| Branch names | Settings UI | Admin → Branches |
| Pricing | Business rules engine | Admin → Settings → Pricing |

### For Each New Client Deployment:
1. Create new CapRover app (e.g., `client-xyz`)
2. Create new DB (e.g., `client_xyz_erp`)
3. Set their env vars (APP_NAME_AR, APP_NAME_EN, DB_NAME)
4. Push same codebase → auto-migrates + seeds
5. Client logs in, uploads their logo, configures branding

---

## Remaining Work (Future)

- [ ] Custom domain setup per client
- [ ] Demo reset cron (daily reset demo data to fresh state)
- [ ] Landing page / marketing site for El Captain
- [ ] Remove club-specific modules that are too niche (if any)
- [ ] Multi-tenant option (single codebase, DB-per-tenant vs schema-per-tenant)
- [ ] Client onboarding wizard (first-login flow to set up branding)
- [ ] Pricing tiers (basic/pro/enterprise feature gating)

---

## Demo Credentials

| Field | Value |
|-------|-------|
| URL | https://demo.elcaptain.com (after deployment) |
| Username | `admin` |
| Password | `ElCaptain2024` |
