Entity Relationships
Data model diagrams and relationship documentation
Overview
This document provides visual representations of how data entities relate to each other across the ComplyAI platform.
Core Domain Model
┌─────────────────────────────────────────────────────────────────────────────────┐
│ COMPLYAI CORE DATA MODEL │
└────────────────────────── ───────────────────────────────────────────────────────┘
┌──────────────┐
│ USERS │
│──────────────│
│ id │
│ email │
│ name │
│ avatar │
│ ... │
└──────┬───────┘
│
┌─────────────┼─────────────┐
│ │ │
│ user_organizations │ roles_users
│ (junction) │ │ (junction)
│ │ │
▼ │ ▼
┌──────────────┐ │ ┌──────────────┐
│ORGANIZATIONS │ │ │ ROLES │
│──────────────│ │ │──────────────│
│ id │ │ │ id │
│ name │ │ │ name │
│ active │ │ │ description │
│ subscription_│ │ └──────────────┘
│ plan │ │
│ ... │ │
└──────┬───────┘ │
│ │
│ │
▼ │
┌────────────────────┐ │
│ORG_BUSINESS_ACCOUNTS│◀────┘
│────────────────────│
│ id │
│ facebook_id │
│ name │
│ organization_id (FK)│
│ system_user_id │
│ access_token │
│ ... │
└─────────┬──────────┘
│
│ 1:N
▼
┌────────────────────┐
│ ORG_AD_ACCOUNTS │
│────────────────────│
│ id │
│ facebook_id │
│ name │
│ org_business_ │
│ account_id (FK) │
│ currency │
│ account_status │
│ ... │
└─────────┬──────────┘
│
│ 1:N
▼
┌────────────────────┐ ┌────────────────────┐
│ ORG_ADS │────────▶│ ORG_ADS_SCORE │
│────────────────────│ 1:1 │────────────────────│
│ id │ │ id │
│ facebook_id │ │ score │
│ name │ │ text_score │
│ status │ │ media_score │
│ effective_status │ │ db_ad_id (FK) │
│ org_ad_account_id │ └────────────────────┘
│ (FK) │
│ text │
│ image_url │
│ ... │
└────────────────────┘
User & Authentication Model
┌─────────────────────────────────────────────────────────────────────────────────┐
│ USER & AUTHENTICATION MODEL │
└───────────────────────────────────────────────────────────────────── ────────────┘
┌──────────────┐ ┌──────────────┐
│ USERS │ │ ROLES │
│──────────────│ │──────────────│
│ id PK │◀───────────────┐ │ id PK │
│ sub_id │ │ │ name │
│ email UQ │ │ │ description │
│ name │ │ │ permissions │
│ avatar │ │ └──────┬───────┘
│ email_verified│ │ │
│ user_access_ │ │ │
│ token (enc)│ │ │
│ stripe_ │ │ │
│ customer_id│ │ │
│ terms_ │ │ │
│ accepted │ │ │
│ active │ │ │
│ confirmed_at │ │ │
│ ... │ │ │
└──────┬───────┘ │ │
│ │ │
│ │ │
▼ ▼ ▼
┌──────────────────────┐ ┌────── ────────────────┐
│ USER_ORGANIZATIONS │ │ ROLES_USERS │
│──────────────────────│ │──────────────────────│
│ user_id (FK) PK │ │ user_id (FK) PK │
│ org_id (FK) PK │ │ role_id (FK) PK │
└──────────────────────┘ └──────────────────────┘
│
│
▼
┌──────────────┐
│ORGANIZATIONS │
│──────────────│
│ id PK │
│ name │
│ ... │
└──────────────┘
Ad Status Tracking Model
┌─────────────────────────────────────────────────────────────────────────────────┐
│ AD STATUS TRACKING MODEL │
└─────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────┐
│ ORG_ADS │
│────────────────────│
│ id PK │
│ facebook_id │◀──────────────────────────────────────────┐
│ name │ │
│ status │ ← Meta status │
│ effective_status │ ← Meta effective status │
│ ... │ │
└────────────────────┘ │
│
│
┌────────────────────────────┐ ┌──────────────────────── ────┐
│ FACEBOOK_AD_STATUS │ │FACEBOOK_TOTAL_AD_DATA_ │
│────────────────────────────│ │ FEEDBACK │
│ id PK │ │────────────────────────────│
│ ad_id │──────│ id PK │
│ status │ │ ad_id │
│ ← ComplyAI status │ │ admin_id (FK) │
│ false_positive │ │ admin_response │
│ created_time │ │ client_id (FK) │
│ updated_time │ │ client_response │
└────────────────────────────┘ │ admin_read │
│ client_read │
└────────────────────────────┘
│
│
┌────────────────────────────┐ │
│ AD_ACCOUNT_CASE │ │
│────────────────────────────│ │
│ id PK │ │
│ ad_account_id │ │
│ case_id │ │
│ case_contact │ │
└────────────────────────────┘ │
│
▼
┌────────────────────────────┐
│ USERS │
│────────────────────────────│
│ id PK │
│ ... │
└────────────────────────────┘
Activity & Audit Model
┌─────────────────────────────────────────────────────────────────────────────────┐
│ ACTIVITY & AUDIT MODEL │
└─────────────────────────────────────────────────────────────────────────────────┘
┌──────────────┐ ┌────────────────────┐
│ USERS │ │ ACTIVITY_EVENTS │
│──────────────│ │────────────────────│
│ id PK │◀───────────────────│ id PK │
│ name │ │ user_id (FK) │
│ email │ │ ip_address │
│ ... │ │ action │
└──────────────┘ │ description │
│ created_time │
└────────────────────┘
┌──────────────┐ ┌────────────────────┐
│ORGANIZATIONS │ │ NOTIFICATIONS │
│──────────────│ │────────────────────│
│ id PK │◀───────────────────│ id PK │
│ name │ │ organization_id(FK)│
│ ... │ │ title │
└──────────────┘ │ content │
│ notification_type │
│ read │
│ created_time │
└────────────────────┘
┌──────────────┐ ┌────────────────────┐
│ USERS │ │ ISSUES │
│──────────────│ │────────────────────│
│ id PK │◀───────────────────│ id PK │
│ ... │ │ user_id (FK) │
└──────────────┘ │ company_id (FK) │
│ │ name │
│ │ email │
▼ │ issue │
┌──────────────┐ │ issue_type │
│ORGANIZATIONS │◀───────────────────│ ... │
│──────────────│ └─────────┬──────────┘
│ id PK │ │
│ ... │ │ 1:N
└──────────────┘ ▼
┌─────────── ─────────┐
│ ISSUE_ATTACHMENTS │
│────────────────────│
│ id PK │
│ issue_id (FK) │
│ attachment_url │
│ created_time │
└────────────────────┘
Facebook Pages Model
┌─────────────────────────────────────────────────────────────────────────────────┐
│ FACEBOOK PAGES MODEL │
└─────────────────────────────────────────────────────────────────────────────────┘
┌──────────────┐
│ USERS │
│──────────────│
│ id PK │◀─────────────────┬─────────────────┐
│ name │ │ │
│ ... │ │ │
└──────────────┘ │ │
│ │
│ │
┌────────┴───────┐ │
│ FACEBOOK_PAGES │ │
│────────────────│ │
│ id PK │ │
│ user_id (FK) │ │
│ page_name │ │
│ page_id │ │
│ profile_photo_ │ │
│ url │ │
│ cover_photo_ │ │
│ url │ │
│ website │ │
│ status │ │
│ task_id │ │
│ message │ │
└────────┬───────┘ │
│ │
│ M:N │
▼ │
┌────────────────┐ │
│ PAGE_PARTNERS │ │
│────────────────│ │
│ page_id (FK) PK│────────┘
│ user_id (FK) PK│
│ status │
│ created_at │
└────────────────┘
Relationship Summary
One-to-Many Relationships
| Parent | Child | Description |
|---|---|---|
organizations | org_business_accounts | Org has many BMs |
org_business_accounts | org_ad_accounts | BM has many ad accounts |
org_ad_accounts | org_ads | Ad account has many ads |
organizations | notifications | Org has many notifications |
users | activity_events | User has many events |
users | facebook_pages | User has many pages |
issues | issue_attachments | Issue has many attachments |
Many-to-Many Relationships
| Table 1 | Junction | Table 2 | Description |
|---|---|---|---|
users | user_organizations | organizations | Users belong to orgs |
users | roles_users | roles | Users have roles |
facebook_pages | page_partners | users | Pages have partners |
One-to-One Relationships
| Table 1 | Table 2 | Description |
|---|---|---|
org_ads | org_ads_score | Each ad has one score |
Index Strategy
Primary Indexes
All tables have primary key indexes on id.
Foreign Key Indexes
-- Important FK indexes for performance
CREATE INDEX ix_org_business_accounts_org_id ON org_business_accounts(organization_id);
CREATE INDEX ix_org_ad_accounts_bm_id ON org_ad_accounts(org_business_account_id);
CREATE INDEX ix_org_ads_account_id ON org_ads(org_ad_account_id);
CREATE INDEX ix_org_ads_score_ad_id ON org_ads_score(db_ad_id);
Search Indexes
-- Frequently searched fields
CREATE INDEX ix_org_ads_facebook_id ON org_ads(facebook_id);
CREATE INDEX ix_org_ads_status ON org_ads(effective_status);
CREATE INDEX ix_ad_accounts_account_id ON ad_accounts(account_id);
CREATE INDEX ix_facebook_ad_status_ad_id ON facebook_ad_status(ad_id);
📝 Changelog
| Date | Change |
|---|---|
| 2024-12 | Initial ERD documentation |