Logo di Multi Tenancy

Multi Tenancy

Community
MartinOlivero
multi-tenancy

Questa skill va usata quando più clienti, organizzazioni, team o aree di lavoro condividono un’applicazione, ma i loro dati devono rimanere separati, soprattutto se una persona può appartenere a più di uno di questi gruppi. Tra le frasi che la attivano (in inglese): «multi-tenant», «organizations and members», «workspaces», «teams», «invite users to an org», «a user in two companies», «switch workspace», «agency with several clients», «tenant isolation», «demo account», «white label». Tra le frasi che la attivano (in spagnolo): «multi-tenant», «varias empresas en la misma app», «organizaciones y miembros», «invitar usuarios», «un usuario en dos empresas», «cambiar de espacio», «cuenta demo», «que un cliente no vea los datos de otro». Definisce il modello di appartenenza prima che lo schema diventi difficile da modificare, centralizza le regole sui tenant e copre i punti in cui possono verificarsi fughe di dati: funzioni server, eliminazioni, inviti e demo condivisa. Usa `data-modeling` per lo schema e `rls-audit` per verificare le policy.

Add to TypingMind

Panoramica

Pubblicato daMartinOlivero
Repositorysaas-builder
Nome della skillmulti-tenancy
Stelle
4
Fork
2
File inclusi
1
LicenzaMIT
Link
  • Istruzioni in Markdown

    Un file SKILL.md che il modello carica quando serve, consumando token solo quando una richiesta è effettivamente pertinente.

  • Funziona con qualsiasi LLM

    Le skill IA sono in semplice Markdown, non in codice specifico di un fornitore, quindi funzionano con GPT, Claude, Gemini, Grok o un modello locale.

  • File inclusi: 1

    Script, template e riferimenti che il modello può leggere mentre lavora. I file sono di sola lettura e non vengono mai eseguiti.

  • Open source

    Pubblicata da MartinOlivero su GitHub. Leggi i sorgenti prima di installarla.

Installazione

Installa la skill IA Multi Tenancy in TypingMind per usarla con qualsiasi LLM, oppure copiala in un altro agente in grado di leggere SKILL.md.

1

Installa in TypingMind

TypingMind installa una skill direttamente dalla sua cartella GitHub: legge SKILL.md, raccoglie i file delle risorse e salva il risultato in locale.

  1. Apri l'app e vai su Plugin → Skill.
  2. Scegli "Installa da GitHub".
  3. Incolla l'URL della cartella della skill riportato qui sotto e conferma.
    https://github.com/MartinOlivero/saas-builder/tree/main/skills/multi-tenancy
  4. Attiva la skill in ogni chat in cui vuoi averla a disposizione.
Plugin → Skill → Aggiungi skill → Da URL GitHub, poi incolla l'URL della cartella e premi Continua.
2

Installa in un altro agente

Qualsiasi agente che legge il formato Agent Skills può usare questa skill: copia la cartella della skill nella directory delle skill di quell'agente.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/MartinOlivero/saas-builder.git /tmp/saas-builder
mkdir -p .claude/skills
cp -r /tmp/saas-builder/skills/multi-tenancy .claude/skills/multi-tenancy
Dopo la copia, riavvia Claude Code per caricare la nuova skill.

Usala in TypingMind

Attiva Multi Tenancy in qualsiasi chat di TypingMind e al resto pensa il modello. Il nome e la descrizione della skill sono nel prompt di sistema e, non appena arriva una richiesta pertinente, il modello carica da solo le istruzioni complete: non devi mai richiamarla manualmente e non consuma token finché non viene effettivamente usata.

Il modello carica automaticamente Multi Tenancy non appena riceve una richiesta pertinente.

Funziona con qualsiasi modello IA

Le skill IA sono semplici istruzioni in Markdown, non codice specifico di un fornitore, quindi Multi Tenancy non è vincolata al modello per cui è stata scritta. Installala una sola volta in TypingMind e usala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modello locale che esegui tu, sempre con le tue chiavi API.

  • Caricata solo quando serve

    Il prompt di sistema contiene solo il nome e la descrizione. Le istruzioni vengono recuperate alla prima richiesta pertinente, quindi una skill inutilizzata non costa nulla.

  • Cambia modello durante la chat

    Poiché la skill è composta da istruzioni e non da codice, continua a funzionare anche se cambi modello: il nuovo modello legge lo stesso file SKILL.md.

Istruzioni della skill

Questo è il contenuto di SKILL.md che il modello carica. Leggilo prima dell'installazione: una skill è un insieme di istruzioni che il tuo modello seguirà.

