# lucaorio/obsidian-image-gallery architecture

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

- Interactive diagram: https://gitdiagram.com/lucaorio/obsidian-image-gallery
- Repository: https://github.com/lucaorio/obsidian-image-gallery

## Overview

##### Main Components

a. Input Layer:
- Code Block Parser (handles ```img-gallery blocks)
- Settings Parser (processes YAML configuration)
- File System Interface (reads images from vault paths)

b. Core Processing Layer:
- Gallery Builder
- Horizontal Layout Engine
- Vertical Layout Engine
- Image Processing Pipeline
- Settings Manager

c. Rendering Layer:
- Gallery Renderer
- Lightbox Component
- Error Renderer

##### Component Relationships

- Blue: Input Layer
- Green: Core Processing Layer
- Orange: Rendering Layer

**Input → Processing → Rendering**

##### Specific Implementation Details

- `init.ts` initializes the plugin
- `get-settings.ts` interfaces with configuration
- `get-imgs-list.ts` handles file system operations
- `build-horizontal.ts` and `build-vertical.ts` implement layout logic
- `build-lightbox.ts` manages image viewing functionality

##### Key Technical Elements

Important aspects:
- Obsidian API Integration
- File System Access
- Image Processing Pipeline
- Layout Engines (Horizontal/Vertical)
- Event Handling System

##### Architecture Pattern

**User Input → Parser → Builder → Renderer → Display**

##### Component Details

For each major component, include:
- Input Handler:
- YAML Config Parser
- Path Resolution
- File Type Validation

- Gallery Builder:
- Layout Selection Logic
- Image Size Calculator
- Grid System Manager

- Renderer:
- DOM Manipulation
- CSS Application
- Event Listeners

##### External Dependencies

Integration points with:
- Obsidian API
- File System
- DOM Interface

- Double lines: Data flow

Remember to highlight the plugin's key features:
- Zero setup architecture
- Dual layout options
- Lightbox functionality
- Configurable display options

This will create a comprehensive yet clear visualization of how the plugin processes image galleries from configuration to display.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef input fill:#a8d1f0,stroke:#000
    classDef core fill:#90EE90,stroke:#000
    classDef render fill:#FFB347,stroke:#000
    classDef external fill:#D3D3D3,stroke:#000

    %% External Systems
    subgraph External["External Systems"]
        ObsAPI["Obsidian API"]:::external
        FileSystem["File System"]:::external
        DOM["DOM Interface"]:::external
    end

    %% Input Layer
    subgraph InputLayer["Input Layer"]
        CodeParser["Code Block Parser"]:::input
        Settings["Settings Parser"]:::input
        FSInterface["File System Interface"]:::input
    end

    %% Core Processing Layer
    subgraph CoreLayer["Core Processing Layer"]
        PluginInit["Plugin Initializer"]:::core
        MainController["Main Plugin Controller"]:::core
        
        subgraph BuilderSystem["Gallery Builder"]
            HorzLayout["Horizontal Layout Engine"]:::core
            VertLayout["Vertical Layout Engine"]:::core
            ImgProcess["Image Processing Pipeline"]:::core
        end
        
        SettingsManager["Settings Manager"]:::core
    end

    %% Rendering Layer
    subgraph RenderLayer["Rendering Layer"]
        GalleryRender["Gallery Renderer"]:::render
        Lightbox["Lightbox Component"]:::render
        ErrorRender["Error Renderer"]:::render
        Styling["Styling System"]:::render
    end

    %% Relationships
    ObsAPI --> PluginInit
    FileSystem --> FSInterface
    DOM --> GalleryRender

    CodeParser --> MainController
    Settings --> SettingsManager
    FSInterface --> ImgProcess

    PluginInit --> MainController
    MainController --> BuilderSystem
    SettingsManager --> BuilderSystem

    HorzLayout --> GalleryRender
    VertLayout --> GalleryRender
    ImgProcess --> GalleryRender

    GalleryRender --> Lightbox
    GalleryRender --> ErrorRender
    Styling --> GalleryRender

    %% Click Events
    click Settings "https://github.com/lucaorio/obsidian-image-gallery/blob/main/src/get-settings.ts"
    click FSInterface "https://github.com/lucaorio/obsidian-image-gallery/blob/main/src/get-imgs-list.ts"
    click HorzLayout "https://github.com/lucaorio/obsidian-image-gallery/blob/main/src/build-horizontal.ts"
    click VertLayout "https://github.com/lucaorio/obsidian-image-gallery/blob/main/src/build-vertical.ts"
    click Lightbox "https://github.com/lucaorio/obsidian-image-gallery/blob/main/src/build-lightbox.ts"
    click ErrorRender "https://github.com/lucaorio/obsidian-image-gallery/blob/main/src/render-error.ts"
    click PluginInit "https://github.com/lucaorio/obsidian-image-gallery/blob/main/src/init.ts"
    click MainController "https://github.com/lucaorio/obsidian-image-gallery/blob/main/src/main.ts"
    click Styling "https://github.com/lucaorio/obsidian-image-gallery/blob/main/styles.css"

    %% Legend
    subgraph Legend
        L1["Input Layer"]:::input
        L2["Core Processing"]:::core
        L3["Rendering Layer"]:::render
        L4["External Systems"]:::external
    end
```
