The new Revique healthcare / medspa business platform backend — catalog, packages, gift cards, loyalty, promotions, payments, patient portal, notifications and a robust RBAC system — running on Aurora PostgreSQL. Built by Codex, separate from the existing Portal (React / CI-CD) stack.
Engine
Aurora PostgreSQL 16.13
Region
us-east-1
Tables
36
Access
SSM Tunnel · Bastion
Values masked — account ID, cluster endpoint, bastion instance ID and other identifiers are redacted (first 3 chars + ****). The DB password is never printed. Retrieve real values from AWS Secrets Manager / your account before running commands.
The native backend is a purpose-built data platform for the Revique healthcare / medspa business. Where the existing Portal is a React front-end shipped through an AWS CI/CD pipeline (documented on the main page), the native backend is the system of record behind it: a normalized PostgreSQL database that owns catalog & inventory, service packages, gift cards, a loyalty program, promotions, native card payments, the patient portal, cross-system notifications, and a fine-grained role-based access-control (RBAC) system.
It was built by Codex as a fresh, "native" replacement layer that runs alongside the legacy HPT system — many tables carry legacy_* columns (legacy IDs / payloads) so records can be reconciled back to the old platform during migration.
What it is
Aurora PostgreSQL 16.13 cluster in us-east-1
36 tables across 10 functional domains
UUID / identity-based primary keys (no sequences)
pgcrypto enabled for hashing & UUID generation
Append-only ledgers for money & balance movements
How it relates to the Portal
Portal (React/CI-CD) = presentation & delivery
Native backend = authoritative business data
Bridged to legacy HPT via legacy_* keys
Notifications ingest from both legacy_hpt and revique
Payments processed natively via the FluidPay gateway
02
Architecture at a Glance
MASKED
The database has no public IP. Engineers reach it through an AWS SSM Session Manager port-forwarding tunnel that hops through a tiny bastion EC2 instance sitting in the same VPC as the cluster. There is no SSH key and no open inbound port — your AWS credentials are the authentication, and Session Manager brokers the encrypted channel.
Your machine
aws cli + SSM plugin psql → 127.0.0.1:5433
→
Bastion EC2
revique-api-dev-db-tunnel t4g.nano · i-0****
→
Aurora PostgreSQL
rev****.amazonaws.com db: revique · :5432
Engine
Aurora PostgreSQL 16.13, region us-east-1. UUID PKs via gen_random_uuid().
Cryptography
pgcrypto extension enabled — used for UUID generation and for hashing sensitive values (gift-card numbers, portal login identifiers, emulation tokens).
Access model
Private cluster · bastion i-0**** · SSM port-forward tunnel · IAM-based auth (no SSH key, no public endpoint).
Credentials live in AWS Secrets Manager at /revique/revique-api/dev/database/admin (host, port, dbname, username, password). Reference the path — never copy the password into code, tickets, or this page.
03
How to Access the Database
RUNBOOK
A reproducible runbook for opening a read/write session against the dev cluster. All sensitive values are masked — substitute the real ones from describe-* output and Secrets Manager. Commands assume an AWS CLI profile named hptdev.
All eight steps use the masked identifiers shown on this page (i-0****, rev****.amazonaws.com). Replace them with the real values you retrieve in steps b and c.
a
Verify your AWS identity
# Confirm you're authenticated into the right account aws sts get-caller-identity --profile hptdev # → Account: 292**** (masked) · Arn: arn:aws:sts::292****:...
Get credentials from Secrets Manager (never print the password)
# Retrieve the secret — inspect it in a secure shell; do NOT echo/paste the password anywhere aws secretsmanager get-secret-value --region us-east-1 --profile hptdev \ --secret-id /revique/revique-api/dev/database/admin \ --query SecretString --output text # → JSON: { "username": "revique_admin", "host": "rev****...", "port": 5432, "dbname": "revique", "password": "•••••" }
Treat the password as write-only: let psql/PGAdmin prompt for it, or export it to an env var in a private shell. Do not commit it or include it in shared docs.
f
Open the SSM port-forward tunnel (local port 5433)
Gotcha we hit: use local port 5433, not 5432. If you already run a local PostgreSQL it will occupy 5432, and the tunnel will silently collide with it — you'll end up connecting to your own machine instead of Aurora. 5433 keeps them separate.
g
Connect with psql / PGAdmin
# In a second terminal (tunnel stays open in the first): psql "host=127.0.0.1 port=5433 dbname=revique user=revique_admin sslmode=require" # PGAdmin → New Server → Host 127.0.0.1 Port 5433 DB revique User revique_admin # Password: from Secrets Manager (step e)
h
Export the schema (structure only, no data)
pg_dump "host=127.0.0.1 port=5433 dbname=revique user=revique_admin sslmode=require" \ --schema-only --no-owner --no-privileges \ -f revique-native-backend-schema.sql # This is exactly how the schema behind this page was produced.
The raw revique-native-backend-schema.sql still contains unmasked identifiers. Keep it local — do not upload it with the shared site.
04
Database Summary
SCHEMA-ONLY
36
Tables
84
Indexes
27
Foreign Keys
4
Functions
0
Sequences
1
Extension
10
Domains
3
Append-only Ledgers
Design characteristics
UUID identity: every entity PK is uuid DEFAULT gen_random_uuid() — zero sequences.
Money in cents: integer *_cents columns with non-negative CHECK constraints.
Append-only ledgers: gift-card, package and promotion movements are immutable (enforced by triggers).
Multi-location: pricing / configs scoped by practice_location_id, often with partial unique indexes for a "global default" vs per-location row.
Cross-cutting conventions
created_at / updated_at on virtually every table.
set_updated_at() trigger auto-touches updated_at on UPDATE.
legacy_* columns + legacy_payload jsonb preserve the migration lineage from HPT.
idempotency_key + unique indexes protect money operations from double-apply.
05
Schema by Functional Group
36 TABLES
Tables grouped into their business domains. For each, the key columns are listed with type, nullability and default. ★ marks a primary-key column; ◆ marks a foreign-key column. Not every CHECK constraint is shown — see the notes for the important ones.
loyalty_point_adjustments— point earn/burn history◆ loyalty_profile_id
Column
Type
Null
Notes
★ id · ◆ loyalty_profile_id
uuid
not null
→ loyalty_profiles (CASCADE)
points_delta / points_balance_after
integer
not null
delta ≠ 0, balance ≥ 0
source_type / source_id
text
null
partial-unique per (profile, source) — idempotent
eligible_amount_cents
integer
null
loyalty_program_products— products that earn pointsUNIQUE (program, sku)
Column
Type
Null
Notes
★ id
uuid
not null
program_key / name / sku
text
not null
sku non-empty
upc
text
null
CHECK digits only
Packages
6 tables
Sellable service/product bundles: definitions, their line items and per-location prices, plus the per-patient instances, per-item balances and an append-only package ledger.
package_definitions— sellable package templatesPK id
Column
Type
Null
Notes
★ id
uuid
not null
practice_id / name
text
not null
unique (practice, lower(name))
price_cents / currency_code
integer / char(3)
not null
price ≥ 0
starts_at / expires_after_days
timestamptz / int
null
expiry > 0 if set
package_items— what a package contains◆ package_definition_id
Native card payments through the FluidPay gateway: per-practice/location gateway configs and the transaction log. Card data is tokenized — only card_token method is allowed and no PAN is stored.
payment_gateway_configs— gateway credentials/config (secret by reference)PK id
The largest domain — a full role-based permission model with per-location scoping, role emulation and an audit trail. See the RBAC deep-dive for how these fit together.
rbac_roles— roles per practiceUNIQUE (practice, normalized_name)
Column
Type
Null
Notes
★ id
uuid
not null
practice_id / name / normalized_name
text
not null
CHECK normalized_name ≠ 'master'
is_system / is_active
boolean
not null
system roles protected
rbac_feature_catalog— catalog of features & allowed actionsPK feature_key
Column
Type
Null
Notes
★ feature_key
text
not null
natural PK (no uuid)
module_key / name / description
text
mixed
grouped by module
actions
text[]
not null
subset of view/create/edit/delete/export/manage/assign/refund
sort_order / is_active
int / bool
not null
rbac_role_permissions— which (feature, action) a role grantsPK (role, feature, action)
Column
Type
Null
Notes
★ ◆ role_id
uuid
not null
→ rbac_roles (CASCADE)
★ ◆ feature_key
text
not null
→ rbac_feature_catalog
★ action
text
not null
CHECK ∈ 8 verbs
rbac_user_roles— user ⇄ role assignmentsPK (user, role)
Column
Type
Null
Notes
★ ◆ user_id
uuid
not null
→ rbac_users (CASCADE)
★ ◆ role_id
uuid
not null
→ rbac_roles (CASCADE)
rbac_user_locations— which locations a user is scoped toPK (user, location)
Column
Type
Null
Notes
★ ◆ user_id
uuid
not null
→ rbac_users (CASCADE)
★ practice_location_id
text
not null
per-location access scoping
is_active
boolean
not null
rbac_role_emulation_grants— temporary "act as role / super-admin" tokensUNIQUE token_hash
Column
Type
Null
Notes
★ id
uuid
not null
◆ role_id
uuid
null
→ rbac_roles (CASCADE); NULL for super_admin
token_hash
text
not null
hashed (pgcrypto), globally unique
emulation_kind
text
not null
role (role_id set) | super_admin (role_id NULL)
granted_by_user_id / expires_at
text / timestamptz
mixed
CHECK expires_at > created_at
rbac_audit_events— access-control audit trailPK id
Column
Type
Null
Notes
★ id
uuid
not null
practice_id / actor_user_id / actor_user_name
text
mixed
who did it
action / target_type / target_id
text
mixed
what & on which object
metadata
jsonb
not null
indexed by (practice, created_at)
System
1 table
schema_migrations— applied migration ledgerPK id
Column
Type
Null
Notes
★ id
text
not null
migration identifier
name / applied_at
text / timestamptz
not null
tracks Codex migrations
06
RBAC Deep-Dive
8 TABLES
RBAC is the most detailed domain in the schema. It implements a classic users → roles → permissions model, extended with per-location scoping, time-boxed role emulation and a dedicated audit trail. Everything is tenant-scoped by practice_id.
The permission chain
rbac_users ──(rbac_user_roles)──▶ rbac_roles ──(rbac_role_permissions)──▶ ( feature_key , action ) │ │ └──(rbac_user_locations)──▶ practice_location_id rbac_feature_catalog defines the (which sites the user may act in) valid features & their allowed actions
1 · Users & roles
rbac_users holds each platform user (bridged to the legacy user via legacy_user_id). rbac_roles defines named roles per practice. The join table rbac_user_roles (composite PK) grants a user one or more roles. A user with no role has no permissions.
2 · Permissions via a feature catalog
rbac_feature_catalog is the source of truth for what can be permissioned: each feature declares an actions text[] drawn from view, create, edit, delete, export, manage, assign, refund. rbac_role_permissions then grants a role a specific (feature_key, action) pair — its composite PK makes each grant unique, and the FK to the catalog stops invalid feature keys.
3 · Per-location scoping
rbac_user_locations (composite PK of user + practice_location_id) restricts a user to specific sites. Roles say what you can do; locations say where. This lets a "Front Desk" role at Location A be entirely separate from the same role at Location B.
4 · Role emulation
rbac_role_emulation_grants issues a time-boxed, hashed token that lets an authorized user temporarily "act as" another role — or, when emulation_kind = super_admin (with role_id NULL), as a super-admin. A CHECK enforces that expires_at > created_at, and only the token_hash is stored (never the raw token). Ideal for support/impersonation with a built-in expiry.
5 · Audit.rbac_audit_events records who (actor_user_id/name) did what (action) to which object (target_type/target_id), with a JSON metadata blob and a (practice_id, created_at DESC) index for fast per-tenant timelines. Combined with emulation grants, every "act as" is traceable.
Design note. A CHECK on rbac_roles forbids the normalized name 'master', and is_system marks protected built-in roles — guardrails so the reserved super-role can't be spoofed by a practice-created role.
07
Relationships Overview
27 FKs
All 27 foreign keys, grouped by domain. CASCADE = children are removed with their parent; RESTRICT = the parent can't be deleted while children exist (used to protect ledgers & financial history).
Pattern: definition/config parents CASCADE to their pure children (locations, items, links), but anything that touches money or history — issued gift cards, package instances, all three ledgers, payment configs — is RESTRICT, so financial records can never be silently deleted by removing a parent.
08
Functions & Extensions
4 FN · 1 EXT
set_updated_at()
Trigger function — sets NEW.updated_at = now() on every row UPDATE. Wired as a BEFORE UPDATE trigger on ~24 tables so updated_at is always accurate without application code.
prevent_gift_card_ledger_mutation()
Raises 'gift_card_ledger_entries is append-only'. Attached as BEFORE UPDATE and BEFORE DELETE triggers, making the gift-card ledger strictly insert-only.
prevent_package_ledger_mutation()
Raises 'package_ledger_entries is append-only'. Same UPDATE/DELETE guard for the package ledger.
prevent_promotion_application_mutation()
Raises 'promotion_applications is append-only'. Locks the promotion-application log against edits/deletes.
Extension — pgcrypto. Enabled at the database level (CREATE EXTENSION pgcrypto). Supplies gen_random_uuid() for every UUID primary key, and cryptographic hashing for sensitive values stored as *_hash columns (gift-card numbers, portal login identifiers, role-emulation tokens) so raw secrets are never persisted.
Why append-only ledgers? Money and entitlement movements (gift-card balances, package redemptions, applied promotions) must be auditable and irreversible. Instead of updating a balance in place, the app inserts a signed delta row and the trigger forbids editing history — corrections are new compensating entries, not edits.
09
Operational Notes / Next Steps
TO REVIEW
Open items aligned with what leadership asked for — captured here as a working checklist to review and document as the native backend hardens toward production.
Logging & events
Confirm application & DB logs (slow queries, errors) ship to CloudWatch / central logging.
Verify rbac_audit_events is written on every privileged action.
Retention policy for the append-only ledgers & audit trail.
Scaling & availability
Enable / tune Aurora auto-scaling (read replicas, ACU limits for Serverless v2).
Alert on failed payment transactions & gateway errors.
Security & access
Rotate the Secrets Manager DB credential; scope least-privilege DB roles.
Restrict SSM start-session to a named IAM group; log all sessions.
Confirm encryption at rest (KMS) & TLS in transit are enforced.
Do-not-publish reminder. The raw revique-native-backend-schema.sql dump contains unmasked identifiers and must be kept local — exclude it from anything uploaded with this shared site.