# zhoufenfens/tribute-multiple architecture

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

- Interactive diagram: https://gitdiagram.com/zhoufenfens/tribute-multiple
- Repository: https://github.com/zhoufenfens/tribute-multiple

## Overview

##### Project Type and Purpose
- Tribute is an open-source JavaScript library (ES6) providing a cross-browser “@mention”/autocomplete engine.
- It ships as an NPM package, a standalone script/CSS bundle, and supports integration via module bundlers (Webpack, Rollup) or direct `<script>` tags.

##### File Structure
- Top-level build & config:
- .babelrc, rollup.config.js, package.json, .travis.yml, .gitignore
- Source code (`src/`):
- Tribute.js – core orchestration
- TributeEvents.js – key/mouse event wiring
- TributeSearch.js – fuzzy-search logic
- TributeRange.js – caret and selection context
- TributeMenuEvents.js – menu rendering & navigation
- utils.js – shared helpers
- tribute.scss – styling
- index.js – module entry point
- Distribution (`dist/`): transpiled UMD, ESM bundles and CSS
- Example (`example/`): demo HTML/CSS to illustrate integration
- Tests (`test/`): Karma config, helper libs, specification files

##### Insights from README
- API flows: initialize `new Tribute({ collection or values })` → attach to host inputs/contenteditable elements → emits events (`tribute-replaced`, `tribute-no-match`, etc.) → customizable templates for menu items and insertion.
- Integration points: can be triggered programmatically, supports remote data loaders, configurable triggers and templates.

1. Host Application
– Input elements / contenteditable container
– Script loader (module bundler or `<script>` tag)
2. Tribute Core
– Tribute instance (entry point)
– TributeEvents (listening to keystrokes, clicks)
– TributeRange (identify trigger context)
– TributeSearch (local or async data lookup)
– TributeMenuEvents (build & manage dropdown UI)
– Templates (selectTemplate, menuItemTemplate)
3. Data Sources
– Static `values` array
– Dynamic loader function (XHR/fetch)
4. Build Pipeline
– Babel (ES6 → ES5)
– Rollup bundling (UMD, ESM)
– Output: dist/ tribute.js, tribute.esm.js, tribute.css
5. Example & Tests
– example/ integration demonstration
– test/ Karma runner, specs, lib dependencies

- User types in Host Input → TributeEvents → TributeRange
- If trigger detected → TributeSearch queries Data Source
- Results → TributeMenuEvents renders Menu UI → user navigates/chooses
- On select → selectTemplate → TributeRange inserts mention → Host Input updated
- Build Pipeline sources `src/` modules and produces `dist/` bundles
- Example imports dist bundles to demonstrate usage
- Tests import src modules to verify behavior

c. Architectural Patterns & Principles
- Modular ES6 components separated by concern (eventing, search, UI, range)
- Plugin-style initialization and extension points (templates, remote loaders)
- No external dependencies; wrapper around host DOM
- Build/test pipeline decoupled from runtime modules

