# Continuwuity Database Mermaid Diagrams This document contains visual representations of the Continuwuity database schema using Mermaid diagrams. ## 1. Core Event Storage Architecture ```mermaid graph TD A[Matrix Event ID
48 bytes] --> B[eventid_shorteventid] B --> C[Short Event ID
8 bytes] C --> D[shorteventid_eventid] D --> A A --> E[eventid_pduid] E --> F[PDU ID
16 bytes] F --> G[pduid_pdu
Main Event Storage] A --> H[eventid_outlierpdu
Outlier Events] C --> I[shorteventid_authchain
Authorization Chains] C --> J[shorteventid_shortstatehash
Event → State Mapping] G -.->|Shared Cache| H style G fill:#e1f5fe style H fill:#e1f5fe style A fill:#fff3e0 style C fill:#f3e5f5 ``` ## 2. Room State Management System ```mermaid graph TD A[Room State Key] --> B[statekey_shortstatekey] B --> C[Short State Key
8 bytes] C --> D[shortstatekey_statekey] D --> A E[Full State Hash] --> F[statehash_shortstatehash] F --> G[Short State Hash
8 bytes] G --> H[shortstatehash_statediff
State Differences] G --> I[roomid_shortstatehash
Current Room State] G --> J[roomsynctoken_shortstatehash
Sync Token Mapping] K[Room ID] --> I L[Sync Token] --> J style G fill:#e8f5e8 style I fill:#fff3e0 style J fill:#f0f4ff ``` ## 3. User Authentication and Identity Flow ```mermaid graph TD A[User ID] --> B[userid_password
Password Hashes] A --> C[userid_displayname] A --> D[userid_avatarurl] D --> E[userid_blurhash] A --> F[useridprofilekey_value
Custom Profile] G[Access Token] --> H[token_userdeviceid] H --> I[User + Device ID] I --> J[userdeviceid_token] J --> G I --> K[userdeviceid_metadata
Device Info] I --> L[userdevicesessionid_uiaainfo
Auth Sessions] I --> M[userdevicetxnid_response
Transaction Cache] N[OpenID Token] --> O[openidtoken_expiresatuserid] P[Login Token] --> Q[logintoken_expiresatuserid] style H fill:#e1f5fe style J fill:#e1f5fe style B fill:#ffebee ``` ## 4. Room Membership Bidirectional System ```mermaid graph TD A[Room ID + User ID] --> B[roomuserid_joined
Room → User View] C[User ID + Room ID] --> D[userroomid_joined
User → Room View] B -.->|Bidirectional| D A --> E[roomuserid_invitecount] C --> F[userroomid_invitestate] E -.->|Related| F A --> G[roomuserid_leftcount] C --> H[userroomid_leftstate] G -.->|Related| H A --> I[roomuserid_knockedcount] C --> J[userroomid_knockedstate] I -.->|Related| J K[Room ID] --> L[roomid_joinedcount
Total Joined] K --> M[roomid_invitedcount
Total Invited] N[Historical] --> O[roomuseroncejoinedids
Ever Joined Tracking] style B fill:#e8f5e8 style D fill:#e8f5e8 style L fill:#fff3e0 style M fill:#fff3e0 ``` ## 5. Cryptography and Key Management Chain ```mermaid graph TD A[User ID] --> B[userid_devicelistversion
Device List Changes] A --> C[userid_masterkeyid
Master Signing Key] A --> D[userid_selfsigningkeyid
Self Signing Key] A --> E[userid_usersigningkeyid
User Signing Key] F[Key ID] --> G[keyid_key
Actual Keys] C --> G D --> G E --> G H[Key Change ID] --> I[keychangeid_userid
Change Notifications] J[One-Time Key ID] --> K[onetimekeyid_onetimekeys
OTK Storage] A --> L[userid_lastonetimekeyupdate
Last OTK Update] M[Backup ID] --> N[backupid_algorithm
Backup Algorithm] M --> O[backupid_etag
Backup Versioning] P[Backup Key ID] --> Q[backupkeyid_backup
Backed Up Keys] style G fill:#e1f5fe style I fill:#fff3e0 style K fill:#f3e5f5 style Q fill:#e8f5e8 ``` ## 6. Federation and Server Communication ```mermaid graph TD A[Server Name] --> B[servername_destination
Cached Destinations] A --> C[servername_override
Cached Overrides] A --> D[server_signingkeys
Federation Keys] A --> E[servername_educount
EDU Counters] F[Server + Event] --> G[servernameevent_data
Server Events] H[Server Current] --> I[servercurrentevent_data
Current State] J[Room ID] --> K[roomserverids
Room → Servers] L[Server Name] --> M[serverroomids
Server → Rooms] K -.->|Bidirectional| M N[Room ID] --> O[roomid_inviteviaservers
Invitation Routing] style B fill:#e1f5fe style C fill:#e1f5fe style K fill:#e8f5e8 style M fill:#e8f5e8 ``` ## 7. Push Notifications and Read Tracking ```mermaid graph TD A[Sender Key] --> B[senderkey_pusher
Push Endpoints] C[Push Key] --> D[pushkey_deviceid
Device Mapping] B -.->|Related| D E[Read Receipt ID] --> F[readreceiptid_readreceipt
Public Receipts] G[Room + User] --> H[roomuserid_privateread
Private Read Markers] G --> I[roomuserid_lastprivatereadupdate
Update Timestamps] J[User + Room] --> K[userroomid_highlightcount
Mention Count] J --> L[userroomid_notificationcount
Notification Count] style F fill:#e8f5e8 style H fill:#f3e5f5 style K fill:#fff3e0 style L fill:#fff3e0 ``` ## 8. Media and Content Management ```mermaid graph TD A[Media ID] --> B[mediaid_file
File Metadata] A --> C[mediaid_user
Uploader Tracking] B -.->|Related| C D[URL] --> E[url_previews
Preview Cache] F[User ID] --> G[userfilterid_filter
Sync Filters] H[Lazy Load] --> I[lazyloadedids
Member Event Tracking] style B fill:#e1f5fe style C fill:#e1f5fe style E fill:#f0f4ff ``` ## 9. Account Data and Presence System ```mermaid graph TD A[Room + User + Type] --> B[roomusertype_roomuserdataid
Account Data Index] B --> C[Room User Data ID] C --> D[roomuserdataid_accountdata
Actual Account Data] E[User ID] --> F[userid_presenceid
Presence Mapping] F --> G[Presence ID] G --> H[presenceid_presence
Presence Data] I[To-Device ID] --> J[todeviceid_events
Device Messages] style D fill:#e8f5e8 style H fill:#f3e5f5 style J fill:#fff3e0 ``` ## 10. Global Configuration and Access Control ```mermaid graph TD A[Global Config] --> B[global
Server Settings] C[Room Categories] --> D[publicroomids
Public Rooms] C --> E[bannedroomids
Banned Rooms] C --> F[disabledroomids
Disabled Rooms] G[App Service ID] --> H[id_appserviceregistrations
Application Services] I[Token Management] --> J[tokenids
Token Allocation] K[Relations] --> L[tofrom_relation
Event Relations] K --> M[threadid_userids
Thread Participants] K --> N[referencedevents
Referenced Events] K --> O[softfailedeventids
Failed Events] style B fill:#e1f5fe style D fill:#e8f5e8 style E fill:#ffebee style F fill:#ffebee ``` ## 11. Complete System Overview ```mermaid graph TB subgraph "Identity Management" UI[User Identity] UA[User Auth] UD[User Devices] UP[User Profile] end subgraph "Event Storage" ES[Event Storage] EID[Event ID Mapping] EO[Outlier Events] end subgraph "Room Management" RS[Room State] RM[Room Membership] RMeta[Room Metadata] end subgraph "Cryptography" DK[Device Keys] CS[Cross Signing] KB[Key Backups] end subgraph "Federation" FS[Federation Servers] FK[Federation Keys] FE[Federation Events] end subgraph "Communication" PUSH[Push Notifications] RT[Read Tracking] DM[Device Messages] end subgraph "Content" MC[Media Content] UP2[URL Previews] AD[Account Data] end UI --> UA UA --> UD UI --> UP ES --> EID ES --> EO EID --> RS RS --> RM RM --> RMeta UD --> DK DK --> CS CS --> KB RM --> FS FS --> FK FK --> FE UD --> PUSH RM --> RT UD --> DM UI --> MC MC --> UP2 UI --> AD style UI fill:#e8f5e8 style ES fill:#e1f5fe style RS fill:#f3e5f5 style DK fill:#fff3e0 style FS fill:#f0f4ff ``` ## Diagram Legend - **Blue boxes** (`#e1f5fe`): Core storage tables - **Green boxes** (`#e8f5e8`): Membership and relationship tables - **Purple boxes** (`#f3e5f5`): ID mapping and compression tables - **Orange boxes** (`#fff3e0`): Count and metadata tables - **Light blue boxes** (`#f0f4ff`): Sync and federation tables - **Red boxes** (`#ffebee`): Access control and security tables - **Solid arrows**: Direct relationships - **Dotted arrows**: Bidirectional or related tables - **Shared Cache notation**: Tables that share memory pools These diagrams show how Continuwuity's 89 database tables interconnect to provide a complete Matrix homeserver implementation with optimized storage patterns and efficient relationship management.