Tenant-scoped request and PHI access
How every request resolves its tenant, binds the correct data plane, and returns only permitted, decrypted, audited PHI.
- 1An SPA request reaches nginx, which maps the request origin/subdomain to the tenant header
- 2OrgContextMiddleware resolves the tenant from subdomain, header and JWT and cross-validates them, returning a fail-closed 403 on mismatch
- 3It binds the tenant id, member role and permissions, the tenant data-plane database alias, and the PostgreSQL RLS session GUCs
- 4The DRF viewset gates the caller through the Redis-cached RBAC permission catalogue and phi_guard field-group checks
- 5The routed queryset executes under the bound alias with RLS, and encrypted PHI columns are decrypted with the per-tenant DEK
- 6The permissioned serializer drops out-of-scope fields and PHIAuditMiddleware records a fail-closed audit entry before the response returns



