# pneves-ciandt/ngx-extended-pdf-viewer architecture

> Architecture diagram of the GitHub repository pneves-ciandt/ngx-extended-pdf-viewer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pneves-ciandt/ngx-extended-pdf-viewer
- Repository: https://github.com/pneves-ciandt/ngx-extended-pdf-viewer

## Overview

##### Project type and purpose
- This is an Angular component library (“ngx-extended-pdf-viewer”) that wraps Mozilla’s pdf.js into an Angular-friendly viewer plus UI.
- It provides an npm-publishable library (under projects/ngx-extended-pdf-viewer) with schematics, assets, and tests.
- Key use cases: embed a PDF viewer into Angular apps, supply a consistent UI, support translations, themes, and advanced features (annotations, find, print, etc.).

##### High-level file-structure analysis
- Root configuration & scripts:
- angular.json, tsconfig.json, .prettierrc, jest.config.ts, GitHub workflow files (.github/)
- Custom scripts (e.g., add-version-number, extract-versions.js) for build/versioning
- Library source under projects/ngx-extended-pdf-viewer/:
- src/lib: Angular components, services, pipes, modules, event definitions
- assets: cmaps, fonts, locale FTL files, pdf.worker/ sandbox bundles
- schematics: ng-add recipe to scaffold example apps
- theme, toolbar, sidebar, dialogs: organized feature folders
- Tests & compatibility:
- Unit tests (Jest) in src/lib and toolbar subfolders
- End-to-end compatibility tests under compatibility-tests/ (Angular16, Angular17 demos, Playwright scripts)
- CI, publishing & security:
- GitHub Actions config (.github/) to run builds, tests, SonarCloud analysis
- sbom.json, dependabot.yml, sonar-cloud.yml, security.md
- Build output & packaging:
- ng-package.json and ng-package.prod.json control ng-packagr
- Public API surface in public_api.ts
- package.json / package-lock.json for npm

##### README insights
- Confirms purpose: “Bringing Mozilla’s pdf.js to the Angular world”
- Points to live demos (pdfviewer.net) and build instructions (how-to-build.md)
- Emphasizes library distribution via npm/unpkg

a. Main components
- Developer workspace / repo (source code + scripts + configs)
- Angular library module (ngx-extended-pdf-viewer) comprising:
- Angular UI components (toolbar, sidebar, dialogs)
- Services & event bus (pdf- script-loader, notification, CSP policy)
- Schematics (ng-add recipe)
- Assets package (cmaps, fonts, locale FTLs, pdf.worker & sandbox bundles)
- Build & test pipeline
- Angular CLI (ng build, ng-packagr) → bundles (ESM, UMD)
- Jest (unit tests)
- Playwright & Docker (compatibility-tests)
- GitHub Actions + SonarCloud + Dependabot
- Consumers
- Angular applications importing the library
- npm registry / unpkg CDN serving bundles
- External dependencies
- pdf.js (packaged assets)
- Angular framework
- rxjs, Zone.js, etc.

b. Relationships and interactions
- Developer commits → GitHub Actions triggers → build & test → if green → publish bundles to npm
- Consumer app (frontend) imports module → loads assets (pdf.worker, fonts, cmaps) from library package → Angular components render PDF
- Angular component communicates with web worker (pdf.worker-X.mjs) for parsing/rendering → returns canvas/svg/text layers → UI components subscribe to events via pdf-event-bus

c. Architectural patterns & principles
- Modular architecture: UI features (toolbar, sidebar, dialogs) separated into feature modules
- Service-oriented: central PdfScriptLoaderService, EventBus, NotificationService
- Asset-bundle separation: large binary/text assets separated from TS code for tree-shaking
- Schematics for code generation (ng-add)
- CI/CD as code (GitHub Actions, Docker demos)

