Core Concepts

Ecosistema completo para organización y gestión de contenido con interfaces espaciales

🎓 Core Concepts

Understanding the key architectural concepts behind our intelligent storage system.


🧠 Intelligent Storage Philosophy

Autonomous Decision-Making

Our storage system is built on the principle that the system should make optimal decisions automatically rather than requiring manual configuration.

Traditional Approach (Manual):

// ❌ Developer must decide where to store data
await opfsStorage.save('user-data', userData);
await localStorageAdapter.save('critical-data', criticalData);
await indexedDBAdapter.save('large-data', largeData);

Our Approach (Intelligent):

// ✅ System decides automatically based on data characteristics
await storage.put('user-data', userData);        // → OPFS + localStorage (redundant)
await storage.put('critical-data', criticalData); // → Multi-adapter redundancy
await storage.put('large-data', largeData);      // → OPFS (optimal for size)

📦 Storage Adapters

Three-Tier Adapter System

The system uses three complementary storage adapters:

1. OPFS (Origin Private File System)

2. Dexie.js (IndexedDB)

3. localStorage

Automatic Adapter Selection

The Policy Engine analyzes each operation and selects adapters based on:

  1. Key Pattern Analysis

    • user/*, auth/*, critical/* → Redundant storage
    • cache/* → Performance-optimized
    • temp/* → Single adapter, high-speed
    • data/* → Best available adapter
  2. Data Size Analysis

    • Small (<8KB) → localStorage micro-cache
    • Medium (8KB-1MB) → Dexie with compression
    • Large (>1MB) → OPFS file system
  3. Access Pattern Learning

    • Frequently accessed → Prioritized for cache
    • Rarely accessed → Storage-optimized
    • Hot keys → Pre-loaded on startup

⚡ Flash Persistence

Auto-Persistent Signals

Flash Persistence provides signals that automatically persist without manual save/load.

Traditional State (Manual):

// ❌ Boilerplate-heavy with manual persistence
@Component({})
export class Example {
  settings = signal({ theme: 'dark' });

  async ngOnInit() {
    const saved = await storage.get('settings');
    if (saved) this.settings.set(saved);
  }

  async saveSettings() {
    await storage.put('settings', this.settings());
  }
}

Flash Persistence (Automatic):

// ✅ Zero boilerplate - automatic persistence
@Component({})
export class Example {
  settings = autoFlashState('settings', { theme: 'dark' });
  // That's it! Automatically saved on every change.
}

Key Features


🔄 Cloud Sync (Optional)

Offline-First Architecture

Cloud sync is completely optional and maintains local-first performance:

┌─────────────────────────────────────┐
│   Your App (Instant 0.3ms Access)  │
├─────────────────────────────────────┤
│   Flash Persistence (Auto-Save)    │
├─────────────────────────────────────┤
│   Local Storage (Always Fast)      │
│   ├── OPFS (20GB+)                 │
│   ├── Dexie (1GB+)                 │
│   └── localStorage (5-10MB)        │
└─────────────────────────────────────┘
           │
           ↓ (Optional Background Sync)
┌─────────────────────────────────────┐
│   Cloud (MongoDB/Firebase)          │
│   - Configurable sync intervals     │
│   - Priority-based                  │
│   - Conflict resolution             │
└─────────────────────────────────────┘

Sync Strategies

MongoDB Integration:

Firebase Integration:


🎯 Storage Strategies

Three Performance Modes

Speed Strategy

storage.setStrategy('speed');

Balanced Strategy (Default)

storage.setStrategy('balanced');

Durable Strategy

storage.setStrategy('durable');

🔄 Cross-Tab Synchronization

Automatic State Sync

Changes automatically propagate across browser tabs using BroadcastChannel:

// Tab 1: Save data
await storage.put('user/theme', 'dark');

// Tab 2: Automatically updates within ~200ms
const theme = userTheme(); // 'dark' - no manual refresh!

Namespace Isolation

Each namespace gets its own broadcast channel:

// App A (namespace: 'app-a')
storage.put('user/data', dataA); // Broadcasts on 'gg-storage:app-a'

// App B (namespace: 'app-b')
storage.put('user/data', dataB); // Broadcasts on 'gg-storage:app-b'
// No conflicts - completely isolated

📊 Performance Architecture

Multi-Level Caching

Three-tier caching system for maximum performance:

┌─────────────────────────────────────┐
│  L1: Memory Cache (LRU)             │  ← 0.1ms
│  - Hot keys in RAM                  │
│  - Automatic eviction               │
├─────────────────────────────────────┤
│  L2: Micro-Cache (localStorage)     │  ← 0.3ms
│  - 100KB budget (configurable)      │
│  - Frequently accessed data         │
├─────────────────────────────────────┤
│  L3: Storage (OPFS/Dexie)          │  ← 2-5ms
│  - Persistent storage               │
│  - Automatic adapter selection      │
└─────────────────────────────────────┘

Boot Manifest

Automatically tracks "hot" keys for optimization:


🛡️ Data Safety

Smart Redundancy

Critical data is automatically mirrored across adapters:

await storage.put('user/auth-token', token);
// → Saved to:
//   1. OPFS (primary storage)
//   2. localStorage (redundancy)
//   3. Memory cache (performance)

Automatic Error Recovery

The system handles errors gracefully:


🔍 Key Concepts Summary

Concept What It Does Why It Matters
Intelligent Storage Automatic adapter selection No manual configuration needed
Flash Persistence Auto-persistent signals Zero boilerplate state management
Multi-Adapter OPFS + Dexie + localStorage Optimal performance + reliability
Strategies Speed/Balanced/Durable modes Adaptable to different needs
Micro-Cache localStorage fast layer 0.3ms cache hits
Cloud Sync Optional MongoDB/Firebase Offline-first with cloud backup
Cross-Tab Sync BroadcastChannel Automatic state propagation
Smart Redundancy Critical data mirroring Data safety without complexity

🎓 Learning Path

Now that you understand the core concepts:

  1. Getting Started - Implement your first storage
  2. API Reference - Explore all available methods
  3. Flash Persistence - Deep dive into auto-persistent signals
  4. MongoDB Integration - Add cloud sync
  5. Performance Guide - Optimize for your use case

Understanding these concepts helps you leverage the full power of our intelligent storage system! 🚀