Architecture Overview
PassTru uses Supabase (PostgreSQL) as its database backend, featuring a multi-tenant architecture with row-level security (RLS) policies. The schema supports role-based access control, token-based billing, event management, and attendee check-in workflows.Core Design Principles
Multi-Tenancy
The database uses an organization-based multi-tenancy model:- Each organization is a separate tenant with isolated data
- Organizations own events and manage attendees
- Row-level security (RLS) enforces tenant isolation
- Super admins can access all organizations for platform management
Security Architecture
All tables use Row-Level Security (RLS) policies to enforce access control at the database layer, preventing unauthorized data access even if application logic is compromised.
SECURITY DEFINERfunctions for privilege escalation where needed- Separate public RPCs for unauthenticated check-in pages
- Authorization checks in all token deduction functions
- Audit logging for compliance and debugging
Token-Based Billing
PassTru uses a prepaid token system:- Event tokens: Consumed when creating a new event (1 token per event)
- Attendee tokens: Consumed when adding attendees (1 token per attendee)
- Tiered pricing based on purchase quantity
- Token balances tracked in the
organizationstable - All transactions recorded in
token_transactions
Database Schema Layers
Layer Descriptions
| Layer | Tables | Purpose |
|---|---|---|
| Auth Layer | auth.users (Supabase managed) | User authentication and session management |
| User Management | profiles, user_roles | User profiles and role assignments |
| Organization | organizations, organization_members | Multi-tenant structure and team management |
| Event Management | events, event_manager_assignments | Event configuration and manager assignments |
| Attendee Management | attendees | Event attendees and check-in status |
| Billing | token_pricing, token_transactions | Token-based billing and payment tracking |
| Audit | audit_logs | Activity tracking and compliance |
| Platform | platform_settings | Global platform configuration |
| Storage | Storage buckets | File uploads (logos, branding assets) |
Entity Relationships
The database follows a hierarchical ownership model:Key Features
Draft/Publish Workflow
Events support a draft-publish workflow for branding and content:draft_*columns store work-in-progress content- Published columns (
branding_portal,checkin_page_content, etc.) serve public pages - Changes can be previewed before publishing
draft_branding_portal,draft_branding_checkin,draft_branding_postcheckindraft_puck_portal_data,draft_puck_checkin_data,draft_puck_post_checkin_datadraft_attendee_portal_content,draft_checkin_page_content,draft_post_checkin_content
Realtime Updates
Theattendees table is enabled for Supabase Realtime, allowing:
- Live check-in status updates
- Real-time attendee list refreshes
- Multi-user collaboration during events
Performance Optimizations
Denormalized Counters:events.total_attendeesandevents.checked_in_countare maintained by triggers- Eliminates expensive COUNT queries on the attendees table
- Atomic updates ensure consistency
- Token deduction functions use
FOR UPDATEto prevent race conditions - Ensures accurate token balances under concurrent access
Public Access Functions
Public pages (check-in, attendee portal) use
SECURITY DEFINER functions instead of direct table access to prevent data leakage.get_org_public_info(_slug)- Safe organization lookup by slugget_event_public_info(_event_slug, _org_id)- Event details for public pagespublic_atomic_checkin(...)- Single-call check-in with validationget_attendee_portal_data(...)- Attendee portal data with privacy controls
Data Types
Enums
JSON Fields
Several tables use JSONB for flexible schema:| Table | Column | Purpose |
|---|---|---|
events | attendee_fields | Custom form fields configuration |
events | branding_* | Theme and styling JSON |
events | puck_*_data | Page builder component data |
attendees | custom_fields | Custom attendee data |
audit_logs | details | Event-specific audit details |
platform_settings | value | Configuration values |
Storage Buckets
org-logos
- Public: Yes
- Purpose: Organization logo uploads
- Folder structure:
{user_id}/{filename} - Access: Owners can upload/update/delete, public read
branding-assets
- Public: Yes
- Purpose: Event branding images (backgrounds, confirmation email images)
- Folder structure:
{event_id}/{filename} - Access: Event owners and managers can upload/update/delete, public read
Next Steps
Tables Reference
Detailed column specifications for all tables
Relationships
Foreign keys and table relationships