# no-instructions/relay architecture

> Architecture diagram of the GitHub repository no-instructions/relay, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/no-instructions/relay
- Repository: https://github.com/no-instructions/relay

## Overview

##### Main System Components

a) Client-Side (Obsidian Plugin)
- Frontend UI Layer (src/components/*)
- Sync Engine (src/BackgroundSync.ts, src/sync.ts)
- CRDT Implementation (src/y-codemirror.next/*)
- Storage Layer (src/DiskBuffer.ts, src/LocalStorage.ts)
- Authentication (src/LoginManager.ts, src/TokenStore.ts)

b) Server-Side (Referenced but not in codebase)
- Relay Server
- Authentication Service
- Storage Service

##### Architectural Patterns to Highlight

a) Local-First Architecture
- Local storage and CRDT implementation
- Offline capability
- Demonstrate sync flow when online

b) Real-time Collaboration
- How updates flow between clients through relay
- Cursor sharing mechanism
- Demonstrate CRDT merge strategy

##### Specific Implementation Details

Create these distinct sections:

a) Data Flow Layer
**Client Storage <-> CRDT Engine <-> Sync Manager <-> Relay Server <-> Other Clients**

b) Component Interaction Layer
**UI Components -> Document Manager -> CRDT Engine -> Sync Manager**

##### Key Relationships

- Document editing flow
- Real-time cursor sharing
- Folder sharing mechanism
- Authentication flow
- Offline/Online state handling

##### Technical Stack Indicators

- Svelte (UI components)
- Yjs (CRDT implementation)
- CodeMirror (Editor integration)
- WebSocket (Real-time communication)

##### Specific Implementation Notes

- The plugin's integration with Obsidian
- The role of RelayManager in coordinating updates
- The SharedFolder mechanism
- The LiveViews system for real-time updates

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI["Frontend UI Components"]:::ui
        DocMgr["Document Manager"]:::doc
        CRDT["CRDT Engine"]:::crdt
        SyncMgr["Sync Manager"]:::sync
        Storage["Local Storage"]:::storage
        Auth["Authentication"]:::auth
        Network["Network Manager"]:::network
        SharedFolder["Shared Folder System"]:::folder
        LiveViews["Live Views System"]:::live
    end

    subgraph Server
        Relay["Relay Server"]:::server
        AuthService["Auth Service"]:::server
        StorageService["Storage Service"]:::server
    end

    %% Client-side relationships
    UI --> DocMgr
    DocMgr --> CRDT
    CRDT --> SyncMgr
    SyncMgr --> Storage
    Auth --> SyncMgr
    Network --> SyncMgr
    SharedFolder --> DocMgr
    LiveViews --> UI
    
    %% Server interactions
    SyncMgr <-.->|WebSocket| Relay
    Auth <--->|Authentication| AuthService
    Storage <-.->|Sync| StorageService
    
    %% Cross-client communication
    Relay <--->|Real-time Updates| Client2[Client 2]:::client
    Relay <--->|Real-time Updates| Client3[Client 3]:::client

    %% Click events
    click UI "https://github.com/no-instructions/relay/tree/main/src/components/*"
    click DocMgr "https://github.com/no-instructions/relay/blob/main/src/Document.ts"
    click CRDT "https://github.com/no-instructions/relay/blob/main/src/y-codemirror.next/LiveEditPlugin.ts"
    click SyncMgr "https://github.com/no-instructions/relay/blob/main/src/BackgroundSync.ts"
    click Storage "https://github.com/no-instructions/relay/blob/main/src/LocalStorage.ts"
    click Auth "https://github.com/no-instructions/relay/blob/main/src/LoginManager.ts"
    click Network "https://github.com/no-instructions/relay/blob/main/src/NetworkStatus.ts"
    click SharedFolder "https://github.com/no-instructions/relay/blob/main/src/SharedFolder.ts"
    click LiveViews "https://github.com/no-instructions/relay/blob/main/src/LiveViews.ts"

    %% Styling
    classDef ui fill:#a8d1f0
    classDef doc fill:#90caf9
    classDef crdt fill:#64b5f6
    classDef sync fill:#42a5f5
    classDef storage fill:#ffeb3b
    classDef auth fill:#ff9800
    classDef network fill:#f44336
    classDef folder fill:#4caf50
    classDef live fill:#9c27b0
    classDef server fill:#81c784
    classDef client fill:#e0e0e0

    %% Legend
    subgraph Legend
        L1[UI Components]:::ui
        L2[Document Management]:::doc
        L3[CRDT System]:::crdt
        L4[Sync Engine]:::sync
        L5[Storage]:::storage
        L6[Authentication]:::auth
        L7[Network]:::network
        L8[Shared Folders]:::folder
        L9[Live Updates]:::live
        L10[Server Components]:::server
    end
```
