# Enterprise demo and test server

How to run the Enterprise tenant type on a demo or test server, for demos and for the
mobile team. Never point this at the live database.

## What it gives you

- The **Enterprise** tenant type (`TenantKind.ENTERPRISE`): every hostel module with
  residents called *employees* and guardians called *emergency contacts*. No role sees
  money, and online payments, the public page and guardian logins are off.
- The **TEPL DHMS modules**, all 25 BRD items. What each sprint added, the environment,
  the checks and the security changes: [release-candidate.md](release-candidate.md).
  The testers' brief: [vapt-scope.md](vapt-scope.md).
- `npm run seed:enterprise-demo`: the demo account.

## Moving the existing demo server from `tata-demo` to `enterprise`

The server still runs `tata-demo`, where this tenant type is called `EMPLOYEE`. Every
`tata-demo` migration is also on `enterprise`, so this is a normal update. The rename
migration `20261215090000_enterprise_tenant_kind` carries the existing tenant across.

Take a database snapshot first. Then, in the backend folder on the server:

```bash
git fetch origin
git checkout enterprise
git reset --hard origin/enterprise
npm ci --include=dev
npx prisma migrate deploy
npm run build
```

Add these to the server's `.env` if they aren't there:

```bash
# Generate with: openssl rand -base64 32
# Medical records and government ID numbers are sealed with this.
MEDICAL_ENCRYPTION_KEY=...
# Leave these at their defaults so the demo sends nothing real.
PUSH_PROVIDER=log
```

Restart, then reseed so the data has today's dates and every new field:

```bash
sudo pm2 restart hostelcare-api --update-env
DEMO_PASSWORD='choose-one' npm run seed:enterprise-demo -- --reset
```

If you keep old data instead of using `--reset`, run `npm run enterprise:harden-data` once.
It seals existing government ID numbers and clears old rents, deposits, fees, salaries and costs. Running it twice
changes nothing.

Web: build `hostelcare-frontend` branch `enterprise` with `VITE_API_BASE_URL` set to this
server, and publish it the way the demo site is already published.

Check it:

1. `GET /api/health` answers.
2. Sign in on the web as `admin@demo.example`. The tenant should read Enterprise, with no
   Expenses page or money anywhere.
3. Sign in as `employee1@demo.example` from a build of the mobile `enterprise` branch.
4. Try a mobile build from before Enterprise. It should get
   `ENTERPRISE_APP_UPDATE_REQUIRED`, not a broken screen.

## Pointing the mobile app at it

The `dev` flavour's address is in `lib/main_dev.dart`. If this server is not that address,
change it locally rather than committing it, or add the address to your own run config.

```bash
flutter run --flavor dev -t lib/main_dev.dart
```

Push notifications only reach a phone if the server sets `PUSH_PROVIDER=fcm` with a
Firebase key. Leave it on `log` unless you are testing the emergency alert on a real phone.

## Setting up a new server

```bash
npm ci --include=dev   # the build needs TypeScript and Prisma
npx prisma migrate deploy
npm run build          # makes dist/, which the seed and the server run from
DEMO_PASSWORD='choose-one' npm run seed:enterprise-demo
```

It creates **"Enterprise Demo Hostel"**: Block A and Block B, 120 beds, about 100 employees
with TEPL IDs, a month of leave and gate passes, repairs and complaints, visitors, notices,
the mess menu and meal counts, biometric punches and roll call, staff and custom roles.

The sign-ins are printed at the end: admin, wardens, canteen, security, plant approvers,
housekeeping, the OHC, leadership, EHS and three employees. Emails use `demo.example`,
which receives no mail, and mail and WhatsApp are log-only while the script runs.

The seed refuses a database that holds other tenants unless `ALLOW_DEMO_SEED=yes`. Don't
set that on anything with real data.

Run it again with `--reset` before each demo to start fresh with today's dates:

```bash
DEMO_PASSWORD='choose-one' npm run seed:enterprise-demo -- --reset
```

## For mobile developers

The sign-in rules, the fields that differ for Enterprise and the module list are in
[api-guide.md](api-guide.md) and [mobile-contract.md](mobile-contract.md).
