# Sehat Sahoolat v1 — Local Bring-Up

This is the legacy Laravel 8 platform, booted locally in Docker for visual
touring. It does NOT serve real traffic — production lives at
`https://sehatsahoolat.com`. Use this stack only to walk through screens,
confirm bugs, and reference behaviour while v2 is built out.

## Bring it up

```bash
cd /Users/tariqmustafa/Desktop/sehat_sahoolat/web
docker compose -f docker-compose.v1.yml up -d --build

# First boot does composer install (~3 min) and imports the 8.6 MB SQL dump.
# Tail the app logs to watch progress:
docker compose -f docker-compose.v1.yml logs -f app
```

Once you see `apache2-foreground` in the logs (and the seeder reports six
test users created), the stack is ready.

- App URL : <http://localhost:8080>
- DB port : `3307` (host) → MariaDB 10.6 inside the container
- DB conn : `mysql://sehat:sehat_v1@127.0.0.1:3307/sehat_v1`

Tear down without losing the DB:
```bash
docker compose -f docker-compose.v1.yml down
```

Tear down AND wipe the DB volume (forces a re-import of `sehat_web.sql`):
```bash
docker compose -f docker-compose.v1.yml down -v
```

## Test credentials

All accounts are seeded by `database/seeders/V1TestAccountsSeeder.php` and
are safe to re-create on every boot.

| Role          | Email                  | Password    |
| ------------- | ---------------------- | ----------- |
| Admin         | `admin@v1.local`       | `AdminV1!`  |
| Doctor        | `doctor@v1.local`      | `DoctorV1!` |
| Patient       | `patient@v1.local`     | `PatientV1!`|
| Case Manager  | `casemgr@v1.local`     | `CaseV1!`   |
| Receptionist  | `recept@v1.local`      | `ReceptV1!` |
| Accountant    | `accountant@v1.local`  | `AccountV1!`|

Original production seed accounts (e.g. `admin@hms.com / 123456789`) also
exist in the imported dump but most have unknown / hashed-on-prod passwords;
prefer the v1.local accounts above.

## Port map (avoid v2 collisions)

| Service              | Port   |
| -------------------- | ------ |
| v2 backend           | 3000   |
| v2 web portals       | 3001 / 3002 / 3003 |
| v2 postgres          | 5433   |
| v2 redis             | 6380   |
| **v1 web (this)**    | **8080** |
| **v1 mariadb (this)**| **3307** |

## Troubleshooting

- **`Cannot connect to the Docker daemon`** — Docker Desktop isn't running.
  Open it from `/Applications`, wait for the whale icon to settle, retry.
- **Port already allocated (`8080` or `3307`)** — something else on your
  host is using that port. Stop it (`lsof -i :8080`) or edit
  `docker-compose.v1.yml` to map a different host port.
- **`Could not read ./composer.lock` / `Resource deadlock avoided`** — files
  in the project are macOS iCloud "dataless" placeholders. Materialize them
  by `cd`ing into the directory and running
  `find . -type f -exec dd if='{}' bs=1 count=1 of=/dev/null \; 2>/dev/null`
  (or open them all in Finder). Then `docker compose -f docker-compose.v1.yml restart app`.
- **SQL import errors on `CREATE TABLE` (charset / FK order)** — already
  handled by `docker/v1/00-pre.sql`, which prepends `SET NAMES utf8mb4` and
  disables `FOREIGN_KEY_CHECKS` before the dump runs. If you ever rebuild
  the SQL dump and FK errors return, confirm `00-pre.sql` is still mounted
  in `/docker-entrypoint-initdb.d/` (it must sort *before* `01-init.sql`).
- **`composer install` fails on PHP-version mismatch** — the entrypoint
  automatically retries with `--ignore-platform-reqs`. If both passes fail,
  run interactively: `docker compose -f docker-compose.v1.yml exec app composer install --ignore-platform-reqs`.
- **Login page renders but credentials rejected** — re-run the seeder:
  `docker compose -f docker-compose.v1.yml exec app php artisan db:seed --class=V1TestAccountsSeeder --force`.
- **Need a fresh APP_KEY** — `docker compose -f docker-compose.v1.yml exec app php artisan key:generate --show`
  then paste into `.env.v1` (line `APP_KEY=`).

## What's inside

- `web/docker-compose.v1.yml` — the two-service stack (app + db).
- `web/Dockerfile.v1` — PHP 8.0 + Apache + the PHP extensions Laravel needs.
- `web/entrypoint-v1.sh` — first-boot bootstrap (composer install, key gen,
  seeder, then Apache).
- `web/.env.v1` — local-only Laravel config; the entrypoint copies this over
  any existing `.env` in the container.
- `web/docker/v1/00-pre.sql` / `02-post.sql` — wrap the SQL import.
- `web/database/seeders/V1TestAccountsSeeder.php` — idempotent test-account
  seeder, role-aware (uses the `departments` table that v1 uses as Spatie's
  roles table).
- `sehat_web.sql` — the 8.6 MB phpMyAdmin export of production (191 tables).
