<?xml version="1.0" encoding="UTF-8"?>
<mxfile host="eli.ai" agent="eli.ai diagram exporter" version="1">
  <diagram id="tenancy-and-rls-7eec09d7" name="Tenancy and RLS">
    <mxGraphModel dx="1600" dy="1200" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1600" pageHeight="1200" math="0" shadow="0">
      <root>
        <mxCell id="0"/>
        <object id="1" label="Tenancy and RLS" schemaVersion="1" diagramId="tenancy-and-rls-7eec09d7" canonicalAppearanceKey="tsx:src/app/(docs)/docs/architecture/page.tsx:TENANCY_CHART#1" sourceSha256="7eec09d714e2b4ff19bb93e99366904e9936f44b18dd2d17c224c0aba6710521" metadataPayloadSha256="da2480e4d98f4fa5d25c26125f94409e5db4b424d0a522a524c6351f676e9bb4" generationKey="77aeab53a3be9045a52a191e657dc411d0ae9666602c23439c13847f2faff56e" concepts="[&quot;Tenancy and RLS&quot;,&quot;Public overview diagrams&quot;,&quot;Tenancy &amp; security (load-bearing)&quot;,&quot;Architecture&quot;,&quot;Tenancy&quot;]" keywords="[&quot;queries run under RLS&quot;,&quot;workspace_id = app.workspace_id?&quot;,&quot;membership check (role)&quot;,&quot;zero rows (fail closed)&quot;,&quot;unset / mismatch&quot;,&quot;Request /w/:workspaceId/…&quot;,&quot;withWorkspace(workspaceId, fn)&quot;,&quot;transaction-local&quot;,&quot;policy&quot;,&quot;rows&quot;,&quot;match&quot;,&quot;requireWorkspaceAccess(workspaceId)&quot;]" application="{&quot;name&quot;:&quot;eli-ai&quot;,&quot;version&quot;:&quot;0.1.0&quot;}" packages="{&quot;mermaid&quot;:&quot;11.16.0&quot;,&quot;mermaidCli&quot;:&quot;11.16.0&quot;,&quot;playwright&quot;:&quot;1.62.1&quot;,&quot;playwrightCore&quot;:&quot;1.62.1&quot;,&quot;puppeteer&quot;:&quot;25.6.0&quot;,&quot;puppeteerCore&quot;:&quot;25.6.0&quot;}" environment="{&quot;architecture&quot;:&quot;x64&quot;,&quot;containerImage&quot;:&quot;playwright:v1.62.1-noble@sha256:c091b21d9fae78c76e85cd4356431e9b018402f172a214fc7d7a5e9a7e29d8ac+node:26.3.1-bookworm-slim@sha256:209558c3e5e40e8adff68959d3c2ba7cd73723e716d89196878a0c362fa1e109&quot;,&quot;node&quot;:&quot;v26.3.1&quot;,&quot;platform&quot;:&quot;linux&quot;,&quot;yarn&quot;:&quot;4.17.1&quot;}" renderer="{&quot;browser&quot;:{&quot;executableSha256&quot;:&quot;0b20b130e7edd9dd51873be867761295fe0cfad490c2b9a64f95bd3cfc08fa71&quot;,&quot;name&quot;:&quot;chromium&quot;,&quot;revision&quot;:&quot;1234&quot;,&quot;version&quot;:&quot;151.0.7922.34&quot;},&quot;font&quot;:{&quot;family&quot;:&quot;Eli Diagram Inter Variable&quot;,&quot;fileSha256&quot;:&quot;3100e775e8616cd2611beecfa23a4263d7037586789b43f035236a2e6fbd4c62&quot;,&quot;licenseSha256&quot;:&quot;3b0a5fca3d17942cde889069889dedbbbd075e9b599968c82a95f4d944e9b345&quot;},&quot;mermaidConfigSha256&quot;:&quot;68c10966fe84406ee626034d58bfabd555df9f65f691204b7c46db24038da101&quot;,&quot;themeCssSha256&quot;:&quot;c80287a78d80ad63d27bd5ca348b2ef9a7e2f44da289e436be6484ea28a1b033&quot;}" adapterVersions="{&quot;diagramGenerator&quot;:&quot;2&quot;,&quot;drawioFlowchart&quot;:&quot;1&quot;,&quot;drawioGantt&quot;:&quot;1&quot;,&quot;drawioSequence&quot;:&quot;1&quot;,&quot;drawioState&quot;:&quot;1&quot;}" mermaidType="flowchart" direction="TD" generatedAt="2026-08-12T23:42:46.846Z" mermaidSource="flowchart TD&#10;  Req[&quot;Request /w/:workspaceId/…&quot;] --&gt; Guard[&quot;requireWorkspaceAccess(workspaceId)&lt;br/&gt;membership check (role)&quot;]&#10;  Guard --&gt; WW[&quot;withWorkspace(workspaceId, fn)&quot;]&#10;  WW --&gt; SC[&quot;set_config(&apos;app.workspace_id&apos;, id, true)&lt;br/&gt;(transaction-local)&quot;]&#10;  SC --&gt; Q[&quot;queries run under RLS&quot;]&#10;  Q --&gt; Pol{&quot;policy:&lt;br/&gt;workspace_id = app.workspace_id?&quot;}&#10;  Pol --&gt;|match| Rows[&quot;rows&quot;]&#10;  Pol --&gt;|unset / mismatch| Zero[&quot;zero rows (fail closed)&quot;]">
          <mxCell parent="0"/>
        </object>
        <object id="n:Req" label="Request /w/:workspaceId/…" mermaidId="Req" mermaidShape="rectangle">
          <mxCell parent="1" vertex="1" style="fillColor=#ECECFF;fontColor=#333333;html=1;rounded=0;strokeColor=#9370DB;whiteSpace=wrap;">
            <mxGeometry x="59.007813" y="8" width="256" height="76" as="geometry"/>
          </mxCell>
        </object>
        <object id="n:Guard" label="requireWorkspaceAccess(workspaceId)membership check (role)" mermaidId="Guard" mermaidShape="rectangle">
          <mxCell parent="1" vertex="1" style="fillColor=#ECECFF;fontColor=#333333;html=1;rounded=0;strokeColor=#9370DB;whiteSpace=wrap;">
            <mxGeometry x="8" y="134" width="358.015625" height="76" as="geometry"/>
          </mxCell>
        </object>
        <object id="n:WW" label="withWorkspace(workspaceId, fn)" mermaidId="WW" mermaidShape="rectangle">
          <mxCell parent="1" vertex="1" style="fillColor=#ECECFF;fontColor=#333333;html=1;rounded=0;strokeColor=#9370DB;whiteSpace=wrap;">
            <mxGeometry x="44.679688" y="260" width="284.65625" height="76" as="geometry"/>
          </mxCell>
        </object>
        <object id="n:SC" label="set_config(&apos;app.workspace_id&apos;, id, true)(transaction-local)" mermaidId="SC" mermaidShape="rectangle">
          <mxCell parent="1" vertex="1" style="fillColor=#ECECFF;fontColor=#333333;html=1;rounded=0;strokeColor=#9370DB;whiteSpace=wrap;">
            <mxGeometry x="39.34375" y="386" width="295.328125" height="100" as="geometry"/>
          </mxCell>
        </object>
        <object id="n:Q" label="queries run under RLS" mermaidId="Q" mermaidShape="rectangle">
          <mxCell parent="1" vertex="1" style="fillColor=#ECECFF;fontColor=#333333;html=1;rounded=0;strokeColor=#9370DB;whiteSpace=wrap;">
            <mxGeometry x="74.742188" y="536" width="224.53125" height="52" as="geometry"/>
          </mxCell>
        </object>
        <object id="n:Pol" label="policy:workspace_id = app.workspace_id?" mermaidId="Pol" mermaidShape="diamond">
          <mxCell parent="1" vertex="1" style="fillColor=#ECECFF;fontColor=#333333;html=1;perimeter=rhombusPerimeter;shape=rhombus;strokeColor=#9370DB;whiteSpace=wrap;">
            <mxGeometry x="37.507813" y="638" width="300" height="300" as="geometry"/>
          </mxCell>
        </object>
        <object id="n:Rows" label="rows" mermaidId="Rows" mermaidShape="rectangle">
          <mxCell parent="1" vertex="1" style="fillColor=#ECECFF;fontColor=#333333;html=1;rounded=0;strokeColor=#9370DB;whiteSpace=wrap;">
            <mxGeometry x="36.640625" y="1012" width="92.609375" height="52" as="geometry"/>
          </mxCell>
        </object>
        <object id="n:Zero" label="zero rows (fail closed)" mermaidId="Zero" mermaidShape="rectangle">
          <mxCell parent="1" vertex="1" style="fillColor=#ECECFF;fontColor=#333333;html=1;rounded=0;strokeColor=#9370DB;whiteSpace=wrap;">
            <mxGeometry x="179.25" y="1012" width="223.640625" height="52" as="geometry"/>
          </mxCell>
        </object>
        <object id="e:L_Req_Guard_0" label="" mermaidId="L_Req_Guard_0" mermaidKind="relationship">
          <mxCell parent="1" source="n:Req" target="n:Guard" edge="1" style="edgeStyle=orthogonalEdgeStyle;endArrow=block;endFill=1;html=1;jettySize=auto;orthogonalLoop=1;rounded=0;strokeColor=#333333;">
            <mxGeometry relative="1" as="geometry">
              <mxPoint x="187.007813" y="84" as="sourcePoint"/>
              <mxPoint x="187.007813" y="134" as="targetPoint"/>
              <Array as="points">
                <mxPoint x="187.007813" y="109"/>
              </Array>
            </mxGeometry>
          </mxCell>
        </object>
        <object id="e:L_Guard_WW_0" label="" mermaidId="L_Guard_WW_0" mermaidKind="relationship">
          <mxCell parent="1" source="n:Guard" target="n:WW" edge="1" style="edgeStyle=orthogonalEdgeStyle;endArrow=block;endFill=1;html=1;jettySize=auto;orthogonalLoop=1;rounded=0;strokeColor=#333333;">
            <mxGeometry relative="1" as="geometry">
              <mxPoint x="187.007813" y="210" as="sourcePoint"/>
              <mxPoint x="187.007813" y="260" as="targetPoint"/>
              <Array as="points">
                <mxPoint x="187.007813" y="235"/>
              </Array>
            </mxGeometry>
          </mxCell>
        </object>
        <object id="e:L_WW_SC_0" label="" mermaidId="L_WW_SC_0" mermaidKind="relationship">
          <mxCell parent="1" source="n:WW" target="n:SC" edge="1" style="edgeStyle=orthogonalEdgeStyle;endArrow=block;endFill=1;html=1;jettySize=auto;orthogonalLoop=1;rounded=0;strokeColor=#333333;">
            <mxGeometry relative="1" as="geometry">
              <mxPoint x="187.007813" y="336" as="sourcePoint"/>
              <mxPoint x="187.007813" y="386" as="targetPoint"/>
              <Array as="points">
                <mxPoint x="187.007813" y="361"/>
              </Array>
            </mxGeometry>
          </mxCell>
        </object>
        <object id="e:L_SC_Q_0" label="" mermaidId="L_SC_Q_0" mermaidKind="relationship">
          <mxCell parent="1" source="n:SC" target="n:Q" edge="1" style="edgeStyle=orthogonalEdgeStyle;endArrow=block;endFill=1;html=1;jettySize=auto;orthogonalLoop=1;rounded=0;strokeColor=#333333;">
            <mxGeometry relative="1" as="geometry">
              <mxPoint x="187.007813" y="486" as="sourcePoint"/>
              <mxPoint x="187.007813" y="536" as="targetPoint"/>
              <Array as="points">
                <mxPoint x="187.007813" y="511"/>
              </Array>
            </mxGeometry>
          </mxCell>
        </object>
        <object id="e:L_Q_Pol_0" label="" mermaidId="L_Q_Pol_0" mermaidKind="relationship">
          <mxCell parent="1" source="n:Q" target="n:Pol" edge="1" style="edgeStyle=orthogonalEdgeStyle;endArrow=block;endFill=1;html=1;jettySize=auto;orthogonalLoop=1;rounded=0;strokeColor=#333333;">
            <mxGeometry relative="1" as="geometry">
              <mxPoint x="187.007813" y="588" as="sourcePoint"/>
              <mxPoint x="187.007813" y="638" as="targetPoint"/>
              <Array as="points">
                <mxPoint x="187.007813" y="613"/>
              </Array>
            </mxGeometry>
          </mxCell>
        </object>
        <object id="e:L_Pol_Rows_0" label="match" mermaidId="L_Pol_Rows_0" mermaidKind="relationship">
          <mxCell parent="1" source="n:Pol" target="n:Rows" edge="1" style="edgeStyle=orthogonalEdgeStyle;endArrow=block;endFill=1;html=1;jettySize=auto;orthogonalLoop=1;rounded=0;strokeColor=#333333;">
            <mxGeometry relative="1" as="geometry">
              <mxPoint x="133.378867" y="884.371054" as="sourcePoint"/>
              <mxPoint x="82.945313" y="1012" as="targetPoint"/>
              <Array as="points">
                <mxPoint x="82.945313" y="975"/>
              </Array>
            </mxGeometry>
          </mxCell>
        </object>
        <object id="e:L_Pol_Zero_0" label="unset / mismatch" mermaidId="L_Pol_Zero_0" mermaidKind="relationship">
          <mxCell parent="1" source="n:Pol" target="n:Zero" edge="1" style="edgeStyle=orthogonalEdgeStyle;endArrow=block;endFill=1;html=1;jettySize=auto;orthogonalLoop=1;rounded=0;strokeColor=#333333;">
            <mxGeometry relative="1" as="geometry">
              <mxPoint x="240.636758" y="884.371054" as="sourcePoint"/>
              <mxPoint x="291.070313" y="1012" as="targetPoint"/>
              <Array as="points">
                <mxPoint x="291.070313" y="975"/>
              </Array>
            </mxGeometry>
          </mxCell>
        </object>
      </root>
    </mxGraphModel>
  </diagram>
</mxfile>