d. Key technologies/frameworks
- Angular CLI + ng-packagr
- TypeScript, Jest for unit testing
- Playwright + Docker for compatibility e2e tests
- pdf.js (pdf.worker & sandbox modules)
- GitHub Actions, SonarCloud, Dependabot

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Workspace
    DevWS["Developer Workspace / Repository"]:::code
    click DevWS "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main//"

    %% Build & Test Pipeline
    subgraph "Build & Test Pipeline"
        GHActions["GitHub Actions Workflows"]:::ci
        click GHActions "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/.github/"
        Jest["Jest Unit Tests"]:::ci
        click Jest "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/jest.config.ts"
        E2E["Playwright & Docker E2E"]:::ci
        click E2E "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/compatibility-tests/"
    end

    DevWS -->|"push / commit"| GHActions
    GHActions -->|"run build"| Jest
    GHActions -->|"run e2e tests"| E2E

    %% Library Module
    subgraph "ngx-extended-pdf-viewer Library Module" 
        LibRoot["Library Root"]:::code
        click LibRoot "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/"

        %% Build config
        ngPack["ng-packagr Configs"]:::code
        click ngPack "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/ng-package.json"
        click ngPack "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/ng-package.prod.json"
        PublicAPI["Public API Surface"]:::code
        click PublicAPI "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/src/public_api.ts"
        TSConfigs["TS Configurations"]:::code
        click TSConfigs "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/tsconfig.lib.json"
        click TSConfigs "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/tsconfig.spec.json"
        click TSConfigs "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/tsconfig.schematics.json"

        %% UI Components
        subgraph "UI Components" 
            MainComp["Main Component & Module"]:::code
            click MainComp "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/src/lib/ngx-extended-pdf-viewer.component.ts"
            click MainComp "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/src/lib/ngx-extended-pdf-viewer.module.ts"
            Dialogs["PDF Dialogs"]:::code
            click Dialogs "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/src/lib/pdf-dialog/"
            Sidebar["Sidebar"]:::code
            click Sidebar "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/src/lib/sidebar/"
            Toolbar["Toolbar"]:::code
            click Toolbar "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/src/lib/toolbar/"
            SecToolbar["Secondary Toolbar"]:::code
            click SecToolbar "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/src/lib/secondary-toolbar/"
            DynCSS["Dynamic CSS Injector"]:::code
            click DynCSS "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/src/lib/dynamic-css/"
        end

        %% Services & Event Bus
        subgraph "Services & Event Bus"
            ScriptLoader["PdfScriptLoaderService"]:::service
            click ScriptLoader "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/src/lib/pdf-script-loader.service.ts"
            Notification["NotificationService"]:::service
            click Notification "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/src/lib/pdf-notification-service.ts"
            CSP["CSP Policy Service"]:::service
            click CSP "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/src/lib/pdf-csp-policy.service.ts"
            CoreService["Core Library Service"]:::service
            click CoreService "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/src/lib/ngx-extended-pdf-viewer.service.ts"
            EventBus["Event Bus Definition"]:::service
            click EventBus "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/blob/main/projects/ngx-extended-pdf-viewer/src/lib/options/pdf-event-bus.ts"
        end

        %% Assets
        Assets["Assets Package"]:::asset
        click Assets "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/assets/"

        %% Schematics
        Schematics["Schematics (ng-add)"]:::code
        click Schematics "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/schematics/"

        %% Options & Config
        Options["Options & Configuration"]:::code
        click Options "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/src/lib/options/"

        %% Event Definitions
        Events["Event Definitions"]:::code
        click Events "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/src/lib/events/"

        %% Themes
        Themes["Themes"]:::code
        click Themes "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/src/lib/theme/"

        %% Types
        Types["PDF.js API Types"]:::code
        click Types "https://github.com/pneves-ciandt/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/types/"
    end

    Jest -->|"unit tests on"| LibRoot
    GHActions -->|"build library"| LibRoot
    LibRoot -->|"output bundles"| NPM["npm Registry / unpkg CDN"]:::external

    %% Consumer Application Flow
    ConsumerApp["Consumer Angular Application"]:::external
    ConsumerApp -->|"npm install / import module"| NPM
    ConsumerApp -->|"load assets"| Assets
    ConsumerApp -->|"initialize components"| MainComp
    MainComp -->|"uses service"| ScriptLoader
    ScriptLoader -->|"load pdf.worker"| WebWorker["Web Worker (pdf.worker)"]:::external
    WebWorker -->|"render canvas/text"| Canvas["Canvas/Text Layers"]:::external
    Canvas -->|"events"| EventBus

    %% Styles
    classDef code fill:#D0E6FF,stroke:#1C6EA4,stroke-width:1px
    classDef service fill:#DFFFE0,stroke:#3A7F00,stroke-width:1px
    classDef asset fill:#FFF1BF,stroke:#A67C00,stroke-width:1px
    classDef ci fill:#FFE0E0,stroke:#A00,stroke-width:1px
    classDef external fill:#F0F0F0,stroke:#333,stroke-width:1px
```
