# vuefilespreview/vue-files-preview architecture

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

- Interactive diagram: https://gitdiagram.com/vuefilespreview/vue-files-preview
- Repository: https://github.com/vuefilespreview/vue-files-preview

## Overview

##### Project type and purpose
- This is an open‑source Vue 3 plugin/library (vue‑files‑preview) that provides a single component for previewing a wide variety of file formats (docx, xlsx, pdf, image, audio, video, code, markdown, epub, txt, etc.).
- It’s delivered as an npm package and can also be deployed via CDN.

##### File structure
- Top‑level folders:
- .github (CI/CD workflows, issue/pull templates)
- packages (core TypeScript source & subfolders)
- public and assets (static files and images)
- scripts & vite‑plugins (build/version scripts and custom Vite plugins)
- configuration (tsconfig, eslint, vite.config.ts)
- packages/index.ts exports the plugin;
packages/preview holds the “engine” (constants, interfaces, utils) and a `supports` subfolder containing one submodule per file type.

##### Extract architecture insights from the README
- The core plugin “VueFilesPreview” registers a single component that inspects the passed file, picks the right preview renderer, and displays it.
- Some previews use only native HTML (img, audio, video), others leverage third‑party libraries (vue‑office for docx/xlsx/pdf, codemirror for code, markdown‑it for markdown, epubjs for epub).
- CI/CD (GitHub Actions under .github/workflows) builds, runs tests, and publishes to NPM and CDN.

