# l7cy/obsidian-2hop-links-plus architecture

> Architecture diagram of the GitHub repository l7cy/obsidian-2hop-links-plus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/l7cy/obsidian-2hop-links-plus
- Repository: https://github.com/l7cy/obsidian-2hop-links-plus

## Overview

##### Project Context and Purpose
- It extends an existing project (fork of tokuhirom/obsidian-2hop-links-plugin) so some architectural ideas may be inherited from the original.

##### Main Components
a. Plugin Core / Entry Point:
- Use the file "src/main.tsx" as the core of the plugin where Obsidian registers commands, initializes the plugin, and integrates with the Obsidian API.
- How it loads necessary components (settings UI, link models, and views).

b. Data Models:
- A “Data Models” component representing the model subdirectory. This consists of:
- FileEntity.tsx
- PropertiesLinks.tsx
- TwohopLink.tsx
- These represent the data structure (e.g., a note’s title, links, and computed 2-hop relationships).

c. UI Components:
- The “src/ui” directory has several React-based UI files (observing the .tsx extension) including:
- ConnectedLinksView.tsx
- LinkView.tsx
- NewLinksView.tsx
- SeparatePaneView.tsx
- TagLinksListView.tsx
- TwohopLinksRootView.tsx
- TwohopLinksView.tsx

d. Settings Management:
- “src/settings” folder with files like TwohopSettingTab.ts and index.ts. This manages the user configuration (e.g., exclusion paths, preview settings) within Obsidian.
- This component should link back to the Core for initialization and to the UI for user configuration displays.

e. Utility Functions and Processes:
- A module for “Utils” (src/utils.ts) and other helper scripts (e.g., src/getTitle.ts, src/links.ts, src/preview.ts, src/sort.ts) to encapsulate common functionality such as retrieving note titles, handling link extraction, preview generation, and sorting logic.
- These components interconnect with both the UI and data models for processing.

##### Relationships and Interactions Between Components
- The Plugin Core initiating the plugin lifecycle, loading settings, and rendering UI components.
- The UI components consuming data from the Data Models, and interacting with utility functions to display previews and sort links.
- The Settings Module communicating back to Plugin Core and UI components to update configurations.
- Data flow from the utility functions to the UI and models—for example, when a link is clicked in the UI, routing through appropriate handlers defined in the core.

##### Architectural Patterns/Design Principles
- The separation of concerns is clear: distinct directories for models, UI, and settings.
- Uses React (tsx files) for UI, which implies component-based design. Highlight how the state may be passed among these components.
- Leverages configuration files (like manifest.json and manifest-beta.json) for integration with Obsidian’s plugin system.
- Attention to developer tooling is indicated by configuration files (esbuild.config.mjs, tsconfig.json, eslint, etc.), which are peripheral but ensure code quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Integration
    API["Obsidian API"]:::external

    %% Plugin Core
    PC["Plugin Core (main.tsx)"]:::core

    %% Data Models Subgraph
    subgraph "Data Models"
        DM1["FileEntity.tsx"]:::model
        DM2["PropertiesLinks.tsx"]:::model
        DM3["TwohopLink.tsx"]:::model
    end

    %% UI Components Subgraph
    subgraph "UI Components"
        UI1["ConnectedLinksView.tsx"]:::ui
        UI2["LinkView.tsx"]:::ui
        UI3["NewLinksView.tsx"]:::ui
        UI4["SeparatePaneView.tsx"]:::ui
        UI5["TagLinksListView.tsx"]:::ui
        UI6["TwohopLinksRootView.tsx"]:::ui
        UI7["TwohopLinksView.tsx"]:::ui
    end

    %% Settings Management Subgraph
    subgraph "Settings Management"
        S1["TwohopSettingTab.ts"]:::settings
        S2["index.ts"]:::settings
    end

    %% Utility Functions Subgraph
    subgraph "Utility Functions"
        U1["utils.ts"]:::utils
        U2["getTitle.ts"]:::utils
        U3["links.ts"]:::utils
        U4["preview.ts"]:::utils
        U5["sort.ts"]:::utils
    end

    %% Connections
    API -->|"integrates"| PC
    PC -->|"loads"| DM1
    PC -->|"loads"| UI1
    PC -->|"initializes"| S1

    UI1 -->|"rendersDataFrom"| DM1
    UI1 -->|"calls"| U1

    DM1 -->|"processes"| U1

    S1 -->|"updatesConfig"| PC
    S1 -->|"appliesTo"| UI1

    %% Class Definitions for colors
    classDef core fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef model fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef ui fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef settings fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef utils fill:#e2e3e5,stroke:#41464b,stroke-width:2px;
    classDef external fill:#fde2e4,stroke:#a61d24,stroke-width:2px;

    %% Click Events for Plugin Core
    click PC "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/main.tsx"

    %% Click Events for Data Models
    click DM1 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/model/FileEntity.tsx"
    click DM2 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/model/PropertiesLinks.tsx"
    click DM3 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/model/TwohopLink.tsx"

    %% Click Events for UI Components
    click UI1 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/ui/ConnectedLinksView.tsx"
    click UI2 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/ui/LinkView.tsx"
    click UI3 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/ui/NewLinksView.tsx"
    click UI4 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/ui/SeparatePaneView.tsx"
    click UI5 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/ui/TagLinksListView.tsx"
    click UI6 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/ui/TwohopLinksRootView.tsx"
    click UI7 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/ui/TwohopLinksView.tsx"

    %% Click Events for Settings Management
    click S1 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/settings/TwohopSettingTab.ts"
    click S2 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/settings/index.ts"

    %% Click Events for Utility Functions
    click U1 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/utils.ts"
    click U2 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/getTitle.ts"
    click U3 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/links.ts"
    click U4 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/preview.ts"
    click U5 "https://github.com/l7cy/obsidian-2hop-links-plus/blob/master/src/sort.ts"
```
