# contentauth/c2pa-js-examples architecture

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

- Interactive diagram: https://gitdiagram.com/contentauth/c2pa-js-examples
- Repository: https://github.com/contentauth/c2pa-js-examples

## Overview

##### Project type and purpose
- This is a monorepo of self-contained front-end example/demo applications for the c2pa-js SDK.
- It is managed by Rush.js to enable automatic workspace linking and consistent scripting across multiple example “packages.”
- Each subfolder (esm-imports, minimal-ts-rollup, minimal-ts-vite, minimal-ts-webpack, react-ts-vite) is a standalone demo showing how to integrate c2pa-js with various build tools (ESM imports, Rollup, Vite, Webpack, React+Vite).

##### File structure
- Top-level files:
- CONTRIBUTING.md, LICENSE, README.md (monorepo metadata)
- “esm-imports”, “minimal-ts-rollup”, “minimal-ts-vite”, “minimal-ts-webpack”, “react-ts-vite” (Rush workspaces)
- Each workspace has:
- package.json (defines scripts, dependencies on c2pa-js SDK)
- configuration for its bundler (rollup.config.js, vite.config.js, webpack.config.js)
- a small src or example folder with TypeScript/HTML entrypoints
- dev server entry (index.html) and build output location
- Rush config under each workspace’s .rush/temp shows that Rush orchestrates build, linking, and installs.

##### README for additional insights
- The README reiterates that these are examples managed by Rush.
- It refers to a higher-level documentation guide for using the SDK.
- There is no global backend or database—each example is purely client-side.

a. Main components
- Rush monorepo root
- Workspace manager (Rush.js)
- Individual example packages (5)
– esm-imports
– minimal-ts-rollup
– minimal-ts-vite
– minimal-ts-webpack
– react-ts-vite
- Bundler toolchains (Rollup, Vite, Webpack)
- c2pa-js SDK (as a shared dependency)
- Dev servers / static file servers (per example)
- NPM registry / package store (external)
b. Relationships and interactions
- Rush orchestrates “rushx build” / “rushx start” across all workspaces
- Each workspace pulls in c2pa-js from the monorepo link or NPM
- Bundler compiles TypeScript → JavaScript, injects c2pa-js usage, emits static HTML+JS
- Dev server hosts the built files in browser for interactive demos
c. Architectural patterns/design principles
- Monorepo with workspace linking for zero-version skew across examples
- Polyrepo-style isolation at the workspace level for toolchain experiments
- Reuse of the same core SDK package across multiple build configurations
d. Key technologies/frameworks
- Rush.js for monorepo management
- TypeScript for source code
- Rollup, Webpack, Vite as bundler/dev-server frameworks
- React (in react-ts-vite example)
- ESM imports (in esm-imports example)

##### Elements
- Clear labels: “Rush Monorepo”, each “Example Package” by name, “c2pa-js SDK”
- From Rush → each workspace (orchestration)
- From workspaces → c2pa-js SDK (dependency resolution)
- From workspaces → Bundler tool (Rollup/Vite/Webpack)
- From Bundler → Dev Server → Browser
- From workspaces → NPM Registry (external fetch)
- Another for example packages and their pipelines

## Diagram (Mermaid)

