# clams-tech/remote architecture

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

- Interactive diagram: https://gitdiagram.com/clams-tech/remote
- Repository: https://github.com/clams-tech/remote

## Overview

##### Project Type and Purpose
- This is a client-side web application built with Svelte (and SvelteKit) that provides a remote-control interface for Core Lightning nodes via the lightning network.
- The README highlights its use case (“Remote control your Core Lightning node(s)”) and provides links to documentation, the live app, and contributing instructions.
- The system clearly focuses on a rich, interactive user interface that integrates with a lightning network backend.

##### Analysis of the File Structure
- There are many configuration files (eslint, prettier, tailwind, vite, tsconfig) which indicate a modern development environment.
- The top-level “src” directory is organized into:
- Core assets such as app.html, app.css, and various Svelte components.
- A “lib” folder that contains utility modules, type definitions, conversion/crypto helpers, and especially many Svelte components responsible for UI elements (e.g., Button, Modal, Wallet).
- A “db” subdirectory within “src/lib” that manages database workers and helpers, hinting at offline or local persistence (likely using IndexedDB or similar in the browser).
- A “wallets” folder which further divides into configurations and “coreln” related modules, showing that wallet management and interactions with Core Lightning node functionality is abstracted into its own domain.
- The “routes” directory is very expansive, using SvelteKit’s filesystem routing to structure views, pages, and subpages for different functionalities (channels, forwards, offers, payments, lnurl, plugins, settings, utxos, wallets, etc.). This pattern indicates an MVC-like approach where view components are neatly separated by domain.
- Web workers are used in several places (e.g., app.worker, db.worker, coreln/worker) to offload heavy computation or asynchronous operations.

##### Key Components
a. Frontend/UI Layer:
- SvelteKit-based application: all pages (from the “routes” directory) and corresponding Svelte components (from “src/lib/components”).
- Layout and routing mechanisms (e.g., “+layout.svelte”, “+page.svelte” files) that define how the user navigates different sections of the app.
- Styling and UI enhancements managed by Tailwind CSS (see tailwind.config.cjs) and additional static assets.

b. Business Logic / Service Layer:
- Utility modules under “src/lib” (such as crypto, conversion, app logic in services.ts, session.ts, settings.ts) handle core business logic.
- A set of type definitions (in “src/lib/@types”) ensures type safety across different lightning functionalities (channels, invoices, payments, wallets, etc.).
- Lightning network specific modules like bolt11 (for invoice handling) and wallet modules (in “src/lib/wallets” and “src/lib/wallets/coreln”) that encapsulate node communication and wallet validation.

c. Data Management and Workers:
- “src/lib/db” directory contains functionalities, including workers (db.worker.ts), to handle local storage or caching (possibly via IndexedDB).
- Additional worker scripts like app.worker.ts and coreln/worker.ts help offload intensive processing from the main UI thread.

d. External Interfaces:
- Communication endpoints with Core Lightning nodes: Although not explicit in configuration files, the functionality shows that this app interacts with external lead nodes over the lightning network.
- Plugin systems and integrations (for example, the “plugins” routes and corresponding components) indicate extensibility to integrate additional services or APIs.

##### Recommendations
- Use a layered architecture approach:
- The top layer represents the Browser (Client) where the SvelteKit UI runs.
- Below the UI, represent the Service/Business Logic layer with modules such as “Lightning Utilities”, “Wallet Management”, “Session & Settings”, and “Data Formatting (e.g., bolt11, conversion)”.
- A separate section for the Worker Processes that perform asynchronous data handling (app.worker, db.worker, coreln/worker).

- Offloading to worker threads for heavy computation or database operations.
- That the service layer issues commands/request to remote Core Lightning nodes.

- Apply Design/Visual Elements:

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Browser (Client)"]:::frontend

    subgraph "UI Layer"
        UI1["Routes & Views"]:::ui
        UI2["Svelte Components"]:::ui
    end

    subgraph "Business Logic"
        BL1["Utility Modules"]:::service
        BL2["Type Definitions"]:::service
        BL3["Lightning Network Utilities"]:::service
    end

    subgraph "Worker Processes"
        WP1["Main Worker Scripts"]:::worker
        WP2["DB Workers & Helpers"]:::worker
        WP3["Core Lightning Worker"]:::worker
    end

    subgraph "External Interfaces"
        EX1["Plugins & Integrations"]:::external
        EX2["Core Lightning Node API"]:::external
    end

    A -->|"Interacts"| UI1
    A -->|"Interacts"| UI2

    UI1 -->|"triggers"| BL1
    UI2 -->|"triggers"| BL1

    BL1 -->|"uses"| BL2
    BL1 -->|"invokes"| BL3

    BL3 -->|"APIcall"| EX2

    BL1 -->|"offloads"| WP1
    BL1 -->|"offloads"| WP2
    BL1 -->|"offloads"| WP3

    EX1 -->|"extends"| BL1

    click UI1 "https://github.com/clams-tech/remote/tree/main/src/routes"
    click UI2 "https://github.com/clams-tech/remote/tree/main/src/lib/components"
    click BL1 "https://github.com/clams-tech/remote/blob/main/src/lib/services.ts"
    click BL2 "https://github.com/clams-tech/remote/tree/main/src/lib/@types"
    click BL3 "https://github.com/clams-tech/remote/blob/main/src/lib/bolt11.ts"
    click WP1 "https://github.com/clams-tech/remote/blob/main/src/lib/app.worker.ts"
    click WP2 "https://github.com/clams-tech/remote/tree/main/src/lib/db"
    click WP3 "https://github.com/clams-tech/remote/blob/main/src/lib/wallets/coreln/worker.ts"
    click EX1 "https://github.com/clams-tech/remote/tree/main/src/routes/plugins"

    classDef frontend fill:#fef2c0,stroke:#e6b800,stroke-width:2px
    classDef ui fill:#c0e6fef,stroke:#0088cc,stroke-width:2px
    classDef service fill:#d1f7c4,stroke:#3a9d23,stroke-width:2px
    classDef worker fill:#fddede,stroke:#ff4d4d,stroke-width:2px
    classDef external fill:#e3d6ff,stroke:#8a2be2,stroke-width:2px
```