a. Developer / Consumer
→ uses npm or CDN to install VueFilesPreview
→ in their Vue 3 app calls `app.use(VueFilesPreview)` and embeds `<VueFilesPreview>` in templates
b. VueFilesPreview Plugin (packages/index.ts)
↳ registers the “VueFilesPreview” component globally
c. Preview Engine (packages/preview)
- preview.const.ts (file‑type mapping)
- preview.interface.ts (common props/events)
- utils/utils.ts (file reading & common helpers)
→ dispatches to the selected renderer
d. Preview Renderers (packages/preview/supports/*)
– audio‑preview (native `<audio>` + canvas)
– video‑preview (native `<video>`)
– pic‑preview (native `<img>`)
– code‑preview (CodeMirror)
– md‑preview (markdown‑it)
– pdf‑preview, docx‑preview, xlsx‑preview (vue‑office)
– epub‑preview (epubjs)
– txt‑preview (native text block)
e. External libraries & assets
- vue‑office, codemirror, markdown‑it, epubjs
f. Build & Release Pipeline
- Vite (vite.config.ts + vite‑plugins)
- Custom scripts (build‑version.ts, copy.plugin.ts)
- GitHub Actions (deploy.yml, release‑cdn.yml, contributors.yml)
- Outputs: ESM/CJS bundles, style.css, TypeScript declarations
- Publishes to npm registry & CDN

##### Architectural patterns & principles
- Single‑entry plugin exporting a unified API
- Strategy/Dispatcher pattern for selecting preview modules
- Modular design: one renderer per file type, easy to extend
- Separation of concerns: core engine vs. renderers vs. build pipeline
- CI/CD‑driven automated releases

- Entry and exit points: Developer import → plugin API → rendering → browser DOM

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Consumer
    Consumer["Consumer Vue App"]:::consumer

    %% Library
    subgraph "VueFilesPreview Library"
        subgraph "Plugin Entry"
            Plugin["VueFilesPreview Plugin"]:::internal
        end
        subgraph "Preview Engine"
            Consts["preview.const.ts"]:::internal
            Interfaces["preview.interface.ts"]:::internal
            Utils["utils.ts"]:::internal
        end
        subgraph "Renderers"
            Audio["Audio Preview"]:::internal
            Video["Video Preview"]:::internal
            Image["Image Preview"]:::internal
            Code["Code Preview"]:::internal
            Markdown["Markdown Preview"]:::internal
            PDF["PDF Preview"]:::internal
            DOCX["DOCX Preview"]:::internal
            DOC["DOC Preview"]:::internal
            XLSX["XLSX Preview"]:::internal
            EPUB["EPUB Preview"]:::internal
            TXT["TXT Preview"]:::internal
            Fallback["Fallback Component"]:::internal
        end
    end

    %% External Libraries
    subgraph "External Libraries"
        CM["CodeMirror"]:::external
        VO["vue-office"]:::external
        MI["markdown-it"]:::external
        EPUBJS["epubjs"]:::external
        NativeHTML["HTML5 Elements"]:::external
        Assets["Public Assets"]:::external
    end

    %% Build & Release
    subgraph "Build & Release"
        Vite["Vite"]:::build
        Plugins["Custom Vite Plugins"]:::build
        Scripts["Build & Version Scripts"]:::build
        CI["GitHub Actions"]:::build
        Bundles["Output Bundles"]:::build
        Registry["npm/CDN Registry"]:::build
    end

    %% Flows
    Consumer -->|"install & use"| Plugin
    Plugin -->|"dispatch"| Consts
    Plugin --> Interfaces
    Plugin --> Utils
    Utils -->|"select renderer"| Audio
    Utils --> Video
    Utils --> Image
    Utils --> Code
    Utils --> Markdown
    Utils --> PDF
    Utils --> DOCX
    Utils --> DOC
    Utils --> XLSX
    Utils --> EPUB
    Utils --> TXT
    Utils --> Fallback

    Audio -->|"native"| NativeHTML
    Video --> NativeHTML
    Image --> NativeHTML
    TXT --> NativeHTML
    Code --> CM
    Markdown --> MI
    PDF --> VO
    DOCX --> VO
    DOC --> VO
    XLSX --> VO
    EPUB --> EPUBJS

    Plugin --> Assets
    Fallback --> NativeHTML

    %% Build flow
    Vite --> Bundles
    Plugins --> Bundles
    Scripts --> Bundles
    CI --> Bundles
    Bundles --> Registry

    %% Click Events
    click Plugin "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/index.ts"
    click Consts "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/preview.const.ts"
    click Interfaces "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/preview.interface.ts"
    click Utils "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/utils/utils.ts"
    click Audio "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/supports/audio-preview/index.ts"
    click Video "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/supports/video-preview/index.ts"
    click Image "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/supports/pic-preview/index.ts"
    click Code "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/supports/code-preview/index.ts"
    click Markdown "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/supports/md-preview/index.ts"
    click PDF "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/supports/pdf-preview/index.ts"
    click DOCX "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/supports/docx-preview/index.ts"
    click DOC "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/supports/doc-preview/index.ts"
    click XLSX "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/supports/xlsx-preview/index.ts"
    click EPUB "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/supports/epub-preview/index.ts"
    click TXT "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/supports/txt-preview/index.ts"
    click Fallback "https://github.com/vuefilespreview/vue-files-preview/blob/main/packages/preview/supports/vue-files-preview/index.ts"
    click Assets "https://github.com/vuefilespreview/vue-files-preview/tree/main/assets/images"
    click Vite "https://github.com/vuefilespreview/vue-files-preview/blob/main/vite.config.ts"
    click Plugins "https://github.com/vuefilespreview/vue-files-preview/blob/main/vite-plugins/copy.plugin.ts"
    click Scripts "https://github.com/vuefilespreview/vue-files-preview/blob/main/scripts/build-version.ts"
    click CI "https://github.com/vuefilespreview/vue-files-preview/blob/main/.github/workflows/deploy.yml"

    %% Styles
    classDef internal fill:#BBE1FA,stroke:#333,stroke-width:1px
    classDef external fill:#C6F6D5,stroke:#333,stroke-width:1px
    classDef build fill:#FED9A6,stroke:#333,stroke-width:1px
    classDef consumer fill:#E0E0E0,stroke:#333,stroke-width:1px
```
