Multi-Tenancy Infrastructure
Component Detail
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.
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
Related Data Entities (13)
Data entities managed by this component
Activity
20 fields
core
Activity Type
13 fields
configuration
Badge
15 fields
configuration
Bufdir Report
20 fields
core
Course
20 fields
core
External Resource
13 fields
configuration
Integration
13 fields
external
Local Association
17 fields
core
Mentor Program Session
14 fields
core
Organization
14 fields
core
Organization Label
10 fields
configuration
Region
6 fields
core
Toolbox Card
13 fields
configuration