Multi-tenancy does not always belong at the root of an application.
A production API may have routes such as:
/health /status /metrics
Enter fullscreen mode
Exit fullscreen mode
that should remain independent from tenant resolution, while application routes such as:
/users /orders /projects
Enter fullscreen mode
Exit fullscreen mode
need a tenant-aware execution boundary.
Fastify's plugin encapsulation makes this separation surprisingly natural.
While building the Fastify framework track for Ambiten, I ended up with a pattern that expresses this boundary directly in the application structure.
import Fastify from " fastify " ; import { createFastifyAdapter } from " @ambiten/adapter-fastify " ;
import { AmbitenContext , MultiTenantManager } from " @ambiten/core " ;
import { registerDemoTenants } from " ./core/tenancy " ;
export function buildApp ( logger = false ) { registerDemoTenants ();
const app = Fastify ({ logger });
// This route lives outside the // tenant-protected child plugin. app .…