# Government Integration Architecture

Frontend:
- `admin/government_integrations.php`

Backend:
- `api/admin/government_integrations.php`
- `api/admin/government/country_resolver.php`
- `api/admin/government/crypto.php`

Country Packs:
- `api/admin/government/SA/config.php`
- `api/admin/government/SA/ShomoosAdapter.php`
- `api/admin/government/SA/NtmpAdapter.php`
- `api/admin/government/SA/ZatcaAdapter.php`

Database:
The backend automatically creates:
- `government_integrations`
- `government_integration_logs`

Multi-tenant rule:
The API always uses `$_SESSION['active_property_id']` and does not trust a property ID from the browser.

Adding a country:
1. Create a new country directory, e.g. `AE`.
2. Add `config.php`.
3. Add only that country's adapters/providers.
4. Add the country's aliases to `country_resolver.php`.
5. The same frontend page will display only that country's integrations.

Secrets:
Credentials are encrypted before storing. Prefer the environment variable:
`GOVERNMENT_INTEGRATION_KEY` (64 hex characters).
