# Phase 19 — Production infrastructure and integration automation

## Docker build and runtime topology
- Docker image now requires `composer.lock` and installs locked production dependencies; it no longer runs `composer update` during image build.
- Dedicated `app`, `nginx`, `mysql`, `queue` and `scheduler` services.
- Database-backed Laravel queue with worker restart after one hour.
- Laravel scheduler runs as a separate service.
- MySQL is on a private Docker network and is not published to the host.
- Nginx binds to loopback by default (`127.0.0.1:8080`) for placement behind an approved TLS reverse proxy.
- Container JSON logs have size/file rotation settings.
- API throttles: 120 requests/minute general API and 30 requests/minute patient/FHIR API, keyed by authenticated user or IP.
- Failed queue jobs are scheduled for pruning after 14 days.

## Required pre-deployment sequence
1. Generate a reviewed `composer.lock` using `scripts/generate-composer-lock.sh`.
2. Configure `.env` from `.env.example` with unique strong secrets, HTTPS `APP_URL`, `APP_KEY`, database passwords and optional integration credentials.
3. Run `scripts/deploy-staging.sh`.
4. Review migration status and create a backup before applying migrations.
5. Apply migrations explicitly: `docker compose exec app php artisan migrate --force`.
6. Seed only approved reference data and create the initial super-administrator using the documented setup command.
7. Run `scripts/http-smoke-test.sh https://your-staging-host`.
8. Execute role-based clinical, financial, privacy and interoperability acceptance tests.

The deployment script intentionally does not run migrations automatically.

## Queue and scheduler
- Queue service: `php artisan queue:work database --sleep=3 --tries=3 --timeout=90 --max-time=3600`.
- Scheduler service: `php artisan schedule:work`.
- Queue tables are introduced by migration `2026_01_01_000015_create_queue_tables.php`.
- Queue workers should be monitored and restarted during releases.
- No automated SMS or DHIS2 dispatch job is enabled; the respective outboxes remain explicit operator-controlled workflows.

## Backup and restore
- `scripts/backup.sh` produces encrypted compressed MySQL and `storage/app` backups.
- Encryption uses OpenSSL AES-256-CBC with PBKDF2 and 250,000 iterations; the passphrase is prompted interactively or supplied via `BACKUP_ENCRYPTION_PASSPHRASE` and should be stored separately from the host.
- SHA-256 checksum file is produced for off-host integrity verification.
- `scripts/restore.sh` requires `CONFIRM_DESTRUCTIVE_RESTORE=YES`, validates decryption/compression, enters maintenance mode, restores database and uploaded storage, and clears Laravel caches.
- Backups must be copied off-host and restore drills must be performed regularly. A successful backup command alone is not proof of recoverability.
- Storage and database backups must be handled as sensitive health information under the approved retention, encryption and access policy.

## Security and operations
- General and sensitive API rate limiters are configured.
- Keep TLS termination at a trusted reverse proxy; do not expose PHP-FPM or MySQL ports publicly.
- Store secrets in a managed secret store where possible; do not commit `.env`, backups or credentials.
- Configure external log aggregation, alerting, WAF, endpoint protection, vulnerability scanning, TLS certificates, firewall and database access monitoring before production.
- Run periodic restore tests and penetration tests.
- Define incident response, RPO/RTO, retention and disaster recovery with the LCDA.

## Important limitations
- `composer.lock` is still absent in the current source workspace; image build is intentionally blocked until it is generated and reviewed.
- Docker is unavailable in this build environment; image builds and multi-container runtime tests were not executed.
- The database queue worker is infrastructure only; integration and notification outboxes are not yet wired to automatic dispatch jobs.
- SMS and DHIS2 sends remain operator-controlled.
- Backups are encrypted, but key management, off-site replication, immutable storage and restore drills are operational responsibilities.
- API rate limits are initial defaults and require load/security testing and adjustment.
- No production certification or compliance approval is implied.
