شعار Multi Tenancy

Multi Tenancy

المجتمع
MartinOlivero
multi-tenancy

استخدم هذه المهارة عندما يتشارك عدة عملاء أو مؤسسات أو فرق أو مساحات عمل تطبيقًا واحدًا، مع ضرورة فصل بياناتهم، وخصوصًا عندما يمكن للشخص الانتماء إلى أكثر من جهة منها. تتضمن عبارات التفعيل (بالإنجليزية): «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». وتتضمن عبارات التفعيل (بالإسبانية): «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». تحدد المهارة نموذج العضوية قبل تثبيت المخطط، وتضع قاعدة المستأجر في مكان واحد، وتعالج الحالات التي قد تؤدي إلى تسرب البيانات، مثل وظائف الخادم والحذف والدعوات والحساب التجريبي المشترك. استخدم `data-modeling` للمخطط نفسه و`rls-audit` للتحقق من السياسات.

Add to TypingMind

نظرة عامة

الناشرMartinOlivero
المستودعsaas-builder
اسم المهارةmulti-tenancy
النجوم
4
التفريعات
2
الملفات المرفقة
1
الترخيصMIT
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • الملفات المرفقة: 1

    نصوص برمجية وقوالب ومراجع يمكن للنموذج قراءتها أثناء عمله. الملفات للقراءة فقط ولا تُنفّذ أبدًا.

  • مفتوحة المصدر

    نشرها MartinOlivero على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Multi Tenancy في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى «الإضافات» ثم «المهارات».
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/MartinOlivero/saas-builder/tree/main/skills/multi-tenancy
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات ← المهارات ← إضافة مهارة ← من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

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
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Multi Tenancy في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج مهارة Multi Tenancy تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Multi Tenancy بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تستهلك تعليمات المهارة أي توكنات ما دامت المهارة غير مستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

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.

الملفات المرفقة

يقرأ النموذج هذه الملفات عند الحاجة ما دامت المهارة محمّلة. وهي متاحة للقراءة ولا تُنفّذ أبدًا.

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Multi Tenancy؟

استخدم هذه المهارة عندما يتشارك عدة عملاء أو مؤسسات أو فرق أو مساحات عمل تطبيقًا واحدًا، مع ضرورة فصل بياناتهم، وخصوصًا عندما يمكن للشخص الانتماء إلى أكثر من جهة منها. تتضمن عبارات التفعيل (بالإنجليزية): «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». وتتضمن عبارات التفعيل (بالإسبانية): «multi-tenant» و«varias empresas en la misma app» و«organizaciones y miembros» و«invitar usuarios» و«un usuario en dos empresas» و«cam...

لماذا تستخدم Multi Tenancy على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Multi Tenancy عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Multi Tenancy في TypingMind؟

في TypingMind، افتح «الإضافات»، ثم «المهارات»، ثم اختر «التثبيت من GitHub» والصق https://github.com/MartinOlivero/saas-builder/tree/main/skills/multi-tenancy. يقرأ TypingMind ملف SKILL.md الخاص بالمهارة، ويجمع ملفاتها ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Multi Tenancy؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Multi Tenancy؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Multi Tenancy معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Multi Tenancy مجانية؟

نعم. نشرها MartinOlivero على GitHub بموجب ترخيص MIT. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا الإخبارية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