Skip to content

Framework Adapters ​

TenantScale provides framework-specific adapters that wrap the core SDK into idiomatic middleware for your web framework. Each adapter gives you drop-in tenant isolation, API key authentication, plan enforcement, and rate limiting — without changing your application logic.

Available Adapters ​

PackageFrameworkStatusNPM
@tenantscale/expressExpress.js✅ Stablenpm
@tenantscale/fastifyFastify✅ Stablenpm
@tenantscale/honoHono✅ Stablenpm
@tenantscale/koaKoa✅ Stablenpm
@tenantscale/nextNext.js (App Router)✅ Stablenpm
@tenantscale/reactReact / Next.js (Client)✅ Stablenpm

ORM Adapters ​

PackageStatus
@tenantscale/drizzle✅ Stable

Feature Comparison ​

FeatureExpressHonoNext.jsReact
Middleware styleapp.use()app.use()withTenant() HOFProvider + Hooks
Tenant accessreq.tenantc.get('tenant')req.tenantuseTenant()
API key authentication✅✅✅❌ (server-side)
Scope-based authorization✅✅✅❌ (server-side)
Plan feature enforcement✅✅✅usePlan() (read)
Plan limit enforcement✅✅✅❌ (server-side)
Rate limiting✅✅✅❌ (server-side)
Client-side rendering❌❌❌✅
Server-side renderingN/AN/A✅✅
TypeScript generics✅✅✅✅
Custom error handling✅✅✅N/A

Architecture Overview ​

Each server adapter follows the same request lifecycle:

Incoming Request
       │
       ▼
┌──────────────────────┐
│  authenticateApiKey  │  → Resolves tenant from API key
│  (or requireScope)   │  → Validates scopes
└──────────┬───────────┘
           ▼
┌──────────────────────┐
│  requirePlanFeature  │  → Checks plan has required feature
└──────────┬───────────┘
           ▼
┌──────────────────────┐
│  requirePlanLimit    │  → Checks usage within plan limits
└──────────┬───────────┘
           ▼
┌──────────────────────┐
│  rateLimitByApiKey   │  → Applies rate limits per API key
│  (or rateLimitByIp)  │  → Applies rate limits per IP
└──────────┬───────────┘
           ▼
┌──────────────────────┐
│   Your Route Handler │  → req.tenant / c.get('tenant') available
└──────────────────────┘

All adapters share the same core SDK under the hood, so behavior is consistent across frameworks. Choose the adapter that matches your stack.

AdapterDocumentationSource
ExpressExpress Adapter →GitHub
FastifyFastify Adapter →GitHub
HonoHono Adapter →GitHub
KoaKoa Adapter →GitHub
Next.jsNext.js Adapter →GitHub
ReactReact Adapter →GitHub
DrizzleDrizzle Adapter →GitHub

Installation (Quick Reference) ​

bash
# Express
npm install @tenantscale/express

# Fastify
npm install @tenantscale/fastify

# Hono
npm install @tenantscale/hono

# Koa
npm install @tenantscale/koa

# Next.js
npm install @tenantscale/next

# React
npm install @tenantscale/react

# ORM adapters
npm install @tenantscale/drizzle

All adapters require the core SDK (@tenantscale/sdk) as a peer dependency. If it is not already installed, npm will install it automatically.

Shared Concepts ​

Tenant Resolution ​

All server adapters resolve the tenant from an API key sent in the Authorization header:

Authorization: Bearer tsk_live_abc123def456

The adapter extracts the key, looks up the associated tenant, and makes the tenant object available on the request context.

Tenant Object Shape ​

typescript
interface Tenant {
  id: string;
  name: string;
  slug: string;
  plan: Plan;
  features: string[];
  limits: Record<string, number>;
  usage: Record<string, number>;
  metadata?: Record<string, unknown>;
}

Error Handling ​

Server adapters throw typed errors that can be caught by framework-specific error handlers:

ErrorHTTP StatusDescription
InvalidApiKeyError401API key is missing, malformed, or revoked
InsufficientScopeError403API key lacks required scope
PlanLimitExceededError403Usage exceeds plan limit
RateLimitExceededError429Too many requests

Source: github.com/TenantScale/sdk/tree/main/packages

Released under the MIT License (SDK) and BSL 1.1 (API).