Infrastructure high complexity Shared Component backendfrontendmobile
0
Dependencies
2
Dependents
13
Entities
0
Integrations

Description

Application-level tenancy scoping layer that intercepts every incoming API request and attaches the resolved tenant context derived from JWT claims (organization_id, role). Ensures all downstream service and repository calls are automatically filtered to the authenticated user's organizational scope, preventing cross-organization data leakage without requiring each service to manually implement filtering. Also provides Flutter BLoC state integration for passing the selected organization context as a header or path parameter on every mobile API request.

Feature: Multi-Organization Hierarchy Management

multi-tenancy-infrastructure

Responsibilities

  • Extract and validate organization_id and role from JWT claims on every request
  • Attach TenantContext to the request lifecycle for downstream use by all services
  • Provide Next.js middleware that enforces org-scoped data access in the admin panel
  • Expose tenant context to Flutter BLoC state so mobile passes org header on every call
  • Reject requests where the resolved tenant context does not match the requested resource's organization

Interfaces

resolveTenantContext(request: HttpRequest): TenantContext
withTenantScope<T>(ctx: TenantContext, fn: () => T): T
getTenantHeader(ctx: TenantContext): Record<string, string>
validateTenantAccess(ctx: TenantContext, resourceOrgId: string): boolean
createNextjsTenantMiddleware(): NextMiddleware
createFlutterTenantInterceptor(): DioInterceptor
injectTenantContext(orgId: string, roleId: string): TenantContext
getCurrentTenant(): TenantContext

Relationships

Dependents (2)

Components that depend on this component