Skip to main content

Delfino

Delfino is a TypeScript RPC bridge library that enables type-safe bidirectional communication between Volpe (an iframe-based reader) and its host applications (Farfalla and Fenice). The library encapsulates all Comlink complexity, providing simple, typed APIs for both sides of the communication.

Overview

Delfino provides:

  • Type-safe RPC communication between iframe and host via Comlink
  • Bidirectional message passing with automatic Message<T> wrapping
  • Domain-based module organization (session, notes, content, playback, etc.)
  • Security features including rate limiting and logging
  • Singleton pattern for Volpe (hostBridge) and factory pattern for hosts (createClientBridge)
  • MessageChannel-based communication for isolation and performance

Package Information

PropertyValue
Package Name@publicala/delfino
Current Version1.1.1
Module TypeESM ("type": "module")
Repositoryhttps://gitlab.com/publicala/delfino.git
LicenseMIT (Proprietary - Publica.la)

Architecture

Communication Model

Delfino uses a bidirectional architecture where both sides share the same base class (BaseBridge) with different roles:

┌─────────────────────────────────────────────────────────────────────────┐
│ COMMUNICATION FLOW │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ HOST (Farfalla/Fenice) VOLPE (iframe) │
│ ══════════════════════ ══════════════ │
│ │
│ ┌──────────────────────┐ ┌─────────────────────────────┐ │
│ │ ClientBridge │ │ HostBridge │ │
│ │ │ │ │ │
│ │ Implements: │ │ Implements: │ │
│ │ • Handlers │◄───────────│ • Commands │ │
│ │ (notes.store) │ Volpe │ (session.sessionExpired)│ │
│ │ (session.init) │ APIs │ (navigation.goBack) │ │
│ │ │ consume │ │ │
│ │ │ handlers │ Consumes (via APIs): │ │
│ │ Calls: │ │ • Handlers │ │
│ │ • Commands │───────────►│ notesAPI.store() │ │
│ │ (goBack) │ Host │ sessionAPI.init() │ │
│ │ (sessionExpired) │ calls │ │ │
│ │ │ commands │ │ │
│ └──────────────────────┘ └─────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘

Naming Convention

The naming follows "bridge to communicate WITH X":

BridgeUsed ByPurpose
HostBridgeVolpe (iframe)Communicate WITH the Host
ClientBridgeHost (Farfalla/Fenice)Communicate WITH the Client (iframe)

Handlers vs Commands

TypeImplemented ByConsumed ByDirection
HandlersHost (Farfalla/Fenice)Volpe (via API classes)Volpe → Host
CommandsVolpeHost (Farfalla/Fenice)Host → Volpe

Key distinction:

  • Farfalla/Fenice creates Handler classes that implement the actual business logic (e.g., NotesHandlers with database operations)
  • Volpe creates API classes that consume those Handlers through hostBridge (e.g., NotesAPI calls hostBridge.notes.store())

Technology Stack

LayerTechnology
LanguageTypeScript 5.0+
RPCComlink 4.4.1
BuildRollup 4.0+
TestingVitest 4.0+ (jsdom)
LintingESLint 9.39+
FormattingPrettier 3.8+

Available Modules

ModuleHandlers (Volpe → Host)Commands (Host → Volpe)
sessioninitializesessionExpired
noteslist, store, update, delete-
contentgetContentStructure, searchContent-
navigationopenLink, locationChanged, reachLastPagegoBack, goToPosition
playbackplayTrack, pauseTrack, seekToPosition, playerStateChangedexternalPlayTrack, externalPauseTrack, externalSeekToPosition
readerreaderInitializedreloadContent, getContentInfo
analyticstrack-
settingsupdate, cookiesAreDisabled-
uiclose, share, copyToClipboard, exportText-
integrations.aigenerate, feedback, listActions-
integrations.dictionarylookup-
integrations.listensynthesize-
integrations.searchsearch-
integrations.translatetranslate-

Security

Delfino provides two security presets:

PresetRate LimitingLogging LevelUse Case
developmentDisableddebugLocal development
productionEnabled (50 req/30s)warnProduction deployment
// Development: verbose logging, no rate limiting
createClientBridge(iframe, { security: 'development' });

// Production: rate limiting enabled, minimal logging
createClientBridge(iframe, { security: 'production' });

Version Synchronization

Volpe and Farfalla must use compatible versions of Delfino.

Rule: Volpe's Delfino version ≤ Farfalla's Delfino version

This ensures Volpe never calls methods that Farfalla does not implement.

Update Order:

  1. Publish new Delfino version
  2. Update Farfalla (implement new handlers)
  3. Update Volpe (call new methods)

Delfino facilitates communication between:

  • Volpe - Iframe-based content reader (PDF, EPUB, Audio)
  • Farfalla - Main web application and backend API
  • Fenice - Mobile and desktop reading applications

Development

For detailed architecture, integration guides, and local setup instructions, refer to the additional documentation sections in this project area.

X

Graph View