← ClaudeAtlas

multitenancylisted

Multi-tenant architecture patterns. Database-per-tenant, schema-per-tenant, shared-schema with tenant ID, row-level security, tenant resolution, and data isolation. USE WHEN: user mentions "multi-tenant", "multitenancy", "SaaS architecture", "tenant isolation", "row-level security", "tenant ID", "subdomain routing" DO NOT USE FOR: general database design - use database skills; authentication - use auth skills
claude-dev-suite/claude-dev-suite · ★ 33 · AI & Automation · score 80
Install: claude install-skill claude-dev-suite/claude-dev-suite
# Multi-Tenant Architecture ## Isolation Strategies | Strategy | Isolation | Complexity | Cost | |----------|-----------|------------|------| | Database per tenant | Highest | High | High | | Schema per tenant | High | Medium | Medium | | Shared schema (tenant_id column) | Medium | Low | Low | | Row-level security (RLS) | Medium-High | Medium | Low | ## Shared Schema with Tenant ID (most common) ```typescript // Middleware: resolve tenant from subdomain or header function tenantMiddleware(req: Request, res: Response, next: NextFunction) { const host = req.hostname; // acme.myapp.com const subdomain = host.split('.')[0]; const tenant = await tenantRepo.findBySubdomain(subdomain); if (!tenant) return res.status(404).json({ error: 'Tenant not found' }); req.tenantId = tenant.id; next(); } // Always filter by tenant app.get('/api/products', async (req, res) => { const products = await db.product.findMany({ where: { tenantId: req.tenantId }, }); res.json(products); }); ``` ### Prisma with Tenant Scoping ```typescript // Extension to auto-apply tenant filter const prisma = new PrismaClient().$extends({ query: { $allOperations({ args, query, operation }) { if (['findMany', 'findFirst', 'count', 'updateMany', 'deleteMany'].includes(operation)) { args.where = { ...args.where, tenantId: getCurrentTenantId() }; } if (['create', 'createMany'].includes(operation)) { args.data = { ...args.data, tenantId: getCurrentTenantI