# alx/react-bounding-box architecture

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

- Interactive diagram: https://gitdiagram.com/alx/react-bounding-box
- Repository: https://github.com/alx/react-bounding-box

## Overview

##### Main components
A. Source Layer (blue)
- `src/tests/index.js` – Mocha test suite for unit/regression tests
- `stories/` – Storybook stories (`.stories.js`) plus static JSON & CSS assets for interactive examples

B. Build & Packaging Layer (green)
- Babel (`.babelrc`) & ESLint (`.eslintrc`) – transpile + linting
- Webpack (`webpack.config.js` & `.storybook/webpack.config.js`) – bundle source into `dist` and Storybook dev server
- Custom scripts (`.scripts/`) – `mocha_runner.js`, `prepublish.sh`, `publish_storybook.sh`, etc.

C. Distribution Layer (orange)
- `public/` – static demo assets (JSON segmentation files, images) for Storybook & GitHub Pages
- NPM Registry & GitHub Pages – final hosting targets

D. Runtime Environment (purple)
- Consumer Application (any React app) – imports the published bundle
- HTML Canvas & Image Loader – at runtime, the component
1. Loads an image (via URL or local asset)

##### Relationships & Data Flows
1. Developer writes code & stories →
runs linter/tests (`npm test` using `.scripts/mocha_runner.js`) →
compiles/transpiles via Babel → bundles via Webpack →
outputs `dist/` artifacts.
2. `npm publish` (with `prepublish.sh`) pushes the bundle to the npm registry.
3. `publish_storybook.sh` deploys the Storybook static site (using `public/` assets) to GitHub Pages.
component loads in browser →

##### Architectural Patterns & Principles
- Single Responsibility: separate folders for source code, tests, stories, and build scripts
- Modular Bundling: UMD/ESM output so the component can be consumed in multiple module systems
- Demo Isolation: Storybook harness isolates examples, static assets, and interactive use cases
- CI/CD Hooks: Scripts folder encapsulates build, test, publish, and demo-deploy steps

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Source Layer"
        direction TB
        Core["react-bounding-box.js"]:::source
        Tests["index.js (Mocha Tests)"]:::source
        subgraph "Stories & Assets"
            direction TB
            Story1["index.stories.js"]:::source
            Story2["indexState.stories.js"]:::source
            subgraph "static"
                boxes1["boxesAgeReal.json"]:::source
                boxes2["boxesBorderZero.json"]:::source
                seg["segmentation.json"]:::source
                segMasks["segmentationMasks.json"]:::source
                segMaskBox["segmentationMasksBoxes.json"]:::source
                styles["styles.css"]:::source
            end
        end
        SBConfig[".storybook/config.js"]:::source
    end

    subgraph "Build & Packaging Layer"
        direction TB
        ESLint["ESLint (.eslintrc)"]:::build
        Babel["Babel (.babelrc)"]:::build
        WebpackBundle["Webpack Bundle (webpack.config.js)"]:::build
        SBWebpack["Webpack Storybook (.storybook/webpack.config.js)"]:::build
        subgraph "Scripts"
            direction TB
            MochaRunner["mocha_runner.js"]:::build
            Prepublish["prepublish.sh"]:::build
            PublishSB["publish_storybook.sh"]:::build
        end
    end

    subgraph "Distribution Layer"
        direction TB
        Dist["dist/react-bounding-box.js"]:::dist
        Public["public/"]:::dist
        NPM["NPM Registry"]:::dist
        GH["GitHub Pages"]:::dist
    end

    subgraph "Runtime Environment"
        direction TB
        Consumer["Consumer React App"]:::runtime
        Canvas["HTML5 Canvas & Image Loader"]:::runtime
    end

    Core -->|source| MochaRunner
    Tests -->|source| MochaRunner
    MochaRunner -->|"runs ESLint & Mocha"| ESLint
    MochaRunner -->|"runs ESLint & Mocha"| Babel
    ESLint -->|"lints code"| Babel
    Babel -->|"transpiles"| WebpackBundle
    WebpackBundle -->|"outputs bundle"| Dist
    Prepublish -->|"npm publish"| NPM
    Dist -->|published| NPM

    SBConfig -->|configures| SBWebpack
    Story1 -->|story file| SBWebpack
    Story2 -->|story file| SBWebpack
    boxes1 -->|static asset| SBWebpack
    boxes2 -->|static asset| SBWebpack
    seg -->|static asset| SBWebpack
    segMasks -->|static asset| SBWebpack
    segMaskBox -->|static asset| SBWebpack
    styles -->|static asset| SBWebpack
    SBWebpack -->|"builds Storybook"| Public
    PublishSB -->|"deploys"| GH
    Public -->|host| GH

    Consumer -->|imports bundle| NPM
    Consumer -->|runs in browser| Canvas
    Canvas -->|draws boxes| Consumer

    click Core "https://github.com/alx/react-bounding-box/blob/master/src/react-bounding-box.js"
    click Tests "https://github.com/alx/react-bounding-box/blob/master/src/tests/index.js"
    click Story1 "https://github.com/alx/react-bounding-box/blob/master/stories/index.stories.js"
    click Story2 "https://github.com/alx/react-bounding-box/blob/master/stories/indexState.stories.js"
    click boxes1 "https://github.com/alx/react-bounding-box/blob/master/stories/static/boxesAgeReal.json"
    click boxes2 "https://github.com/alx/react-bounding-box/blob/master/stories/static/boxesBorderZero.json"
    click seg "https://github.com/alx/react-bounding-box/blob/master/stories/static/segmentation.json"
    click segMasks "https://github.com/alx/react-bounding-box/blob/master/stories/static/segmentationMasks.json"
    click segMaskBox "https://github.com/alx/react-bounding-box/blob/master/stories/static/segmentationMasksBoxes.json"
    click styles "https://github.com/alx/react-bounding-box/blob/master/stories/static/styles.css"
    click SBConfig "https://github.com/alx/react-bounding-box/blob/master/.storybook/config.js"
    click ESLint "https://github.com/alx/react-bounding-box/blob/master/.eslintrc"
    click Babel "https://github.com/alx/react-bounding-box/blob/master/.babelrc"
    click WebpackBundle "https://github.com/alx/react-bounding-box/blob/master/webpack.config.js"
    click SBWebpack "https://github.com/alx/react-bounding-box/blob/master/.storybook/webpack.config.js"
    click MochaRunner "https://github.com/alx/react-bounding-box/blob/master/.scripts/mocha_runner.js"
    click Prepublish "https://github.com/alx/react-bounding-box/blob/master/.scripts/prepublish.sh"
    click PublishSB "https://github.com/alx/react-bounding-box/blob/master/.scripts/publish_storybook.sh"
    click Dist "https://github.com/alx/react-bounding-box/blob/master/dist/react-bounding-box.js"
    click Public "https://github.com/alx/react-bounding-box/tree/master/public/"

    classDef source fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef build fill:#90EE90,stroke:#333,stroke-width:1px
    classDef dist fill:#FFA500,stroke:#333,stroke-width:1px
    classDef runtime fill:#9370DB,stroke:#333,stroke-width:1px
```
