Locations Domain
Technical design of multi-location hierarchy and data isolation
Overview
The locations domain is the foundation of multi-tenancy in Danvas. It allows a single team (Clerk Organization) to manage multiple physical restaurant locations with strictly isolated operational data.
Database Schema
Locations (locations)
The central entity for physical sites.
| Column | Type | Description |
|---|---|---|
id | text | Primary key (UUID) |
teamId | text | References teams.id (Clerk Org) |
slug | text | URL-friendly identifier |
name | text | Human-readable name |
timezone | text | IANA timezone (e.g., America/Chicago) |
brandColor | text | Custom UI color for the location |
Multi-location Logic
Active Location Resolution
The application uses a utility getActiveLocation() to determine which site the user is currently interacting with.
- Preference: The user's
primaryLocationIdin their profile. - Context: URL parameters or headers for specific requests.
- Fallback: The first location alphabetically assigned to the user.
Data Isolation
Isolation is enforced at the query level. Every table that stores location-specific data (reports, incidents, shifts) includes a locationId column.