# estebanrfp/gdb architecture

> Architecture diagram of the GitHub repository estebanrfp/gdb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/estebanrfp/gdb
- Repository: https://github.com/estebanrfp/gdb

## Overview

##### Project type and purpose
- GenosDB is a client-side, decentralized P2P graph database packaged as a JavaScript library.
- It provides a local-first storage engine (OPFS), a powerful query API (CRUD + recursive traversals), real-time P2P synchronization (via GenosRTC and BroadcastChannel), and optional RBAC/ACL security modules.

##### File structure
- Top-level “dist/index.js”: the published, minified library.
- “lib/”: source of high-level API wrappers and internal abstractions.
- “docs/”: detailed design/architecture guides, API references, module guides (e.g., sm-architecture, genosrtc-architecture).
- “examples/”: dozens of standalone HTML demos showing how an application integrates GDB.
- Configuration and CI: package.json, vitest.config.js, .github/workflows/test.yml.
- Testing: “tests/” folder for unit and integration tests of core, operators, API.
- Third-party licenses and architectural whitepapers (WHITEPAPER.md, ROADMAP.md, PHILOSOPHY.md).

##### README for additional insights
- Core modules: Engine, Storage (OPFS), Serialization (MessagePack), Compression (Pako).
- Sync: GenosRTC (WebRTC + Nostr relays) for device-to-device; BroadcastChannel for inter-tab.
- Security: WebAuthn for authentication, RBAC + ACL modules, transaction signatures.
- Architectural papers: hybrid-delta protocol, logical clocks, fallback full-state sync.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "Client Integration" 
        direction TB
        UI["Client Application"]:::ui
    end

    %% Core Layer
    subgraph "GenosDB Core" 
        direction TB
        Engine["Core Engine"]:::core
        API["Core API & Abstractions"]:::core
    end

    %% Storage & Serialization Layer
    subgraph "Storage & Serialization" 
        direction TB
        OPFS["Local Storage (OPFS)"]:::storage
        MsgPack["Serialization (MessagePack)"]:::storage
        Pako["Compression (Pako)"]:::storage
    end

    %% Sync Layer
    subgraph "Real-Time Sync Subsystem" 
        direction TB
        RTC["GenosRTC Module"]:::sync
        Fallback["Fallback Full-State Sync"]:::sync
        BC["BroadcastChannel (cross-tab)"]:::sync
    end

    %% Conflict Resolution
    CR["Conflict Resolution (CRDT/LWW)"]:::storage

    %% Security Layer
    subgraph "Security Manager" 
        direction TB
        SecArch["Security Architecture & API"]:::security
        ACLs["ACLs Module"]:::security
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Nostr["Nostr Relay Network"]:::external
    end

    %% Connections
    UI -->|"gdb({...})"| Engine
    Engine -->|"uses API"| API
    API -->|"writeOp → serialize"| MsgPack
    MsgPack -->|"compress"| Pako
    Pako -->|"store"| OPFS
    Engine -->|"emit delta"| RTC
    Engine -->|"emit delta"| BC
    Engine -->|"full-state request"| Fallback
    RTC -->|"deltaMessage"| Engine
    BC -->|"tab update"| Engine
    Fallback -->|"state sync"| Engine
    Engine -->|"resolve conflicts"| CR
    CR -->|"apply"| OPFS
    Engine -->|"auth check"| SecArch
    SecArch -->|"verify ACLs"| ACLs
    UI -->|"subscribe events"| Engine
    RTC -.->|"signal"| Nostr

    %% Click Events
    click UI "https://github.com/estebanrfp/gdb/tree/main/examples/"
    click Engine "https://github.com/estebanrfp/gdb/blob/main/dist/index.js"
    click API "https://github.com/estebanrfp/gdb/tree/main/lib/"
    click OPFS "https://github.com/estebanrfp/gdb/blob/main/docs/genosdb-worker-architecture.md"
    click MsgPack "https://github.com/estebanrfp/gdb/blob/main/licenses/msgpack-license.txt"
    click Pako "https://github.com/estebanrfp/gdb/blob/main/licenses/pako-license.txt"
    click RTC "https://github.com/estebanrfp/gdb/blob/main/docs/genosrtc-architecture.md"
    click Fallback "https://github.com/estebanrfp/gdb/blob/main/docs/genosdb-fallback-server.md"
    click BC "https://github.com/estebanrfp/gdb/blob/main/docs/genosdb-worker-architecture.md"
    click CR "https://github.com/estebanrfp/gdb/blob/main/docs/genosdb-hybrid-delta-protocol.md"
    click SecArch "https://github.com/estebanrfp/gdb/blob/main/docs/sm-architecture.md"
    click ACLs "https://github.com/estebanrfp/gdb/blob/main/docs/sm-acls-module.md"
    click Nostr "https://github.com/estebanrfp/gdb/blob/main/relays.json"

    %% Styles
    classDef ui fill:#f0f0f0,stroke:#333,stroke-width:1px;
    classDef core fill:#ffffff,stroke:#000,stroke-width:1px;
    classDef storage fill:#cce5ff,stroke:#004085,stroke-width:1px;
    classDef sync fill:#d4edda,stroke:#155724,stroke-width:1px;
    classDef security fill:#fff3cd,stroke:#856404,stroke-width:1px;
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:1px;
```
