# johnfactotum/foliate architecture

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

- Interactive diagram: https://gitdiagram.com/johnfactotum/foliate
- Repository: https://github.com/johnfactotum/foliate

## Overview

##### Main Components

a. Frontend Layer:
- GTK4/Libadwaita UI Components (represented by the /src/ui directory)
- Main Application Window
- Book Viewer
- Library View
- Navigation Components

b. Core Application Layer:
- Book Processing Engine
- Annotation System
- Search functionality
- Text-to-Speech System

c. Backend Services:
- WebKit Engine Integration
- File System Integration
- Settings Management (GSettings)
- Optional Tracker Integration

##### User Interface Layer (Top)
- UI components connected to their respective controllers
- Main views: Library, Book Viewer, Image Viewer
- UI elements to their corresponding .ui files

##### Core Application Layer (Middle)
- Book Processing (src/reader/reader.js)
- Annotation Management (src/annotations.js)
- Navigation Controls (src/navbar.js)
- Search System (src/search.js)

##### Service Layer (Bottom)
- File System Integration
- WebKit Integration (src/webview.js)
- Database/Storage Services
- External Services (Speech Dispatcher, Tracker)

##### Specific Implementation Details

- Rectangles for UI components (blue)
- Hexagons for core services (green)
- Clouds for external services (purple)

##### Connection Flows

- Data flow between components
- Event handling paths
- Service dependencies
- File system interactions

##### Important Subsystems to Highlight

- OPDS Integration (src/opds)
- Selection Tools (src/selection-tools)
- Theme Management (src/themes.js)
- Internationalization System (po directory)

##### Technical Specifications to Note

- GJS Runtime Requirement (≥ 1.76)
- GTK4 (≥ 4.12)
- WebKitGTK 6.0 dependency
- Optional dependencies (hyphenation, speech-dispatcher)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI
        MainWindow["Main Application Window"]:::ui
        BookViewer["Book Viewer"]:::ui
        LibraryView["Library View"]:::ui
        NavComponents["Navigation Components"]:::ui
    end

    subgraph Core
        BookEngine["Book Processing Engine"]:::core
        AnnotationSystem["Annotation System"]:::core
        SearchSystem["Search System"]:::core
        TTSSystem["Text-to-Speech System"]:::core
        SelectionTools["Selection Tools"]:::core
        ThemeManager["Theme Management"]:::core
    end

    subgraph Services
        WebKit["WebKit Engine"]:::service
        FileSystem["File System"]:::service
        Settings["Settings Management"]:::service
        Tracker["Tracker Integration"]:::service
        OPDS["OPDS Integration"]:::service
        I18n["Internationalization"]:::service
    end

    MainApp["Main Application"]:::main

    %% UI Layer Connections
    MainApp --> MainWindow
    MainWindow --> BookViewer
    MainWindow --> LibraryView
    MainWindow --> NavComponents

    %% Core Layer Connections
    BookViewer --> BookEngine
    BookViewer --> AnnotationSystem
    BookViewer --> SearchSystem
    BookViewer --> TTSSystem
    BookViewer --> SelectionTools
    BookViewer --> ThemeManager

    %% Service Layer Connections
    BookEngine --> WebKit
    BookEngine --> FileSystem
    LibraryView --> FileSystem
    MainApp --> Settings
    LibraryView --> Tracker
    LibraryView --> OPDS
    MainApp --> I18n

    %% Click Events
    click BookViewer "https://github.com/johnfactotum/foliate/blob/gtk4/src/ui/book-viewer.ui"
    click LibraryView "https://github.com/johnfactotum/foliate/blob/gtk4/src/ui/library.ui"
    click NavComponents "https://github.com/johnfactotum/foliate/blob/gtk4/src/ui/navbar.ui"
    click BookEngine "https://github.com/johnfactotum/foliate/blob/gtk4/src/reader/reader.js"
    click AnnotationSystem "https://github.com/johnfactotum/foliate/blob/gtk4/src/annotations.js"
    click SearchSystem "https://github.com/johnfactotum/foliate/blob/gtk4/src/search.js"
    click TTSSystem "https://github.com/johnfactotum/foliate/blob/gtk4/src/tts.js"
    click WebKit "https://github.com/johnfactotum/foliate/blob/gtk4/src/webview.js"
    click Settings "https://github.com/johnfactotum/foliate/blob/gtk4/data/com.github.johnfactotum.Foliate.gschema.xml"
    click SelectionTools "https://github.com/johnfactotum/foliate/tree/gtk4/src/selection-tools/"
    click ThemeManager "https://github.com/johnfactotum/foliate/blob/gtk4/src/themes.js"
    click MainApp "https://github.com/johnfactotum/foliate/blob/gtk4/src/app.js"
    click OPDS "https://github.com/johnfactotum/foliate/tree/gtk4/src/opds/"
    click I18n "https://github.com/johnfactotum/foliate/tree/gtk4/po/"

    %% Styles
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#9b59b6,stroke:#8e44ad,color:white
    classDef main fill:#e74c3c,stroke:#c0392b,color:white

    %% Legend
    subgraph Legend
        UI_Component["UI Component"]:::ui
        Core_Component["Core Component"]:::core
        Service_Component["Service Component"]:::service
        Main_Component["Main Application"]:::main
    end
```