Multi-tenancy

Tenant isolation is one rule — "you only touch what belongs to an organization you are in" — that must hold in every query, every server function and every screen. This skill is about writing that rule once and about the places it is forgotten.

Analogy: an office building with several companies. The lobby is shared, each floor is private. The security model isn't a guard on every desk — it's one badge system that every door consults. The failures are never the front doors; they are the service elevator, the cleaning contractor with a master key, and the show floor left open for visitors.

Discovery (max 3 questions, only if unknown)

  1. Can one person ever belong to two organizations — a freelancer, an agency, a consultant, a founder with two companies?
  2. Who creates an organization — anyone who signs up, or only you?
  3. Is there a shared demo or sample account that strangers can enter?

Step 1 — Decide the membership model now

ModelShapeChoose when
Single-orgusers.org_idThe answer to question 1 is a certain, permanent no
Membershipsmemberships(user_id, org_id, role) + an active-org selectionAny doubt at all

Default to memberships. The single-org shortcut saves a table today. Converting later, in one production app, meant touching 39 of 56 policies, 21 functions and 33 files — and exposed the side effects in Step 4.

Step 2 — One choke point

Every policy and query asks one function for the caller's tenant — current_org_id() — instead of reading a column directly.

  • With memberships it returns the active organization, after checking the caller is really a member of it.
  • Because everything goes through it, changing the model later changes one function.
  • The role check lives beside it and filters by the caller's id. Never ask "is there an admin row?" — the first row returned belongs to someone.

Step 3 — "What I can see" is not "who is on the team"

These are two different questions, and conflating them is the commonest bug after a membership migration.

  • What I see follows my active organization.
  • Who is on the team is everyone with a membership in this organization, whatever they have open right now.

List teams from the memberships (a team view), never from a per-user "current org" field — otherwise a person working in their other company vanishes from user lists, assignment rules and public booking pages.

Step 4 — Shared people: decide each of these explicitly

Once a person can be in two organizations, each of these has a wrong default:

  • Deleting an organization must not delete its people. Check the ON DELETE of every foreign key between org and person.
  • "Remove user" removes a membership. The account is deleted only when the last one goes.
  • Profile fields (name, working hours, avatar) — can the admin of A edit them for someone shared with B? Usually: per-membership settings belong to the membership, identity belongs to the person.
  • Per-person integrations (a connected calendar, a personal API key): which organization's data do they sync into?
  • Revoked access: is the login disabled, or only the membership? Leaving the auth user alive keeps the password valid; re-inviting then collides with "email already exists".
  • Invitations: a link opened while signed in as someone else should say so, not bounce to the dashboard. And a failed read while accepting is an error — never "this user has no organization", which can move a person out of the one they had.

Step 5 — The service elevator: code that bypasses RLS

Anything running with a service key or as SECURITY DEFINER skips the policies. That code must apply the tenant rule itself:

  • Take the tenant from the verified session, never from the request body or a function parameter.
  • Add the tenant to every join and lookup inside it. A background job with the admin key that forgets one filter writes to another customer's client.
  • Enforce "same tenant" in the schema with composite foreign keys — (tenant_id, id) referenced as a pair — so a row cannot point at a parent in another tenant even when code forgets.
  • Use one server-side gate for "may this caller act here?" (active user, valid membership, current subscription). Then test that the server gate and the screen's own check agree for every role — two gates drift.

Step 6 — The front door: who can create a tenant

Closing the sign-up page does not close sign-up. If a function creates an organization, it can be called directly — in one app, three strangers created organizations the same day through social login after the registration screen had been removed.

  • Protect the function that creates the tenant, not the page that calls it.
  • Get notified on every new organization.

Step 7 — The show floor: a shared demo is a hostile tenant

A demo that visitors enter is an account controlled by strangers. Assume they will try every button and every API call.

  • Block spend: no paid AI calls, emails or messages from the demo.
  • Block writes that persist: no changing or disconnecting keys, no inserting or deleting shared records.
  • Enforce in the server and in the policies ("the organization is not the demo"), not by hiding buttons.
  • Fail closed: if the code cannot tell whether this is the demo, refuse.
  • No shared password in the bundle. Issue a personal link that expires.
  • Demo data ages. Seeded dates drift into the past; re-date them on a schedule, including derived columns the dashboards filter by.

