multi-tenancy
Skill2 starsChanged 6 months agoMITView on GitHub
Use when an app has organizations/teams/workspaces — resolve the active tenant from the session or URL, scope every query to it, and guarantee one tenant can never read or write another's data.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- rrezartprebreza/spring-boot-skillstheir own version, first seen Aug 7, 2026
- Deadlymind/nanolamatheir own version, first seen Jul 16, 2026
- Iteam-company/claude-code-boilerplatestheir own version, first seen May 19, 2026
- YepAPI/skillstheir own version, first seen Apr 12, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- rrezartprebreza/spring-boot-skills★ 293same name
- YepAPI/skills★ 8same name
- Iteam-company/claude-code-boilerplates★ 2same name
- Deadlymind/nanolama★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- api-routes-and-validationSkill
- authenticationSkill
- authorization-rbacSkill
- background-jobsSkill
- data-access-layerSkill
- database-schemaSkill
- deployment-and-ciSkill
- environment-and-configSkill
- file-uploads-and-storageSkill
- observability-and-errorsSkill
- payments-stripeSkill
- project-scaffoldingSkill
- subscription-billingSkill
- transactional-emailSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 46
App layer (required): every DAL query filters by org_id (see data-access-layer).
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Multi-Tenancy
Overview
B2B SaaS is multi-tenant: users belong to organizations, and all data is owned by an org. The cardinal rule is isolation — no request may ever touch another tenant's rows. Use the shared-database, shared-schema model (an org_id column on every tenant table) and enforce scoping in one place: resolve the active org from the session, verify membership, and pass orgId into the data-access layer.
When to use
- The app has teams, workspaces, or organizations.
- A user can belong to more than one org and switch between them.
- You're writing any query against tenant-owned data.
Resolving the active org
// src/server/auth/active-org.ts
import "server-only";
import { and, eq } from "drizzle-orm";
import { db } from "@/server/db/client";
import { memberships, organizations } from "@/server/db/schema";
import { requireSession } from "@/server/auth/require";
export async function requireOrg(slug: string) {
const session = await requireSession();
const [row] = await db
.select({ org: organizations, role: memberships.role })
.from(memberships)
.innerJoin(organizations, eq(memberships.orgId, organizations.id))
.where(and(eq(memberships.userId, session.user.id), eq(organizations.slug, slug)))
.limit(1);
if (!row) throw new Error("Not a member of this organization"); // 404/redirect
return { org: row.org, role: row.role, user: session.user };
}Route by org in the URL — /(app)/[org]/... — and call requireOrg(params.org) in the layout so membership is checked before anything renders.
Isolation strategies (defense in depth)
- App layer (required): every DAL query filters by
org_id(seedata-access-layer). - Database layer (strong): Postgres Row-Level Security with a
current_setting('app.org_id')policy, so even a buggy query can't cross tenants. - Never trust a client-supplied
orgId. Derive it from a verified membership, not a form field or header.
Pitfalls
- Resolving org from a request body/header — a user can forge it. Resolve from session + membership.
- A single missing
org_idfilter — one un-scoped query is a full cross-tenant breach. Centralize in the DAL. - Checking membership in the UI only — re-check on the server for every action and route.
- Global unique constraints that should be per-tenant — e.g. project name unique per org, not globally; use composite unique indexes.
- Leaking tenant existence — return 404, not 403, for orgs the user can't access.
Hand-off
A verified { org, role, user } for the request. Feed role into authorization-rbac and org.id into every data-access-layer call.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

