Data Model
TruePortAI’s data architecture is designed for multi-tenancy, strict isolation, and full auditability. The model spans two distinct service domains: the Platform Backend (identity, billing, configuration) and TruePortAI Services (gateway, analytics, governance).
Domain Overview
Full Entity Relationship Diagram
Platform Backend Entities
Tenant
The primary organizational unit. Every resource is scoped to a tenant.
Field |
Type |
Notes |
|---|---|---|
|
Short UUID |
Public-facing identifier |
|
String |
URL-safe, globally unique |
|
Enum |
|
|
Ref → User |
Creator and primary owner |
Multi-Tenancy Pattern: Tenant isolation is enforced at the middleware layer. The TenantContextMiddleware resolves the tenant from the JWT claim (tid), subdomain, or X-Tenant-Slug header. No endpoint in the service API requires an explicit tenant_id parameter.
User
Global identity that can belong to multiple tenants.
Field |
Type |
Notes |
|---|---|---|
|
Short UUID |
Never expose MongoDB |
|
EmailStr |
Globally unique |
|
String |
Argon2 hash |
|
Boolean |
Grants full system access |
|
Enum |
|
Membership
The join table between User and Tenant, carrying the user’s role within that tenant.
Role |
Permissions |
|---|---|
|
Full control, billing, delete tenant |
|
Manage members, keys, policy rules |
|
Create/read API keys, view analytics |
|
Read-only access to analytics |
Subscription & Billing
Configuration System
The configuration model uses a hierarchical override chain:
Bootstrap Default → System DB (Global) → Tenant DB Override
Each ConfigItem stores a scope and optional is_locked flag. When is_locked = true, tenant admins cannot override the value.
TruePortAI Service Entities
API Key
The authentication credential for client applications connecting to the Gateway.
Field |
Type |
Notes |
|---|---|---|
|
String |
Format: |
|
Int |
Default 60 req/min; enforced via Redis |
|
Boolean |
Soft-disable without key rotation |
Key Lifecycle:
Admin creates key via
POST /trueportai-services/api/v1/keysKey is stored hashed in MongoDB
Client embeds key in
x-api-keyheader orAuthorization: BearerMiddleware validates on every request
Key can be deactivated in-place (
is_active = false)
Usage Log
The immutable audit record for every AI interaction.
Field |
Type |
Notes |
|---|---|---|
|
Enum |
|
|
String |
e.g., |
|
Int |
Extracted from provider response |
|
Int |
For cost calculation |
|
Float |
Computed per provider pricing |
|
Float |
End-to-end proxy + provider time |
Storage Strategy:
MongoDB (
usage_logscollection): Hot data, last 30 days, indexed for dashboard queries.S3/Blob (
{tenant-id}/logs/{YYYY/MM/DD}/{log-id}.json): Cold archive, unlimited retention, raw payload included.
Violation
Generated by the Analytics Engine when an ML model or policy rule triggers.
Field |
Type |
Notes |
|---|---|---|
|
Enum |
|
|
Enum |
|
|
Enum |
|
|
Boolean |
True if request/response was stopped |
|
Object |
The scrubbed snapshot — no raw PII stored |
Policy Rule
Tenant-defined governance rules that augment the ML model detections.
Action |
Behavior |
|---|---|
|
Request/response is stopped; 403 returned |
|
Matching tokens replaced with |
|
Violation logged and notification sent |
|
Silent audit only |
Storage Layout (S3 / Azure Blob)
{tenant-slug}/
├── logs/
│ └── {YYYY}/
│ └── {MM}/
│ └── {DD}/
│ └── {usage-log-id}.json # Full raw interaction
├── violations/
│ └── {violation-id}.json # Violation snapshot
└── exports/
└── {report-id}.csv # On-demand exports
Database Collections Summary
saas_platform_core (Global — MongoDB Atlas)
Collection |
Purpose |
|---|---|
|
Global user accounts |
|
Organization records |
|
User↔Tenant role assignments |
|
Pending email invitations |
|
SaaS product catalog |
|
Pricing tiers |
|
Active billing contracts |
|
Config UI layout |
|
Dynamic settings key-value store |
|
One-time passwords (TTL index) |
|
Per-tenant storage credentials |
trueport_ai (Per-Tenant — MongoDB Atlas)
Collection |
Purpose |
|---|---|
|
TruePortAI authentication credentials |
|
Hot audit trail (30-day retention) |
|
Detected policy and ML violations |
|
Custom governance rules |