# kiwix/kiwix-desktop architecture

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

- Interactive diagram: https://gitdiagram.com/kiwix/kiwix-desktop
- Repository: https://github.com/kiwix/kiwix-desktop

## Overview

##### Main Components

a. User Interface Layer:
- Main Window (src/mainwindow.*)
- Content Manager (src/contentmanager.*)
- Settings Manager (src/settingsmanager.*)
- Search Interface (src/searchbar.*)
- Various UI Components (tabbar, webview, etc.)

b. Core Application Layer:
- KiwixApp (src/kiwixapp.*) - Central application controller
- Library Management (src/library.*)
- Download Management (src/downloadmanagement.*)
- Local Kiwix Server (src/localkiwixserver.*)

c. Data Layer:
- ZIM File Handling (via libkiwix)
- Content Management System
- Settings Storage

d. External Dependencies:
- libkiwix (core functionality)
- Qt Framework (UI and core features)
- QtWebEngine (web content rendering)
- aria2 (download management)

**[User Interface Layer]**
- ↑↓
**[Core Application Layer]**
- ↑↓
**[Data Layer]**
- ↑↓
**[External Dependencies]**

##### Component Relationships

- User Interface → Core App: User actions and events
- Core App → Data Layer: Content and settings management
- Core App → External Libraries: Service utilization
- Local Server ↔ Web View: Content serving
- Download Manager ↔ External Services: Content retrieval

##### Detailed Component Breakdown

Main Window:
**[MainWindow]**
- ↓
**[TopWidget] → [TabBar]**
- ↓
**[WebView] ← [ZimView]**
- ↓
**[SearchBar, FindInPageBar, TableOfContentBar]**

Content Management:
**[ContentManager]**
- ↓
**[ContentManagerModel] → [Library]**
- ↓
**[ContentManagerView] → [DownloadManagement]**

##### Implementation Details

Use standardized UML notation:
- Diamonds: Composition relationships

##### Additional Elements

Supporting components:
- Single Application Handler (QtSingleApplication)
- URL Scheme Handler
- Web Channel Object
- Translation System

This architecture reflects a typical Qt desktop application structure with additional specialized components for ZIM file handling and content management. The design emphasizes separation of concerns between UI, business logic, and data management while maintaining good modularity and extensibility.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef data fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    %% User Interface Layer
    subgraph UI
        MW[Main Window]:::ui
        TB[Tab Bar]:::ui
        SB[Search Bar]:::ui
        WV[Web View]:::ui
        ZV[ZIM View]:::ui
        CM[Content Manager]:::ui
        CMV[Content Manager View]:::ui
        SM[Settings Manager]:::ui
    end

    %% Core Application Layer
    subgraph Core
        KA[KiwixApp]:::core
        LM[Library Management]:::core
        DM[Download Management]:::core
        KS[Local Kiwix Server]:::core
        CMM[Content Manager Model]:::core
        USH[URL Scheme Handler]:::core
        WCO[Web Channel Object]:::core
        SAH[Single Application Handler]:::core
    end

    %% Data Layer
    subgraph Data
        ZF[ZIM Files]:::data
        CMS[Content Management System]:::data
        SS[Settings Storage]:::data
        I18N[Translation System]:::data
        RES[Resources]:::data
    end

    %% External Dependencies
    subgraph External
        LK[libkiwix]:::external
        QT[Qt Framework]:::external
        QWE[QtWebEngine]:::external
        A2[aria2]:::external
    end

    %% Relationships
    MW --> TB
    MW --> WV
    MW --> SB
    WV --> ZV
    CM --> CMV
    CMV --> DM
    CM --> CMM
    CMM --> LM
    KA --> LM
    KA --> DM
    KA --> KS
    KA --> USH
    KA --> WCO
    KA --> SAH
    KS --> WV
    DM --> A2
    LM --> ZF
    SM --> SS
    WV --> QWE
    KA --> QT
    LM --> LK

    %% Click events for component mapping
    click MW "https://github.com/kiwix/kiwix-desktop/blob/main/src/mainwindow.cpp"
    click CM "https://github.com/kiwix/kiwix-desktop/blob/main/src/contentmanager.cpp"
    click SM "https://github.com/kiwix/kiwix-desktop/blob/main/src/settingsmanager.cpp"
    click SB "https://github.com/kiwix/kiwix-desktop/blob/main/src/searchbar.cpp"
    click WV "https://github.com/kiwix/kiwix-desktop/blob/main/src/webview.cpp"
    click TB "https://github.com/kiwix/kiwix-desktop/blob/main/src/tabbar.cpp"
    click KA "https://github.com/kiwix/kiwix-desktop/blob/main/src/kiwixapp.cpp"
    click LM "https://github.com/kiwix/kiwix-desktop/blob/main/src/library.cpp"
    click DM "https://github.com/kiwix/kiwix-desktop/blob/main/src/downloadmanagement.cpp"
    click KS "https://github.com/kiwix/kiwix-desktop/blob/main/src/localkiwixserver.cpp"
    click SAH "https://github.com/kiwix/kiwix-desktop/tree/main/subprojects/QtSingleApplication"
    click I18N "https://github.com/kiwix/kiwix-desktop/tree/main/resources/i18n"
    click RES "https://github.com/kiwix/kiwix-desktop/tree/main/resources/css"
    click CMM "https://github.com/kiwix/kiwix-desktop/blob/main/src/contentmanagermodel.cpp"
    click ZV "https://github.com/kiwix/kiwix-desktop/blob/main/src/zimview.cpp"
    click USH "https://github.com/kiwix/kiwix-desktop/blob/main/src/urlschemehandler.cpp"
    click WCO "https://github.com/kiwix/kiwix-desktop/blob/main/src/kiwixwebchannelobject.h"

    %% Legend
    subgraph Legend
        UI_L[UI Components]:::ui
        CORE_L[Core Components]:::core
        DATA_L[Data Components]:::data
        EXT_L[External Dependencies]:::external
    end
```
