AMS Docs
Docs / Multi-Tenancy

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:

MethodURL PatternExampleUse Case
Subdomain{slug}.ams.hkus1.s4s.hostpasha.ams.hkus1.s4s.hostDefault for all tenants. No DNS setup needed.
Path Prefixams.hkus1.s4s.host/tenant/{slug}/ams.hkus1.s4s.host/tenant/pasha/Shared-IP environments, no wildcard DNS.
Custom Domain{your-domain.com}members.pasha.orgWhite-label deployments. Requires CNAME setup.
โ„น๏ธ Priority OrderCustom domain is checked first, then subdomain, then path prefix. If none matches, the request returns 404.

Data Isolation

Tenant isolation is enforced at multiple layers:

๐Ÿšจ Never Share API TokensAPI tokens are tenant-scoped at creation time. Sharing a token from one tenant with another integration will result in 403 Forbidden errors, not data leakage โ€” but it is still a security bad practice.

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:

dns โ€” 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

bash โ€” Register custom domain
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"}'
json โ€” Response
{
  "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:

bash โ€” Check domain status
curl https://pasha.ams.hkus1.s4s.host/api/v1/admin/tenant/domain \
  -H "Authorization: Bearer $ADMIN_TOKEN"
โš ๏ธ Root Domain LimitationRoot domains (e.g. 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:

ElementWhere to ConfigureNotes
LogoSettings โ†’ Branding โ†’ LogoPNG/SVG, shown in navbar and emails
FaviconSettings โ†’ Branding โ†’ Favicon32ร—32px ICO or PNG
Primary colourSettings โ†’ Branding โ†’ ColoursHex value, used for buttons and links
Email sender nameSettings โ†’ Email โ†’ Sendere.g. "PASHA Membership Team"
Portal nameSettings โ†’ Organisation โ†’ Display NameShown in browser tab and emails
"Powered by AMS"Settings โ†’ Branding โ†’ FooterCan be hidden on Professional plan and above

How Tenant Resolution Works

php โ€” TenantResolver middleware
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);
    }
}