Multi-Tenancy Refactoring

Enforce tenantId propagation across API and database calls.

2|Updated Feb 3, 2026
One-click install
npx skills add https://github.com/stackconsult/RE-Engine --skill multi-tenancy-refactoring
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Multi-Tenancy Refactoring
Source: https://github.com/stackconsult/RE-Engine/tree/main/.agent/skills/multi-tenancy-refactor
Command: npx skills add https://github.com/stackconsult/RE-Engine --skill multi-tenancy-refactoring

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Systematic approach to adding tenant isolation to existing codebases by injecting and standardizing tenantId propagation across services and data operations.

Core Features & Use Cases

  • Parameter Order Consistency: standardizes tenantId placement across search, get, create, and update methods.
  • Refactoring Checklist: provides a concrete steps checklist to migrate code safely without regressions.
  • Common Patterns: API service, service method, and background job patterns to enforce multi-tenant discipline.
  • Error Prevention & Verification: outlines validation steps and type checks to prevent tenant leakage and misorders.
  • Architecture & Testing Guidance: covers tenancy architecture considerations and testing strategies for isolation.

Quick Start

Apply this skill to an existing API by adding tenantId to all data operations and wiring middleware for tenant resolution.

Frequently Asked Questions about Multi-Tenancy Refactoring

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add tenant isolation to an existing API without breaking current method signatures?

To add tenant isolation safely, you systematically inject and thread tenantId across all service methods and database calls. This refactoring approach standardizes parameter ordering for CRUD operations while adding validation checks to prevent data leakage.

What is the best way to enforce tenantId propagation across microservices?

The best way to enforce tenantId propagation is by standardizing its placement in API signatures and extracting it from requests via middleware. You then thread this tenantId through all downstream database calls to guarantee strict tenant data separation.

How do I prevent tenant data leakage when refactoring search methods with varying parameter orders?

You prevent tenant data leakage by standardizing parameter order consistency across search, get, create, and update methods. The refactoring process includes type checks and validation steps to guard against parameter misorders and ensure tenantId is always present.

Does this multi-tenancy refactoring approach provide a checklist for migrating code safely?

Yes, this multi-tenancy refactoring approach provides a concrete steps checklist to migrate code safely without regressions. It covers API service patterns, background job adjustments, and testing strategies to verify strict isolation.

Why do I need to validate parameter order when adding tenantId to existing CRUD operations?

Validating parameter order is necessary because existing CRUD and search methods often vary in their parameter ordering. Standardizing tenantId placement and verifying it through type checks prevents misuses that could accidentally expose or mix data across tenants.

What testing strategies should I use to verify tenant isolation after refactoring?

To verify tenant isolation after refactoring, you should implement testing strategies that validate strict data separation across tenants. This includes checking that tenantId is correctly propagated through all service and database calls to prevent leakage.