# saas-multi-tenant

Guides the agent in structuring multi-tenant SaaS backends with PostgreSQL and TypeScript. Sets up database row policies, request context middleware, and query filtering.

- skill · `type=skill` · Claude Code · 171 installs
- Author: davila7
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/davila7/claude-code-templates/tree/HEAD/cli-tool/components/skills/development/saas-multi-tenant
- Updated: 2026-10-24
- HTML: https://affpapa.org/en/nevibecode/skills/saas-multi-tenant

## What it does

The skill provides architectural workflows for isolating tenant data inside a single shared database. For workloads under 1000 accounts, it relies on adding a mandatory `tenant_id` column to every domain table and composite index. PostgreSQL Row-Level Security (RLS) policies act as the database safeguard, evaluating rows against a session setting.

At the framework layer, the skill covers middleware for Express and Next.js routes. The handler pulls the organization ID from incoming tokens and executes `set_config` in an active database transaction. It also creates interception logic for Prisma or Drizzle query builders to inject tenant criteria into read and write commands.

Cross-tenant administrative endpoints must execute under dedicated database credentials or bypass policies explicitly. Reusing standard customer sessions for management tooling creates dangerous permission leaks.

## Requirements
- Works with: PostgreSQL

## Install

### Claude Code (native platform)

1. **claude-code-templates**
```bash
npx claude-code-templates@latest --skill development/saas-multi-tenant
```

2. **Skills CLI (Vercel)**
```bash
npx skills add davila7/claude-code-templates --skill saas-multi-tenant -a claude-code
```

3. **Manually: put the files in place**
- File: `~/.claude/skills/saas-multi-tenant/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/saas-multi-tenant/

### Codex

**Manually: put the files in place**
- File: `.agents/skills/saas-multi-tenant/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

**Manually: put the files in place**
- File: `.cursor/skills/saas-multi-tenant/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install davila7/claude-code-templates saas-multi-tenant
```

2. **Manually: put the files in place**
- File: `.github/skills/saas-multi-tenant/SKILL.md`

### Gemini CLI

**Platform CLI**
```bash
gemini skills install https://github.com/davila7/claude-code-templates --path cli-tool/components/skills/development/saas-multi-tenant
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/saas-multi-tenant/SKILL.md` — The legacy .windsurf/skills/ path still works

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/davila7/claude-code-templates/tree/HEAD/cli-tool/components/skills/development/saas-multi-tenant

## When to use it
- isolate tenant records using PostgreSQL Row-Level Security policies
- bind tenant session context in database middleware per request
- inject tenant filters into Prisma and Drizzle ORM operations
- configure distinct routes for cross-account administrative operations
- enforce required tenant identifiers across database migration scripts

## Example prompts
- Write PostgreSQL RLS policies to isolate the projects table by tenant session ID
- Set up Express middleware that passes tenantId to Postgres via set_config in a transaction
- Configure a Prisma extension that automatically attaches tenantId to every query

## Similar
- [mcp-builder](https://affpapa.org/en/nevibecode/skills/mcp-builder.md) — skill · 130949 installs
- [claude-api](https://affpapa.org/en/nevibecode/skills/claude-api.md) — skill · 74198 installs
- [lark-im](https://affpapa.org/en/nevibecode/skills/lark-im.md) — skill · 472900 installs
- [lark-event](https://affpapa.org/en/nevibecode/skills/lark-event.md) — skill · 466800 installs
- [caveman-discover](https://affpapa.org/en/nevibecode/skills/caveman-discover.md) — skill · 104400 installs
- [migration](https://affpapa.org/en/nevibecode/skills/migration.md) — skill · 103900 installs

From the same set: [davila7/claude-code-templates](https://affpapa.org/en/nevibecode/by/davila7/claude-code-templates.md) — 804 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
