SkillAgentSearch skills...

multi-tenancy

Use when implementing tenant resolution, database or schema isolation, tenant-aware JPA, reactive tenant context, migrations, caching, jobs, or authorization in Spring Boot 3.

Install / Use

npx skills add rrezartprebreza/spring-boot-skills --skill multi-tenancy

Installs into whichever agent you are using.

About this skill
📄

SKILL.md

Installable skill definition

Quality Score

83/100

Category

Operations

Supported Platforms

Universal

Our assessment of multi-tenancy

multi-tenancy scores 83/100 on our quality scale, 614th of 745 Operations skills we index.

Its SKILL.md is 5.2 KB long, well organised into 9 sections with 1 code example: a solid amount of guidance for an agent.

It has 334 GitHub stars, a meaningful sign that others use it.

Substance
26/30
Structure
17/20
Description
15/15
Adoption
11/20
Freshness
15/15

Maintenance, license and trust

  • The repository was last updated 18 days ago, so multi-tenancy is actively maintained.
  • It is released under the MIT license, a permissive license that allows use, modification and commercial use with attribution.
  • Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.

Safety scan

No issues found

Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful.

AI review by kimi-k2.7-code on 2026-11-12. Automated pattern scan on 2026-11-12. It catches known dangerous patterns, not every risk — read a skill before letting an agent act on it.

multi-tenancy compared with similar skills

All 4 of these similar skills score higher than multi-tenancy; compare them before choosing.

SkillScoreStarsUpdatedFormat
multi-tenancy (this skill)by rrezartprebreza8333418d agoSKILL.md
x402by browser-use100121.0k3d agoSKILL.md
algorithmic-artby anthropics100177.9k55d agoSKILL.md
pptxby anthropics100177.9k55d agoSKILL.md
designby nextlevelbuilder100149.0k6d agoSKILL.md

Frequently asked questions

How do I install multi-tenancy?
Run npx skills add rrezartprebreza/spring-boot-skills --skill multi-tenancy. The install tabs above show the steps for each supported agent.
Which AI agents does multi-tenancy work with?
It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
Is multi-tenancy safe to use?
Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful. It is MIT-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
Is multi-tenancy still maintained?
The repository was last updated 18 days ago, so multi-tenancy is actively maintained.

name: multi-tenancy description: > Use when implementing tenant resolution, database or schema isolation, tenant-aware JPA, reactive tenant context, migrations, caching, jobs, or authorization in Spring Boot 3.

Multi-Tenancy

Treat tenant identity as an authorization boundary, not a query convenience.

Choose an isolation model

  • Database per tenant: strongest isolation and highest operational cost.
  • Schema per tenant: strong logical isolation with shared infrastructure.
  • Shared schema with tenant_id: simplest operations, but every access path must enforce scope.
  • Document the selected model and prohibit repositories from bypassing it.

Resolve tenant identity

  • Derive the tenant from a verified token claim, trusted host mapping, or authenticated API key.
  • Reject missing, unknown, disabled, or conflicting tenant identifiers.
  • Never trust a public X-Tenant-Id header by itself.
  • Clear servlet thread-local context in finally; use Reactor Context for reactive flows.

Enforce isolation

  • Apply tenant selection before opening the persistence session or transaction.
  • Include tenant identity in unique constraints, cache keys, idempotency keys, and object storage paths.
  • Prevent cross-tenant joins and unrestricted administrative repositories.
  • Authorize support impersonation explicitly and audit every use.

Operations

  • Run migrations per database/schema with resumable progress and version reporting.
  • Propagate tenant identity into scheduled jobs, messages, and async tasks explicitly.
  • Limit noisy tenants with quotas and per-tenant observability using bounded identifiers.
  • Test negative cross-tenant access, not only successful tenant queries.

Examples

  • See examples/good-tenant-filter.java and examples/bad-tenant-filter.java.

Executable shared-schema example

The TenantOrderStore and schema implement tenant-scoped reads, creates, updates and deletes. This example uses blocking JDBC, a verified resource-server JWT and an active-tenant registry. It is not a database/schema-routing or reactive implementation. Preserve the application's existing ID types and isolation model rather than copying this UUID model indiscriminately.

Wire TenantScopeFilter into the security chain before AuthorizationFilter (after bearer authentication and exception translation). Supply a RequestMatcher for only the tenant-protected routes and a server-side predicate checking the tenant registry. Instantiate the filter inside the chain configuration, or disable its servlet auto-registration if it is a bean, so it does not run twice. Missing authentication is 401; missing, disabled or unknown tenant membership is 403. Do not read a public tenant header.

The verified tenant_id claim must be issued under a trusted tenant-membership policy; where revocation must take effect before token expiry, consult current membership as well as the active-tenant registry. Background jobs must similarly re-authorize tenant activity/membership at execution time. A captured ID is context propagation, not perpetual authorization.

TenantContext scopes work with try/finally cleanup, preserves nested scopes and provides tenant-qualified cache keys:

TenantId tenant = TenantAccess.resolve(authentication, tenantRegistry::isActive);
try (var scope = TenantContext.open(tenant)) {
    store.find(orderId);
    String key = TenantContext.orderCacheKey(orderId);
    executor.execute(TenantContext.capture(() -> store.find(orderId)));
}

Open the tenant scope before invoking a separate transactional service proxy. The example does not propagate a transaction or SecurityContext to the worker; it starts its own unit of work. Do not use InheritableThreadLocal with pooled workers. Servlet async dispatches need explicit context propagation too. Scope every list, join and native query, and include tenant_id in child foreign keys. No Java repository wrapper protects against arbitrary unscoped SQL: restrict database credentials and consider PostgreSQL row-level security as defense in depth.

Verify same-ID records in two tenants, forbidden cross-tenant reads/updates/deletes, distinct cache keys, missing-context rejection, exception cleanup and sequential jobs on one worker.

Verification scope

The repository fixture targets Boot 3.5.16 with Java 17/21 and checks PostgreSQL 16 shared-schema access and blocking thread context; not Hibernate schema routing or Reactor. Check the coverage matrix before treating another minor version or an illustrative snippet as verified.

Gotchas

  • Agent trusts a tenant header supplied by the caller - derive tenant from authenticated context.
  • Agent forgets to clear a servlet ThreadLocal - pooled threads can leak one tenant into another request.
  • Agent scopes database queries but not cache keys - cached data can cross tenants.
  • Agent starts a transaction before selecting the tenant - routing may choose the wrong database.
  • Agent runs background jobs without tenant context - make tenant an explicit job parameter.

Related Skills

View on GitHub
GitHub Stars334
CategoryOperations
Updated18d ago
Forks54

Languages

Java

Trust signals

100/100

From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.

No cautions