liveBook · Manning

Tenant scope

As explained in Crack Any Codebase with AI

A tenant scope is the application-level restriction that limits a database query to records belonging to the authorized customer or organization.

A tenant scope limits each database query to records owned by the authorized customer or organization. In a shared-table design, the application must apply that scope consistently; one missing condition can expose another tenant’s data. section 7.4

Proving the administrator’s tenant

A cancellation flow first reads User, Membership, and Team before touching the booking. Those checks establish that the administrator belongs to the correct organization; only then should the flow access the booking. section 7.4

Apply tenant scope through the data model and every query:

  • Tag rows through the ownership hierarchy, such as team belonging to a parent organization. section 7.4
  • Add the relevant tenant condition, such as WHERE teamId = ?, to every shared-table query. section 7.4
  • Treat omitted scope as a data-leak defect, not merely an incomplete filter. section 7.4
Figure 7.6 In a shared table, the application enforces tenant isolation by adding WHERE teamId = ? to every query. Forgetting this clause leaks one tenant's private data to another.

Trace how application-enforced WHERE conditions preserve isolation in a shared table. section 7.4

How Crack Any Codebase with AI covers it

How deep it goes
Explains row-level ownership, nested tenant hierarchies, query conditions, and the failure mode of omitted scope.
Examples
Uses User, Membership, Team, and booking reads plus a WHERE teamId = ? isolation condition.
What it assumes
Assumes familiarity with database queries and organizations, while establishing tenant ownership and validation through concrete tables.
What you can do after
Diagnose missing tenant predicates and verify authorization before allowing access to tenant-owned records.
How it connects
Connects multi-tenancy with shared-table databases, authorization, access control, and row-level isolation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Crack Any Codebase with AI. The section links point to the parts of the book it draws on.