```mermaid
graph TD
    %% Monorepo root and orchestration
    RushRoot["Rush Monorepo Root"]:::monorepo
    NPMRegistry["NPM Registry"]:::external
    C2PA["c2pa-js SDK"]:::sdk

    RushRoot -->|"orchestrates"| esmWorkspace
    RushRoot -->|"orchestrates"| rollupWorkspace
    RushRoot -->|"orchestrates"| viteTsWorkspace
    RushRoot -->|"orchestrates"| webpackWorkspace
    RushRoot -->|"orchestrates"| reactWorkspace

    %% ESM Imports Example
    subgraph "esm-imports Example" 
        esmWorkspace["esm-imports"]:::workspace
        esmRush[".rush"]:::monorepo
        esmPkg["package.json"]:::workspace
        esmBundler["Native ESM Imports"]:::bundler
        esmHTML["index.html"]:::devserver
        esmSandbox["sandbox.config.json"]:::workspace
    end
    esmWorkspace --> esmRush
    esmWorkspace -->|"runs"| esmPkg
    esmWorkspace -->|"fetches deps"| NPMRegistry
    esmWorkspace -->|"links"| C2PA
    esmWorkspace --> esmBundler
    esmBundler --> esmHTML
    esmHTML --> Browser

    %% Rollup Example
    subgraph "minimal-ts-rollup Example"
        rollupWorkspace["minimal-ts-rollup"]:::workspace
        rollupRush[".rush"]:::monorepo
        rollupPkg["package.json"]:::workspace
        rollupConfig["rollup.config.js"]:::bundler
        rollupSrc["src/main.ts"]:::workspace
        rollupHTML["index.html"]:::devserver
    end
    rollupWorkspace --> rollupRush
    rollupWorkspace -->|"runs"| rollupPkg
    rollupWorkspace -->|"fetches deps"| NPMRegistry
    rollupWorkspace -->|"links"| C2PA
    rollupWorkspace --> rollupConfig
    rollupConfig --> rollupSrc
    rollupConfig --> rollupHTML
    rollupHTML --> Browser

    %% Vite TS Example
    subgraph "minimal-ts-vite Example"
        viteTsWorkspace["minimal-ts-vite"]:::workspace
        viteTsRush[".rush"]:::monorepo
        viteTsPkg["package.json"]:::workspace
        viteTsConfig["vite.config.js"]:::bundler
        viteTsEntry["index.ts"]:::workspace
        viteTsHTML["index.html"]:::devserver
    end
    viteTsWorkspace --> viteTsRush
    viteTsWorkspace -->|"runs"| viteTsPkg
    viteTsWorkspace -->|"fetches deps"| NPMRegistry
    viteTsWorkspace -->|"links"| C2PA
    viteTsWorkspace --> viteTsConfig
    viteTsConfig --> viteTsEntry
    viteTsConfig --> viteTsHTML
    viteTsHTML --> Browser

    %% Webpack Example
    subgraph "minimal-ts-webpack Example"
        webpackWorkspace["minimal-ts-webpack"]:::workspace
        webpackRush[".rush"]:::monorepo
        webpackPkg["package.json"]:::workspace
        webpackConfig["webpack.config.js"]:::bundler
        webpackSrc["src/index.ts"]:::workspace
        webpackDev["Dev Server"]:::devserver
    end
    webpackWorkspace --> webpackRush
    webpackWorkspace -->|"runs"| webpackPkg
    webpackWorkspace -->|"fetches deps"| NPMRegistry
    webpackWorkspace -->|"links"| C2PA
    webpackWorkspace --> webpackConfig
    webpackConfig --> webpackSrc
    webpackConfig --> webpackDev
    webpackDev --> Browser

    %% React + Vite Example
    subgraph "react-ts-vite Example"
        reactWorkspace["react-ts-vite"]:::workspace
        reactRush[".rush"]:::monorepo
        reactPkg["package.json"]:::workspace
        reactConfig["vite.config.ts"]:::bundler
        reactMain["src/main.tsx"]:::workspace
        reactApp["src/App.tsx"]:::workspace
        reactHTML["index.html"]:::devserver
    end
    reactWorkspace --> reactRush
    reactWorkspace -->|"runs"| reactPkg
    reactWorkspace -->|"fetches deps"| NPMRegistry
    reactWorkspace -->|"links"| C2PA
    reactWorkspace --> reactConfig
    reactConfig --> reactMain
    reactMain --> reactApp
    reactConfig --> reactHTML
    reactHTML --> Browser

    %% Browser
    Browser["Web Browser"]:::external

    %% Click Events
    click RushRoot "https://github.com/contentauth/c2pa-js-examples/tree/main//"
    click esmRush "https://github.com/contentauth/c2pa-js-examples/blob/main/esm-imports/.rush"
    click rollupRush "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-rollup/.rush"
    click viteTsRush "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-vite/.rush"
    click webpackRush "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-webpack/.rush"
    click reactRush "https://github.com/contentauth/c2pa-js-examples/blob/main/react-ts-vite/.rush"

    click esmPkg "https://github.com/contentauth/c2pa-js-examples/blob/main/esm-imports/package.json"
    click rollupPkg "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-rollup/package.json"
    click viteTsPkg "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-vite/package.json"
    click webpackPkg "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-webpack/package.json"
    click reactPkg "https://github.com/contentauth/c2pa-js-examples/blob/main/react-ts-vite/package.json"

    click esm-dir "https://github.com/contentauth/c2pa-js-examples/tree/main/esm-imports/"
    click esm-html "https://github.com/contentauth/c2pa-js-examples/blob/main/esm-imports/index.html"
    click esm-sandbox "https://github.com/contentauth/c2pa-js-examples/blob/main/esm-imports/sandbox.config.json"

    click rollup-dir "https://github.com/contentauth/c2pa-js-examples/tree/main/minimal-ts-rollup/"
    click rollup-config "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-rollup/rollup.config.js"
    click rollup-src "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-rollup/src/main.ts"
    click rollup-html "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-rollup/index.html"

    click vite-ts-dir "https://github.com/contentauth/c2pa-js-examples/tree/main/minimal-ts-vite/"
    click vite-ts-config "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-vite/vite.config.js"
    click vite-ts-entry "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-vite/index.ts"
    click vite-ts-html "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-vite/index.html"

    click webpack-dir "https://github.com/contentauth/c2pa-js-examples/tree/main/minimal-ts-webpack/"
    click webpack-config "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-webpack/webpack.config.js"
    click webpack-src "https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-webpack/src/index.ts"

    click react-dir "https://github.com/contentauth/c2pa-js-examples/tree/main/react-ts-vite/"
    click react-config "https://github.com/contentauth/c2pa-js-examples/blob/main/react-ts-vite/vite.config.ts"
    click react-main "https://github.com/contentauth/c2pa-js-examples/blob/main/react-ts-vite/src/main.tsx"
    click react-app "https://github.com/contentauth/c2pa-js-examples/blob/main/react-ts-vite/src/App.tsx"
    click react-html "https://github.com/contentauth/c2pa-js-examples/blob/main/react-ts-vite/index.html"

    %% Styles
    classDef monorepo fill:#f9f,stroke:#333,stroke-width:1px
    classDef workspace fill:#bbf,stroke:#333,stroke-width:1px
    classDef sdk fill:#bfb,stroke:#333,stroke-width:1px
    classDef bundler fill:#fbf,stroke:#333,stroke-width:1px
    classDef devserver fill:#ffb,stroke:#333,stroke-width:1px
    classDef external fill:#ddd,stroke:#333,stroke-width:1px
```
