# Repo Split Playbook (Drupal + Frontend)

Goal: keep production deploy simple (`git pull` on Drupal repo), while developing frontend in a dedicated repo (WebStorm), with a clean path to Next.js migration.

## Target structure

- `alemilani10` (Drupal repo, production source of truth)
  - contains Drupal code and only frontend build output in `web/react-app/dist`
- `alemilani-frontend` (frontend repo)
  - contains `react-app` source code and build tooling
  - produces `dist/` that is synced into Drupal repo

## Safety first

1. Commit or stash all current changes before split.
2. Create a full backup branch/tag in Drupal repo.
3. Keep production deployment unchanged until the split is fully validated.

## Phase 1: Extract frontend repo with history

Run in Drupal repo root:

```bash
./scripts/create-frontend-history-branch.sh frontend-history
```

Create frontend repo (example path next to current project):

```bash
cd ..
mkdir -p alemilani-frontend
cd alemilani-frontend
git init -b main
git pull ../alemilani10 frontend-history
```

At this point, `alemilani-frontend` contains the history of `react-app/` only.

## Phase 2: Make frontend repo self-contained

Inside `alemilani-frontend`, update webpack output to local `dist/` (not `../web/...`), then:

```bash
npm ci
npm run build
```

Expected output:

- `alemilani-frontend/dist/*`

## Phase 3: Keep only deployable frontend output in Drupal repo

In Drupal repo:

1. Stop tracking frontend source directory:

```bash
git rm -r --cached react-app
```

2. Ensure only deployable build path is tracked:

- track: `web/react-app/dist/**`
- do not track: `web/react-app/dist-stage/**`, `web/react-app/dist.zip`

3. Commit with a dedicated migration message.

## Phase 4: Day-to-day workflow

Frontend repo:

```bash
npm ci
npm run build
```

Sync output into Drupal repo:

```bash
/absolute/path/to/alemilani10/scripts/sync-react-dist.sh /absolute/path/to/alemilani-frontend
```

Then commit in Drupal repo:

```bash
git add web/react-app/dist
git commit -m "Update frontend dist"
git push
```

Production server:

```bash
git pull --ff-only
composer install --no-dev --optimize-autoloader
vendor/bin/drush updb -y
vendor/bin/drush cim -y
vendor/bin/drush cr
```

## Rollback

- Drupal code rollback: checkout previous commit/tag and redeploy.
- Frontend rollback: sync a previous `dist` commit from Drupal repo.
- Database rollback: from DB backup if a schema update caused issues.
