# fengdh/mdict-js architecture

> Architecture diagram of the GitHub repository fengdh/mdict-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fengdh/mdict-js
- Repository: https://github.com/fengdh/mdict-js

## Overview

##### Project type and purpose
- mdict-js is an open-source, client-side JavaScript library and demo application for parsing and rendering MDict dictionary files (mdx/mdd) entirely in the browser.
- Its purpose is to load local mdx/mdd files, parse headers and indices, decompress/encrypt data blocks, and render definitions and embedded resources without any server-side processing.

##### File structure
- Top-level HTML demos: mdict.html (main dictionary UI), profiler.html (performance profiling).
- Core modules (pure JS files):
- mdict-parser.js / mdict-parser-legacy.js – handle file I/O, header and index parsing
- mdict-renderer.js – converts parsed data into DOM or HTML snippets
- lzo-wrapper.js / minilzo-decompress.js / speex.js – decompression routines (LZO, Speex audio)
- ripemd128.js – decryption of keyword indices
- murmurhash3.js – hashing support
- mdict-common.js – shared utilities
- profile.js – performance measurement
- Configuration and loaders: conf.js (settings), require.js (AMD module loader), bluebird (Promise support).
- No backend code or database: all browser-side.

##### README for additional insights
- Emphasizes pure-JS, no native dependencies, asynchronous Promise-based API, support for compression/encryption, on-demand block loading, low memory usage.
- Lists features and TODOs around plugin/extension points (stylesheets, caching, scoped CSS, Node.js module).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        UI1["mdict.html"]:::ui
        UI2["profiler.html"]:::ui
        UI3["selectize.js"]:::ui
        CSS1["ldoceAZ.css"]:::ui
        CSS2["selectize.default.css"]:::ui
        CSS3["sf_ecce.css"]:::ui
    end

    %% Module Loader & Config
    subgraph "Module Loader & Config"
        Loader["require.js"]:::loader
        Conf["conf.js"]:::util
    end

    %% Core Engine
    subgraph "Core Engine"
        subgraph "Parser Subsystem"
            Parser1["mdict-parser.js"]:::core
            Parser2["mdict-parser-legacy.js"]:::core
        end
        Api["mdict.js"]:::core
        subgraph "Decompression Subsystem"
            LZOw["lzo-wrapper.js"]:::core
            MiniLZO["minilzo-decompress.js"]:::core
            Speex["speex.js"]:::core
            LZO1x["lzo1x.js"]:::core
        end
        Decrypt["ripemd128.js"]:::util
        subgraph "Utility & Hashing"
            Common["mdict-common.js"]:::util
            Murmur["murmurhash3.js"]:::util
        end
        Renderer["mdict-renderer.js"]:::core
        Profiling["profile.js"]:::profiling
    end

    %% Data Flow
    UI1 -->|"user lookup"| Api
    UI2 -->|"start profiling"| Profiling
    Api -->|"load file"| Parser1
    Api -->|"load file"| Parser2
    Parser1 -->|"block request"| LZOw
    Parser1 -->|"block request"| MiniLZO
    Parser1 -->|"block request"| Speex
    Parser1 -->|"block request"| LZO1x
    Parser1 -->|"decrypt index"| Decrypt
    LZOw -->|"decompressed data"| Parser1
    MiniLZO -->|"decompressed data"| Parser1
    Speex -->|"audio data"| Parser1
    LZO1x -->|"test archive"| Parser1
    Parser1 -->|"parsed entry"| Renderer
    Renderer -->|"rendered HTML"| UI1

    %% Module Orchestration
    Loader --> Parser1
    Loader --> Parser2
    Loader --> Api
    Loader --> LZOw
    Loader --> MiniLZO
    Loader --> Speex
    Loader --> LZO1x
    Loader --> Decrypt
    Loader --> Common
    Loader --> Murmur
    Loader --> Renderer
    Loader --> Profiling
    Conf --> Api

    %% Profiling Hooks (dashed)
    Profiling -.-> Parser1
    Profiling -.-> LZOw
    Profiling -.-> Decrypt
    Profiling -.-> Renderer

    %% Click Events
    click UI1 "https://github.com/fengdh/mdict-js/blob/master/mdict.html"
    click UI2 "https://github.com/fengdh/mdict-js/blob/master/profiler.html"
    click UI3 "https://github.com/fengdh/mdict-js/blob/master/selectize.js"
    click CSS1 "https://github.com/fengdh/mdict-js/blob/master/ldoceAZ.css"
    click CSS2 "https://github.com/fengdh/mdict-js/blob/master/selectize.default.css"
    click CSS3 "https://github.com/fengdh/mdict-js/blob/master/sf_ecce.css"
    click Loader "https://github.com/fengdh/mdict-js/blob/master/require.js"
    click Conf "https://github.com/fengdh/mdict-js/blob/master/conf.js"
    click Parser1 "https://github.com/fengdh/mdict-js/blob/master/mdict-parser.js"
    click Parser2 "https://github.com/fengdh/mdict-js/blob/master/mdict-parser-legacy.js"
    click Api "https://github.com/fengdh/mdict-js/blob/master/mdict.js"
    click LZOw "https://github.com/fengdh/mdict-js/blob/master/lzo-wrapper.js"
    click MiniLZO "https://github.com/fengdh/mdict-js/blob/master/minilzo-decompress.js"
    click Speex "https://github.com/fengdh/mdict-js/blob/master/speex.js"
    click LZO1x "https://github.com/fengdh/mdict-js/blob/master/lzo1x.js"
    click Decrypt "https://github.com/fengdh/mdict-js/blob/master/ripemd128.js"
    click Common "https://github.com/fengdh/mdict-js/blob/master/mdict-common.js"
    click Murmur "https://github.com/fengdh/mdict-js/blob/master/murmurhash3.js"
    click Renderer "https://github.com/fengdh/mdict-js/blob/master/mdict-renderer.js"
    click Profiling "https://github.com/fengdh/mdict-js/blob/master/profile.js"

    %% Styles
    classDef ui fill:#e0ffe0,stroke:#008000,stroke-width:1px
    classDef loader fill:#fff2cc,stroke:#b58900,stroke-width:1px
    classDef core fill:#e0f0ff,stroke:#005f99,stroke-width:1px
    classDef util fill:#fff0f0,stroke:#990000,stroke-width:1px
    classDef profiling fill:#f0e0ff,stroke:#800080,stroke-width:1px
```
