saas-multi-tenant
यह क्या करती है
यह टूल ऐसी applications बनाने में मदद करता है जहाँ कई customers (या 'tenants') एक ही database को सुरक्षित तरीके से साझा करते हैं। यह सुनिश्चित करता है कि हर customer सिर्फ अपना data देखे।
कब इस्तेमाल करें
- ✓जब आप कई customers के लिए SaaS application बना रहे हों।
- ✓जब आपको हर customer का data अलग रखना हो।
- ✓जब security चाहिए ताकि customers एक-दूसरे का data न देख सकें।
Skill का लिंक
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/saas-multi-tenant/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मैं अपनी SaaS app में यह कैसे सुनिश्चित करूँ कि एक customer का data दूसरे customer को न दिखे?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह database को इस तरह सेट करता है कि हर table में customer ID वाला column जुड़ जाए, और security rules के ज़रिए data अपने आप filter हो। यह एक 'middleware' भी बनाता है जो हर request पर तय करता है कि कौन सा customer data एक्सेस कर रहा है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
SaaS Multi-Tenant Architecture
When to Use This Skill
- The user is building a SaaS application where multiple customers share the same database
- The user asks about tenant isolation, row-level security, or data leakage prevention
- The user needs to scope every database query to a specific tenant without manual WHERE clauses
- The user asks about shared-schema vs schema-per-tenant vs database-per-tenant tradeoffs
- The user is implementing admin endpoints that must access data across tenants
- The user needs to add
tenant_idcolumns to an existing single-tenant application - The user asks about PostgreSQL RLS policies for tenant isolation
- The user is building tenant-aware middleware in Express, Fastify, or Next.js API routes
Do NOT use this skill when:
- The user is building a single-user application with no shared infrastructure
- The user asks about authentication only without tenant scoping (use an auth skill instead)
- The user needs general database schema design without multi-tenancy requirements
Core Workflow
Determine the tenancy model. Ask the user about their scale expectations and isolation requirements. For most SaaS apps under 1000 tenants, shared-schema with a
tenant_idcolumn on every table is the correct default. Schema-per-tenant adds operational overhead (migrations run N times). Database-per-tenant is only justified when tenants have regulatory data residency requirements.Add
tenant_idto every tenant-scoped table. The column must beNOT NULL, typeUUIDorTEXT, and included in every composite index. Never allow a tenant-scoped table to exist without this column — a missingtenant_idis a data leak waiting to happen.Set up PostgreSQL Row-Level Security (RLS). Create a policy on each tenant-scoped table that filters rows by
current_setting('app.current_tenant_id'). This acts as a database-level safety net — even if application code forgets a WHERE clause, RLS blocks cross-tenant reads.Build tenant-aware middleware. At the start of every request, extract the
tenant_idfrom the authenticated session or JWT claims. Set it on the database connection usingSET LOCAL app.current_tenant_id = '...'inside a transaction. Every subsequent query in that request inherits the tenant scope automatically.Scope all ORM queries by tenant. If using Prisma, apply a global middleware that injects
where: { tenantId }into everyfindMany,findFirst,update, anddeletecall. If using Drizzle, create a base query builder that includes the tenant filter. Never rely on developers remembering to add the filter manually.Handle tenant-aware migrations. Every new table migration must include
tenant_idas a column. Write a linting rule or CI check that rejects any migration creating a table withouttenant_idunless the table is explicitly marked as global (e.g.,plans,feature_flags).Build cross-tenant admin routes separately. Admin endpoints that aggregate data across tenants must bypass RLS explicitly using
SET LOCAL role = 'admin_bypass'or a dedicated database role. These routes must be protected by a separate admin authentication flow — never reuse tenant user sessions for admin access.Implement tenant provisioning. When a new customer signs up, create their tenant record, seed default data (roles, settings, onboarding state), and assign the founding user. Wrap this in a database transaction so partial provisioning never leaves orphan records.
Examples
Example 1: PostgreSQL RLS Policy for Tenant Isolation
-- Enable RLS on the table
ALTER TABLE projects ENABLE ROW LEVEL SECURITY;
ALTER TABLE projects FORCE ROW LEVEL SECURITY;
-- Policy: users can only see rows where tenant_id matches the session variable
CREATE POLICY tenant_isolation ON projects
USING (tenant_id = current_setting('app.current_tenant_id')::uuid);
-- Policy for INSERT: new rows must match the current tenant
CREATE POLICY tenant_insert ON projects
FOR INSERT
WITH CHECK (tenant_id = current_setting('app.current_tenant_id')::uuid);
Example 2: Express Middleware That Sets Tenant Context per Request
import { Pool } from "pg";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
async function tenantMiddleware(req, res, next) {
const tenantId = req.auth?.tenantId; // extracted from JWT during auth
if (!tenantId) return res.status(403).json({ error: "No tenant context" });
…
अक्सर पूछे जाने वाले सवाल
'tenant' क्या है?
'tenant' आपके SaaS application का एक अलग customer होता है। अगर 100 clients आपका software इस्तेमाल कर रहे हैं, तो आपके पास 100 tenants हैं।
shared database क्यों इस्तेमाल करें?
हर customer के लिए अलग database रखने की तुलना में यह सस्ता होता है और इसे संभालना आसान है, खासकर जब customers बहुत हों।
'row-level security' (RLS) क्या है?
यह database की security सुविधा है जो सुनिश्चित करती है कि हर user या customer सिर्फ उन rows (records) को देख या बदल सके जो उसके अपने हैं।
जानकारी
लेखक का मूल विवरण
Design and implement multi-tenant SaaS architectures with row-level security, tenant-scoped queries, shared-schema isolation, and safe cross-tenant admin patterns in PostgreSQL and TypeScript.
लोकप्रियता
- GitHub स्टार
- 48k
- रैंकिंग में स्थान
- #5655
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
00-andruia-consultant
48kआपके एजेंट को AI प्रोजेक्ट शुरू करने या उन्हें बेहतर बनाने में मदद करता है। यह code का विश्लेषण करता है, tools सुझाता है और स्पेनिश भाषा में action plan बनाता है।
007
48kआपका एजेंट security audit और threat modeling करता है। यह प्रोजेक्ट को हमलों और कमजोरियों से बचाने में काम आता है।
10-andruia-skill-smith
48kआपके एजेंट को AI tools बनाने या उन्हें बेहतर करने में मदद करता है। यह तय करता है कि tools कैसे काम करेंगे, documentation लिखता है और structure की जांच करता है।
20-andruia-niche-intelligence
48kआपका एजेंट किसी खास industry का summary बनाता है। भरोसेमंद स्रोतों की मदद से यह प्रोजेक्ट का संदर्भ, नियम, इस्तेमाल के तरीके और जोखिम समझने में मदद करता है।
मिलती-जुलती skills
api-connector-builder
280kयह आपके एजेंट को मौजूदा pattern के हिसाब से नए API connections बनाने देता है। जब बिना कोई नया तरीका बनाए एक और integration जोड़ना हो, तब इसका इस्तेमाल करें।
api-design
280kयह आपके एजेंट को best practices के हिसाब से REST APIs डिज़ाइन करने में मदद करता है। यह तय करने में काम आता है कि APIs आपस में कैसे बात करें, errors कैसे दिखें, और data को कैसे व्यवस्थित करें।
backend-patterns
280kआपके एजेंट को server-side architecture patterns और database optimization में मदद करता है। server पर चलने वाला code बनाने या review करने के लिए उपयोगी है।