Skip to content

Spatial


title: Spatial internals description: How the Spatial domain is built: location hierarchy, tables, creation flows and change history. audience: internal type: explanation owner: platform-team last_reviewed: 2026-11-17


Internals of the Spatial domain. For the public API, see Spatial API.

Architecture

┌──────────────────────────────────────────────────────────────────┐
│                        Spatial Domain                            │
│                                                                  │
│   Venue (root)                                                   │
│   └── Building                                                   │
│       └── Floor                                                  │
│           └── Space ──── Endpoint ──── Device                   │
│                │              (physical mount)   (hardware)      │
│                │                                                  │
│           Zone (logical grouping of spaces)                      │
│                                                                  │
│   Venue ──── Establishment (tenant/operator inside a venue)      │
│          via venue_relationships                                  │
│                                                                  │
│   Location ──── Workspace (via workspace_locations)              │
│                                                                  │
│   [ Catalogue domain references Space ID via                     │
│     channel_space_assignments — read-only cross-domain link ]    │
└──────────────────────────────────────────────────────────────────┘

Request headers read by the flat routes:

Header Description
X-Organization-ID Required on most endpoints for tenant scoping
X-Workspace-ID Optional — filters location trees and device counts to a specific workspace
userId (via c.Locals) Required on create/assign operations

Data model

Location

The core entity. Represents any node in the physical hierarchy.

Field Type Notes
id string UUID
organizationId string Tenant scope
parentId *string Parent location in hierarchy
locationType LocationType venue / building / floor / space
name string Display name
shortName / code string Optional identifiers
status string Default Active
operatingHours OperatingHours JSON map by day of week
venueRole string property or establishment (for venue type only)
venueCategory string e.g. mall, airport
spaceType / placement string For space type only
isDOOHEnabled bool Whether space supports DOOH advertising
isDoohEnabled, avgDailyFootfall DOOH-specific fields
latitude / longitude float64 Geo coordinates

Hierarchy rules (enforced on create): - venue → root-level only (no parentId), unless venueRole = establishment which requires parentVenueId - building → parent must be venue - floor → parent must be building - space → parent must be floor

LocationTree / LocationGroupTree

Recursive tree response returned by /tree and /group-tree. Each node includes: - Aggregated deviceCount, onlineCount, offlineCount (rolled up from all children) - zones for space nodes (from zone_spaces join) - Full metadata fields in group-tree variant

Endpoint

A physical mount point inside a space where a device is installed.

Field Type Notes
spaceId string Must be a space-type location
deviceId *string Linked device (nullable = vacant)
status string Vacant (default) or Occupied
isMonetized bool Whether endpoint is monetized for DOOH

Zone

A logical grouping that aggregates multiple spaces, typically across one floor.

Field Type Notes
floorId *string Must reference a floor location
zoneCode string Short identifier
type string Zone category
status string Active by default

Spaces are linked to zones via zone_spaces join table.

Establishment

A tenant or operator that occupies space within a venue (legacy model, separate from location hierarchy).

Field Type Notes
venueId string Parent venue
contractRef string Contract reference number
type string Establishment category
status string Default Active

VenueType

A reference/lookup table for categorizing venue types (e.g. Mall, Hospital). System-wide, not org-scoped.

VenueRelationship

Links a property venue to an establishment venue with commercial terms.

Field Type Notes
propertyId string Parent property venue
establishmentId string Child establishment venue
commercialModel string e.g. revenue-share, lease
revenueSharePct *float64 Revenue share percentage
leaseStart / leaseEnd *string Contract date range

Tags

Labels that can be assigned to locations for filtering/categorization.

Field Type Notes
name string Tag label
colorCode string Hex color for UI display
category string Tag grouping

Linked to locations via location_tags join table (full replace on assign).


Zone-space assignment is not routed

The handlers HandleGetZoneSpaces, HandleAssignSpaceToZone and HandleRemoveSpaceFromZone exist but no route registers them, so the public API has no way to link a space to a zone.

Route registration

  • Flat routes (/locations, /endpoints, /hardware-assets, /establishments, /venue-types, /venues, /zones) are registered in domain/spatial/routes.go and read org and workspace from X-Organization-ID and X-Workspace-ID. The legacy scope guard covers them.
  • Target groups are mounted at /display-network/target-groups because /target-groups is taken by an older device-membership concept that reuses the same table.
  • Workspace-scoped routes (/venues/:ws/…) are in scoped.go. They verify the token and permission, overwrite the headers with verified values, and run the same handlers.
  • The catalogue live-control code resolves custom target groups only; derived space groups would need an import that cycles (spatial, provisioning, catalogue).

Key creation flows

1. Create the Location Hierarchy

# 1. Create a Venue (root)
POST /locations
  Body: { "name": "Central Mall", "locationType": "venue", "venueRole": "property",
          "venueCategory": "mall", "city": "Bangkok", "country": "TH", "status": "Active" }
  → Returns: { "id": "venue-uuid" }

# 2. Create a Building under the Venue
POST /locations
  Body: { "name": "Main Building", "locationType": "building", "parentId": "venue-uuid" }
  → Returns: { "id": "building-uuid" }

# 3. Create a Floor under the Building
POST /locations
  Body: { "name": "Floor 1", "locationType": "floor", "parentId": "building-uuid" }
  → Returns: { "id": "floor-uuid" }

# 4. Create a Space under the Floor
POST /locations
  Body: { "name": "Lobby Screen Area", "locationType": "space", "parentId": "floor-uuid",
          "spaceType": "lobby", "maxCapacity": 500 }
  → Returns: { "id": "space-uuid" }

2. Create an Endpoint and Assign a Device

# 1. Create an Endpoint in the space
POST /locations/:spaceId/endpoints
  Body: { "name": "Screen Mount A", "code": "EP-001", "isMonetized": true }
  → Validates: locationId must be type 'space'
  → Status defaults to 'Vacant'
  → Returns: { "id": "endpoint-uuid" }

# 2. Assign a provisioned Device to the Endpoint
PUT /endpoints/:endpointId/assign-device
  Headers: X-Organization-ID
  Body: { "deviceId": "device-uuid" }
  → Auto-vacates previous endpoint for this device (if any)
  → Sets endpoint status to 'Occupied'
  → Updates devices.location_id = spaceId
  → Returns: { "message": "Device assigned to endpoint" }

3. Create an Establishment Venue (Tenant)

# Option A: Via /locations (creates venue_relationship automatically)
POST /locations
  Body: {
    "name": "Coffee Shop Co.",
    "locationType": "venue",
    "venueRole": "establishment",
    "engagementRole": "tenant",
    "parentVenueId": "property-venue-uuid"
  }
  → Creates location with venueRole = establishment
  → Auto-inserts venue_relationships record (property → establishment)
  → Returns: { "id": "establishment-venue-uuid" }

# Option B: Via /venues/:venueId/establishments (legacy)
POST /venues/:venueId/establishments
  Body: { "name": "Coffee Shop Co.", "type": "F&B", "contractRef": "CTR-001" }
  → Returns full establishment object

4. Assign Location to a Workspace

POST /locations/:locationId/assign/:workspaceId
  → Validates: location belongs to org, workspace belongs to org
  → Inserts workspace_locations (ON CONFLICT DO NOTHING)
  → Returns: { "message": "Location assigned to workspace" }

Note: When creating a location while X-Workspace-ID header is present, the new location is automatically assigned to that workspace.


Change history

Date Author Change
2026-06-17 — Added description, architecture, data model, creation flows
2026-06-16 Pin Created the openapi