Frontend Architecture for Multi-Tenant SaaS: Theming, Permissions, and Routing

Suman SharmaSuman Sharma

Compliance platforms, B2B dashboards, and AI tools often serve many organisations (exporters, cooperatives, brands) from one codebase. The frontend has to feel tailored to each tenant without becoming a different app for each.

1. Resolve the tenant once

Options:

StrategyExampleNotes
Subdomainacme.app.comBranded, good cookie isolation
Pathapp.com/acmeSimplest
Custom domaincompliance.acme.comMost work: routing + TLS

Resolve the tenant in middleware or the root layout, then pass a tenant context down. Every data request includes the tenant, and the backend verifies the user belongs to it.

2. Theme with tokens

:root { --brand: 24 95% 53%; --brand-foreground: 0 0% 100%; }
<html style={{ "--brand": tenant.theme.brand } as React.CSSProperties}>

Components use bg-[hsl(var(--brand))] or a Tailwind theme mapped to variables, never hard-coded colours. This builds on a token-based design system.

3. Role-based UI

const can = (user: User, action: Action) => user.permissions.includes(action); {can(user, "plots:approve") && <ApproveButton />}
  • Centralise permission checks in one helper.
  • Hide what users can't do, but enforce on the server.

4. Feature flags per tenant

Tenants buy different plans or opt into betas. Use flags (tenant.features.includes("satellite-checks")) rather than branching code per customer name.

5. Isolation pitfalls

  • Caching: never cache tenant-specific data under a shared key. Include the tenant ID in cache keys and tags (Next.js caching).
  • Client state: clear stores when switching tenants.
  • Analytics: tag events with the tenant for debugging, but respect data agreements.

6. Test the matrix

Test at least: two tenants × two roles × feature flag on/off for critical flows.

Frequently asked questions

Subdomain or path for tenants?

Subdomains (acme.app.com) feel more branded and isolate cookies more easily. Paths (app.com/acme) are simpler to set up. Custom domains need extra infrastructure for routing and certificates.

Should permissions be enforced in the frontend?

The frontend should hide what users can't do for a better experience, but the backend must enforce permissions. Never rely on the UI for security.

How do I theme per tenant?

Store tenant brand tokens and apply them as CSS custom properties at the root, so components use variables rather than hard-coded colours.

Contact

Get in Touch

Want to call me? book a call and I'll respond in the available time slot. I will ignore all soliciting.