Data Model
RFID Events

RFID Events

The rfid_events table is the core of Parlevel's real-time tracking. Every tag detection by the relay creates a row here.

Table structure

ColumnTypeDescription
idbigint PKAuto-increment
tag_epctextEPC of the detected tag
location_idbigint FKLocation where the scan occurred
from_location_idbigint FKPrevious location (for movement events)
to_location_idbigint FKDestination location (zone/storeroom ID)
event_typetext"scan", "move", "offline"
rssinumericSignal strength at time of scan (dBm)
reader_idtextID of the reader that detected the tag
created_attimestamptzTimestamp of the event

Zone assignment

A product's zone assignment is derived from rfid_events, not from a direct column on products or products_tag. To find which zone a product is currently in:

SELECT DISTINCT ON (pt.tag_epc)
  pt.tag_epc,
  pt.product_id,
  re.to_location_id AS zone_id,
  re.created_at
FROM products_tag pt
JOIN rfid_events re ON re.tag_epc = pt.tag_epc
WHERE re.to_location_id IS NOT NULL
ORDER BY pt.tag_epc, re.created_at DESC

The most recent event with a to_location_id gives the current zone for each tag.

Event types

event_typeWhen createdDescription
"scan"Every ingest POSTTag was seen by the reader
"move"When tag moves between areasfrom_location_idto_location_id transition
"offline"When tag stops being seenTag has left antenna range

Offline detection

A tag is considered offline when it stops appearing in ingest events for a configurable period. The ingest pipeline:

  1. Compares the incoming tag list against recently-seen tags
  2. Tags missing from the current scan that were present in the previous N scans trigger an "offline" event
  3. The products_tag.tag_status is set to "Offline"

Live tag presence

For real-time presence (is a tag currently in range?), the useLiveTagPresence hook polls the relay directly rather than querying Supabase. This gives sub-second presence updates without waiting for database writes.

Supabase events are used for persistent history and zone assignment — not for live "is it here right now?" checks.

Realtime subscriptions

The Parlevel UI subscribes to rfid_events inserts via Supabase Realtime to update the area management page without a page reload. New events trigger a refetch of storeroom/zone data.

The useRealtimeStorerooms hook manages this subscription. Note: only isLoading (initial fetch) blocks rendering — background refetches triggered by realtime events update the UI silently.