Skip to Content
Living documentation — last reviewed 2026-05-28
FeaturesAdmin AppAdmin App — Data Model

Admin App — Data Model

The admin app stores no client-side state of its own; it’s a window onto existing tables.

audit_logs (libs/db/src/lib/schema/admin.ts)

ColumnTypeNotes
iduuid PKRow identity.
actor_clerk_idvarcharClerk id of the human/agent that performed the action.
actionvarcharAction label (e.g. org.update_tier, payment.refund, agent.workouts.create).
resourcevarcharResource type (organization, payment, workout, …).
resource_idvarchar nullableResource id when applicable.
metadatajsonbFree-form context. Carries adminAction: true for admin-interceptor writes, agent: true for agent writes, impersonatedUserId, ip, userAgent, reason, etc.
created_attimestamp tzSort key.

Indexed by (actor_clerk_id, created_at) and (resource, resource_id) for the admin audit list / drill-in queries.

Tables read (admin views)

TableRead by
organizationsOrg list + detail.
memberships, usersMembers and cross-org user search.
subscriptions, plans, payment_transactionsBilling inspection, payments.
platform_subscriptions, platform_transactionsPlatform billing.
leads, platform_leadsLead pipelines.
import_jobs, export_jobsJob dashboards.
audit_logsAudit log list.
ai_usage_daily, ai_conversations, ai_tool_executionsCosts / observability dashboards (agent slice).
cancellation_requestsBilling inspection.

Redis keys

  • platform-admin:<clerkId> — TTL 300s — caches the privateMetadata.platformRole lookup performed by PlatformAdminGuard.

External

  • Clerk’s user privateMetadata.platformRole is the source of truth for admin access. Updates land via Clerk dashboard or via the SDK.
  • PostHog captures every interceptor-driven audit row as an admin.<action> event.
  • Sentry tags admin.* actions so investigation pivot from an exception → audit log is one click.