d. Key Technologies & Libraries
- ES6 modules, Babel for transpilation, Rollup for bundling
- Karma + Mocha/Stubs for unit tests
- SCSS → CSS for styling dropdown
- UMD & ESM distribution targets

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host Application Layer
    HostApp["Host Application\n(input/contenteditable)"]:::host
    click HostApp "https://github.com/zhoufenfens/tribute-multiple/blob/master/example/index.html"

    %% Core Runtime Modules
    subgraph "Core Runtime" 
        direction TB
        TributeCore["Tribute Core\n(src/Tribute.js)"]:::runtime
        TributeEvents["TributeEvents\n(src/TributeEvents.js)"]:::runtime
        TributeRange["TributeRange\n(src/TributeRange.js)"]:::runtime
        TributeSearch["TributeSearch\n(src/TributeSearch.js)"]:::runtime
        TributeMenu["TributeMenuEvents\n(src/TributeMenuEvents.js)"]:::runtime
        Utils["Utils\n(src/utils.js)"]:::runtime
        Templates["Templates\n(custom templates hooks)"]:::runtime
        IndexEntry["Module Entry\n(src/index.js)"]:::runtime
    end

    %% Data Layer
    subgraph "Data Sources"
        direction TB
        StaticValues["Static values array"]:::data
        AsyncLoader["Dynamic loader (XHR/fetch)"]:::data
    end

    %% Build & Distribution
    subgraph "Build & Distribution"
        direction TB
        BabelConfig["Babel Config\n(.babelrc)"]:::build
        RollupConfig["Rollup Config\n(rollup.config.js)"]:::build
        DistUMD["UMD Bundle\n(dist/tribute.js)"]:::build
        DistESM["ESM Bundle\n(dist/tribute.esm.js)"]:::build
        DistCSS["CSS Output\n(dist/tribute.css)"]:::build
    end

    %% Examples & Tests
    subgraph "Examples & Tests"
        direction TB
        Example["Example Demo\n(example/index.html)"]:::host
        KarmaConfig["Karma Config\n(test/karma.conf.js)"]:::host
        TestSpecs["Test Specs\n(test/spec/test.js)"]:::host
    end

    %% Runtime Flow
    HostApp -->|"user keystroke"| TributeEvents
    TributeEvents -->|"detect trigger"| TributeRange
    TributeRange -->|"trigger? yes"| TributeSearch
    TributeSearch -->|"results"| TributeMenu
    TributeMenu -->|"user select"| Templates
    Templates -->|"insert mention"| TributeRange
    TributeRange -->|"update"| HostApp

    %% Data Source Flow
    TributeSearch --> StaticValues
    TributeSearch --> AsyncLoader

    %% Build Pipeline Flow
    IndexEntry --> BabelConfig
    IndexEntry --> RollupConfig
    BabelConfig --> DistUMD
    RollupConfig --> DistUMD
    RollupConfig --> DistESM
    RollupConfig --> DistCSS

    %% Example & Test Integration
    Example --> DistUMD
    Example --> DistCSS
    KarmaConfig --> Utils
    KarmaConfig --> TributeCore
    TestSpecs --> TribuneEvents
    TestSpecs --> TributeSearch

    %% Click Events
    click TributeCore "https://github.com/zhoufenfens/tribute-multiple/blob/master/src/Tribute.js"
    click TributeEvents "https://github.com/zhoufenfens/tribute-multiple/blob/master/src/TributeEvents.js"
    click TributeRange "https://github.com/zhoufenfens/tribute-multiple/blob/master/src/TributeRange.js"
    click TributeSearch "https://github.com/zhoufenfens/tribute-multiple/blob/master/src/TributeSearch.js"
    click TributeMenu "https://github.com/zhoufenfens/tribute-multiple/blob/master/src/TributeMenuEvents.js"
    click Utils "https://github.com/zhoufenfens/tribute-multiple/blob/master/src/utils.js"
    click IndexEntry "https://github.com/zhoufenfens/tribute-multiple/blob/master/src/index.js"
    click DistUMD "https://github.com/zhoufenfens/tribute-multiple/blob/master/dist/tribute.js"
    click DistESM "https://github.com/zhoufenfens/tribute-multiple/blob/master/dist/tribute.esm.js"
    click DistCSS "https://github.com/zhoufenfens/tribute-multiple/blob/master/dist/tribute.css"
    click RollupConfig "https://github.com/zhoufenfens/tribute-multiple/blob/master/rollup.config.js"
    click BabelConfig "https://github.com/zhoufenfens/tribute-multiple/blob/master/.babelrc"
    click Example "https://github.com/zhoufenfens/tribute-multiple/blob/master/example/index.html"
    click KarmaConfig "https://github.com/zhoufenfens/tribute-multiple/blob/master/test/karma.conf.js"
    click TestSpecs "https://github.com/zhoufenfens/tribute-multiple/blob/master/test/spec/test.js"

    %% Styles
    classDef runtime fill:#AED6F1,stroke:#333,stroke-width:1px
    classDef build fill:#ABEBC6,stroke:#333,stroke-width:1px
    classDef host fill:#F9E79F,stroke:#333,stroke-width:1px
    classDef data fill:#D2B4DE,stroke:#333,stroke-width:1px
```
