Multi-Tenancy
How AMS serves hundreds of independent associations from a single platform โ with complete data isolation, custom domains, and white-labelling.
What is Multi-Tenancy?
Multi-tenancy means one software deployment serves multiple independent customers (called tenants). Each tenant has a completely private, isolated environment โ their data, settings, members, and files are never visible to or accessible by any other tenant.
AMS uses a shared database, shared schema approach: all tenants live in the same MySQL database, but every tenant-scoped table has a tenant_id column. A global query scope on the Laravel models automatically filters every query to the current tenant, making cross-tenant data leaks architecturally impossible at the ORM level.
3 Access Methods
Each tenant can be accessed in three ways. The access method is resolved by the Laravel middleware on every request:
| Method | URL Pattern | Example | Use Case |
|---|---|---|---|
| Subdomain | {slug}.ams.hkus1.s4s.host | pasha.ams.hkus1.s4s.host | Default for all tenants. No DNS setup needed. |
| Path Prefix | ams.hkus1.s4s.host/tenant/{slug}/ | ams.hkus1.s4s.host/tenant/pasha/ | Shared-IP environments, no wildcard DNS. |
| Custom Domain | {your-domain.com} | members.pasha.org | White-label deployments. Requires CNAME setup. |
Data Isolation
Tenant isolation is enforced at multiple layers:
- Database layer โ All queries include
WHERE tenant_id = ?automatically via Eloquent global scopes - File storage layer โ Files are stored under
/{tenant_id}/prefix in S3 or local storage - Cache layer โ All Redis cache keys are prefixed with
tenant:{id}: - Session layer โ Sessions are tied to a tenant; a session from tenant A cannot access tenant B
- API token layer โ API keys are created with a fixed tenant_id and cannot cross tenant boundaries
Setting Up a Subdomain
Every tenant automatically gets a subdomain at {slug}.ams.hkus1.s4s.host when they register. No configuration is required โ the wildcard DNS *.ams.hkus1.s4s.host and the Nginx wildcard server block handle this automatically.
To change your subdomain slug, go to Settings โ Organisation โ Subdomain. Note: existing links using the old subdomain will stop working immediately.
Custom Domain Setup
To serve your portal at your own domain (e.g. members.pasha.org), follow these steps:
Step 1 โ Add a CNAME record
In your DNS provider (Cloudflare, Route53, GoDaddy, etc.), create a CNAME record:
Type: CNAME Name: members (or @ for root domain) Value: pasha.ams.hkus1.s4s.host TTL: 300 (5 minutes)
Step 2 โ Register the domain via API
curl -X POST https://pasha.ams.hkus1.s4s.host/api/v1/admin/tenant/domain \ -H "Authorization: Bearer $ADMIN_TOKEN" \ -H "Content-Type: application/json" \ -d '{"domain": "members.pasha.org"}'
{
"domain": "members.pasha.org",
"status": "pending_verification",
"ssl_status": "provisioning",
"verified_at": null,
"message": "DNS verification in progress. SSL will provision automatically within 15 minutes."
}
Step 3 โ SSL Auto-Provisioning
Once the CNAME is verified, AMS automatically provisions an SSL certificate via Let's Encrypt using the ACME protocol. This typically completes within 5โ15 minutes. You can check the status:
curl https://pasha.ams.hkus1.s4s.host/api/v1/admin/tenant/domain \
-H "Authorization: Bearer $ADMIN_TOKEN"
pasha.org without a subdomain) require ANAME/ALIAS DNS records. Not all DNS providers support this. We recommend using a subdomain like members.pasha.org.White-Labelling Options
With a custom domain, you can fully white-label the AMS portal so members never see "AMS" branding:
| Element | Where to Configure | Notes |
|---|---|---|
| Logo | Settings โ Branding โ Logo | PNG/SVG, shown in navbar and emails |
| Favicon | Settings โ Branding โ Favicon | 32ร32px ICO or PNG |
| Primary colour | Settings โ Branding โ Colours | Hex value, used for buttons and links |
| Email sender name | Settings โ Email โ Sender | e.g. "PASHA Membership Team" |
| Portal name | Settings โ Organisation โ Display Name | Shown in browser tab and emails |
| "Powered by AMS" | Settings โ Branding โ Footer | Can be hidden on Professional plan and above |
How Tenant Resolution Works
class TenantResolver { public function handle(Request $request, Closure $next) { // 1. Check custom domain first $tenant = Tenant::where('custom_domain', $request->getHost())->first(); // 2. Fall back to subdomain if (!$tenant) { $subdomain = explode('.', $request->getHost())[0]; $tenant = Tenant::where('subdomain', $subdomain)->first(); } // 3. Fall back to path prefix if (!$tenant && $request->segment(1) === 'tenant') { $tenant = Tenant::where('subdomain', $request->segment(2))->first(); } if (!$tenant) abort(404, 'Tenant not found'); app()->instance('tenant', $tenant); return $next($request); } }