# buggins/coolreader architecture

> Architecture diagram of the GitHub repository buggins/coolreader, 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/buggins/coolreader
- Repository: https://github.com/buggins/coolreader

## Overview

a. Document Processing Flow:
- Input: Various document formats (FB2, EPUB, etc.)
- Processing: Through format parsers → DOM creation → Rendering
- Output: Rendered pages to GUI

b. User Interaction Flow:
- GUI Events → Core Engine
- Core Engine → Display Updates
- Settings/Configuration → Storage

##### Key Subsystems

a. Document Format Support:
- FB2, EPUB, CHM, DOC, etc.
- Format-specific parsers
- Conversion pipelines

b. Rendering Pipeline:
- Layout Engine
- Font Management
- Image Processing
- Page Composition

c. Storage & Caching:
- Document Cache
- Font Cache
- Image Cache
- Settings Storage

##### Cross-Platform Architecture

a. Shared Components:
- Core Engine (crengine)
- Document Processors
- Rendering System

b. Platform-Specific Implementations:
- GUI Frameworks
- Device Integration
- Platform Services

##### Notes

Annotations for:
- Build configurations
- Platform-specific features
- Performance considerations
- Memory management strategies

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Engine Layer"]
        CREngine["CREngine Core"]
        click CREngine "https://github.com/buggins/coolreader/tree/master/crengine/"
        
        subgraph Processing["Document Processing"]
            DOM["DOM/XML Processing"]
            click DOM "https://github.com/buggins/coolreader/tree/master/crengine/src/lvxml/"
            FontMgmt["Font Management"]
            click FontMgmt "https://github.com/buggins/coolreader/tree/master/crengine/src/lvfont/"
            ImgProc["Image Processing"]
            click ImgProc "https://github.com/buggins/coolreader/tree/master/crengine/src/lvimg/"
        end

        subgraph Formats["Document Formats"]
            DocFormats["Format Support"]
            click DocFormats "https://github.com/buggins/coolreader/blob/master/crengine/include/bookformats.h"
            EPUB["EPUB Parser"]
            click EPUB "https://github.com/buggins/coolreader/blob/master/crengine/include/epubfmt.h"
            FB2["FB2 Parser"]
            click FB2 "https://github.com/buggins/coolreader/blob/master/crengine/include/fb2def.h"
            CHM["CHM Parser"]
            click CHM "https://github.com/buggins/coolreader/blob/master/crengine/include/chmfmt.h"
            DOC["DOC Parser"]
            click DOC "https://github.com/buggins/coolreader/blob/master/crengine/include/wordfmt.h"
            RTF["RTF Parser"]
            click RTF "https://github.com/buggins/coolreader/blob/master/crengine/include/rtfimp.h"
        end

        subgraph Rendering["Rendering System"]
            Renderer["Main Renderer"]
            click Renderer "https://github.com/buggins/coolreader/blob/master/crengine/include/lvrend.h"
            DrawBuf["Drawing Buffers"]
            click DrawBuf "https://github.com/buggins/coolreader/tree/master/crengine/src/lvdrawbuf/"
            PageSplit["Page Splitter"]
            click PageSplit "https://github.com/buggins/coolreader/blob/master/crengine/include/lvpagesplitter.h"
        end

        subgraph Cache["Cache System"]
            CacheObj["Cache Objects"]
            click CacheObj "https://github.com/buggins/coolreader/blob/master/crengine/include/lvcacheableobject.h"
            RefCache["Reference Cache"]
            click RefCache "https://github.com/buggins/coolreader/tree/master/crengine/include/lvrefcache"
            FontCache["Font Cache"]
            click FontCache "https://github.com/buggins/coolreader/blob/master/crengine/src/lvfont/lvfontcache.h"
        end

        subgraph View["Document View"]
            ViewController["View Controller"]
            click ViewController "https://github.com/buggins/coolreader/blob/master/crengine/include/lvdocview.h"
            ViewProps["View Properties"]
            click ViewProps "https://github.com/buggins/coolreader/blob/master/crengine/include/lvdocviewprops.h"
            ViewCmd["View Commands"]
            click ViewCmd "https://github.com/buggins/coolreader/blob/master/crengine/include/lvdocviewcmd.h"
        end
    end

    subgraph GUI["Platform-Specific GUI Layer"]
        Android["Android Frontend"]
        click Android "https://github.com/buggins/coolreader/tree/master/android/"
        Qt["Qt Frontend"]
        click Qt "https://github.com/buggins/coolreader/tree/master/cr3qt/"
        WX["wxWidgets Frontend"]
        click WX "https://github.com/buggins/coolreader/tree/master/cr3wx/"
        Eink["E-ink Device Frontend"]
        click Eink "https://github.com/buggins/coolreader/tree/master/cr3gui/"
    end

    subgraph Deps["Third-Party Dependencies"]
        CoreLibs["Core Libraries<br/>(zlib, libpng, libjpeg)"]
        FontLibs["Font Processing<br/>(freetype, harfbuzz, fribidi)"]
        TextProc["Text Processing<br/>(libunibreak, utf8proc)"]
        Compress["Compression<br/>(zstd)"]
    end

    %% Connections
    CREngine --> Processing
    Processing --> Formats
    Processing --> Rendering
    Processing --> Cache
    Processing --> View

    View --> GUI
    GUI --> View

    Deps --> CREngine

    %% Styling
    classDef core fill:#a8d1f0
    classDef gui fill:#90EE90
    classDef deps fill:#D3D3D3
    classDef processing fill:#FFE4B5
    classDef formats fill:#FFA07A
    classDef cache fill:#DDA0DD
    classDef view fill:#87CEEB

    class CREngine,Processing core
    class GUI,Android,Qt,WX,Eink gui
    class Deps,CoreLibs,FontLibs,TextProc,Compress deps
    class DOM,FontMgmt,ImgProc processing
    class Formats,DocFormats,EPUB,FB2,CHM,DOC,RTF formats
    class Cache,CacheObj,RefCache,FontCache cache
    class View,ViewController,ViewProps,ViewCmd view
```
