Overview

Architecture overview — GgStorage, BackendSyncEngine, MongoDB, Socket.IO, Yjs, adapter selection

Storage System Overview

Our intelligent storage system provides instant reads (RAM cache), durable persistence with smart adapter selection, cross-tab sync, and optional backend sync. Session 166.3 added BackendSyncEngine and syncToBackend() for fire-and-forget backend persistence.


Architecture Diagram

┌─────────────────────────────────────────────────────────────────┐
│ Frontend (Angular Apps)                                          │
│                                                                  │
│  ┌──────────────────────────────────────────────────────────┐   │
│  │ GgStorage (Intelligent Storage)                          │   │
│  │ ├─ OPFS Adapter (large data, file-like)                   │   │
│  │ ├─ Dexie Adapter (IndexedDB, structured data)            │   │
│  │ └─ LocalStorage Adapter (small config data)              │   │
│  └──────────────────────────────────────────────────────────┘   │
│                         ↕️                                        │
│  ┌──────────────────────────────────────────────────────────┐   │
│  │ BackendSyncEngine (Session 166.3) / SyncEngineService     │   │
│  │ - Fire-and-forget sync with retry queue                   │   │
│  │ - Offline-first: Local first, sync in background          │   │
│  └──────────────────────────────────────────────────────────┘   │
│                         ↕️                                        │
│  ┌──────────────────────────────────────────────────────────┐   │
│  │ RealtimeSyncService (Socket.IO + Yjs)                     │   │
│  │ - Event broadcasting (universe, module, widget updates)   │   │
│  │ - CRDT collaborative editing (page content)              │   │
│  └──────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────┘
                            ↕️ HTTP/WebSocket
┌─────────────────────────────────────────────────────────────────┐
│ Backend API (NestJS)                                             │
│  MongoDB (Mongoose) | Socket.IO Server | Yjs WebSocket Server    │
└─────────────────────────────────────────────────────────────────┘

Intelligent Adapter Selection

Never manually specify adapters. The system analyzes data characteristics and chooses automatically:

Size Adapter Why
< 8KB IndexedDB Fast structured storage
8KB–64KB IndexedDB Optimal for medium data
64KB+ OPFS File-system performance
auth/*, session/* IndexedDB + localStorage Critical redundancy
cache/* IndexedDB No redundancy needed
temp/* localStorage Minimal overhead

Use semantic key names: auth/session/token, user/preferences, cache/api/response.


Real-Time Sync (Socket.IO + Yjs)

Collaborators see changes in ~15ms via Yjs; MongoDB persists in background (~100ms).


Performance Characteristics

Operation Local (GgStorage) Sync to MongoDB Cross-Client Update
Create Universe 5ms 200ms 260ms
Update Universe 5ms 150ms 210ms
Edit Page (Yjs) N/A 100ms (bg) 15ms
Query Data 2ms 50ms N/A

Key: User experience is instant (~5ms) thanks to local-first architecture.


Session 166.3 Additions

See BackendSyncEngine guide.


Core Features


Related