Skip to content

Browser and privileged data paths

Toolora uses two application data paths. Ordinary company-internal reads and edits commonly use the Supabase browser client under row-level security (RLS). Portals, integrations and privileged transactions use FastAPI and services. A single workspace can use both paths because the operation determines the required boundary.

The browser uses a public client key and the user’s session. Server service-role queries bypass RLS and therefore require explicit identity, capability and resource admission. Neither path becomes safe merely because the frontend requested a tenant or hid a control.

flowchart TD
UI[Page and reusable hook] --> Choice{Operation boundary}
Choice --> Browser[Supabase browser client]
Browser --> Policy[SQL grants, RLS and constraints]
Choice --> API[FastAPI caller and route policy]
API --> Resource[Target resource admission]
Resource --> Service[Domain service or transaction RPC]
Policy --> State[(Application records)]
Service --> State
Service --> External[Provider adapter and outcome contract]
Both paths establish authority before changing the shared domain records.
Inspected operation Data path Owning checks
Office project/quote query Browser hook and PostgREST Company filter, query context and SQL grants/RLS
Quote creation without contextual opportunity Authenticated create_quote_with_thread RPC RPC authorization and atomic creation contract
Contextual quote creation or revisioned draft save API route and transaction RPC Caller capability, company/resource and transaction validation
Purchase-cost list versus allocation save RLS view read versus privileged API/RPC Staff/capability checks, invoice ownership, revision and source fingerprint
Customer project list/detail Safe API projection Exact live person/company admission plus publication and operation policy
Provider export or delivery Privileged service/adapter Domain authority, durable identity and operation-specific outcome recovery

An RPC is not automatically a privileged API operation. A browser can call an exposed function with its own token; the function’s grants and execution context determine what it can do. Conversely, a server may make several ordinary reads before invoking one atomic mutation. RLS and database transactions own the detailed execution distinctions.

Reusable hooks build tenant-aware cache keys and constrain queries. A successful mutation then invalidates the affected query families. Invalidation asks the UI to read again; it does not commit a business transaction or prove that a provider completed an action.

The purchase-cost hook demonstrates the split: a queue can read v_purchase_cost_queue under RLS, while saving allocations submits expected_revision, basis_fingerprint and reviewed rows to the API. The API establishes principal staff, capabilities, invoice/company and active actor before calling save_purchase_cost_allocations.

Customer portals intentionally consume safe API projections rather than internal project rows through RLS. The selected internal company is not substituted for the customer resource’s admitted company/person pair. Portal scope explains that user-facing boundary.

Example: authorized action on a foreign record

Section titled “Example: authorized action on a foreign record”

A synthetic staff user can hold the required invoice capabilities in Company A and still be denied when submitting Company B’s invoice ID. The API’s tenant-scoped invoice lookup stops before the allocation RPC. An identical-looking browser button or cache key cannot authorize B’s record.

For a direct RLS operation, the same safety question belongs to the actual policy and function execution context. An empty result may represent a filtered row rather than absence from the whole system; the client must not respond by retrying through service-role access.

The inspected hooks and routes establish these representative paths. The endpoint policy catalogue names routes; it does not prove resource checks inside every implementation. Deterministic tests can establish ordered refusal with substituted clients, while real RLS and token behaviour require the local-stack suites. This article does not replace either with an architectural diagram.

See frontend mutations, API policy and integration recovery for the corresponding operation contracts.