Step 8 — Tenant settings that are easy to forget

  • Time zone is tenant (or user) data, and something must write it. A default nobody sets puts everyone in UTC: slots offered at five in the morning, two people seeing different times for the same appointment, day boundaries that cut off the evening.
  • Rate limits and quotas per tenant, especially on public endpoints where you cannot rely on the visitor's IP.

Handoff

Pass the membership model and the choke-point function to data-modeling (schema and indexes led by tenant_id), auth (roles), and rls-audit (verification from outside). Run rls-audit after any change to this model.

Output

Deliver: the membership decision with its reason, the tables, the current_org_id() function and role check, the team view, the explicit answer to each item in Step 4, the server gate, the tenant-creation guard, the demo restrictions if there is one, and the cross-tenant tests (user of A acting on B, through the API and through each server function).

Field notes

references/field-notes.md — the migration and the leaks these steps came from.

Reference

PostgreSQL docs (Row Security Policies, composite foreign keys), AWS "Multi-tenant data isolation with PostgreSQL Row Level Security", the multi-tenancy sections of your BaaS's documentation. Pairs with data-modeling, auth, rls-audit and secure-coding.

File inclusi

Il modello legge questi file quando servono, mentre la skill è caricata. Sono accessibili in sola lettura e non vengono mai eseguiti.

Domande frequenti

Cosa fa la skill IA Multi Tenancy?

Questa skill va usata quando più clienti, organizzazioni, team o aree di lavoro condividono un’applicazione, ma i loro dati devono rimanere separati, soprattutto se una persona può appartenere a più di uno di questi gruppi. Tra le frasi che la attivano (in inglese): «multi-tenant», «organizations and members», «workspaces», «teams», «invite users to an org», «a user in two companies», «switch workspace», «agency with several clients», «tenant isolation», «demo account», «white label». Tra le frasi che la attivano (in spagnolo): «multi-tenant», «varias empresas en la misma app», «organizacio...

Perché usare Multi Tenancy su TypingMind?

Perché la installi una volta e la usi con qualsiasi modello. Multi Tenancy è scritta in semplice Markdown anziché in codice specifico di un fornitore, quindi la stessa skill funziona con GPT-5, Claude, Gemini, Grok o un modello locale, e puoi cambiare modello durante la chat senza che la skill smetta di funzionare. TypingMind usa le tue chiavi API, quindi paghi direttamente i fornitori anziché un abbonamento per posto utente, e le tue skill e chat restano nel tuo spazio di archiviazione.

Come installo Multi Tenancy in TypingMind?

Apri Plugin → Skill → Installa da GitHub in TypingMind e incolla https://github.com/MartinOlivero/saas-builder/tree/main/skills/multi-tenancy. TypingMind legge il file SKILL.md, include i file associati e installa la skill, che puoi abilitare per ogni singola chat.

Quali modelli IA possono usare Multi Tenancy?

Qualsiasi modello che colleghi a TypingMind. Le skill IA sono semplici istruzioni in Markdown anziché codice specifico di un fornitore, quindi GPT, Claude, Gemini, Grok e i modelli locali possono tutti caricare questa skill quando una richiesta corrisponde al suo scopo.

Quanti modelli IA posso usare con Multi Tenancy?

Quanti ne vuoi. Se un modello supporta le skill, puoi usarlo con Multi Tenancy: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e molti altri, tutti su TypingMind con le tue chiavi API.

La skill IA Multi Tenancy è gratuita?

Sì. È pubblicata su GitHub da MartinOlivero con licenza MIT. Paghi solo il tuo fornitore IA per i token che usi.

Cosa sono le skill IA?

Una skill IA è un pacchetto di istruzioni riutilizzabili che insegna a un modello IA come svolgere un'attività specifica. Segue il formato aperto Agent Skills: un file SKILL.md con un nome e una descrizione, più eventuali script, template o file di riferimento di cui il modello potrebbe aver bisogno. Il modello legge le istruzioni solo quando la tua richiesta corrisponde alla skill, quindi una skill installata non comporta costi finché non viene usata.

In cosa si differenziano le skill IA dai plugin o dai server MCP?

Un plugin o un server MCP fornisce a un modello nuovi strumenti da richiamare: codice che viene eseguito da qualche parte e restituisce un risultato. Una skill IA, invece, fornisce al modello conoscenze e procedure: come affrontare un'attività, quali passaggi seguire e quali caratteristiche deve avere un buon output. Le skill sono semplici istruzioni in Markdown, quindi non richiedono server, chiavi API né ambienti di esecuzione e funzionano con qualsiasi modello.

Elenco completo

Crea subito il tuo spazio di lavoro AI

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