# poloclub/cnn-explainer architecture

> Architecture diagram of the GitHub repository poloclub/cnn-explainer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/poloclub/cnn-explainer
- Repository: https://github.com/poloclub/cnn-explainer

## Overview

#### Purpose and runtime
CNN Explainer is a client-side interactive educational visualization for explaining CNN inference and concepts to non-experts. It is a Svelte application bundled with Rollup and served as static assets, including a pretrained model and visualization data. Primary browser entry points are `public/index.html`, `src/main.js`, and `src/App.svelte`.

#### Application composition
`src/App.svelte` is the top-level coordinator for the explainer UI. It assembles persistent navigation/content and switches between the network overview and layer-level explanations:
- `src/Header.svelte`
- `src/Explainer.svelte`
- `src/config.js`

Shared reactive application state is centralized in `src/stores.js`, forming the coordination boundary between overview interactions, selected layers/features, and detail panels.

#### CNN model and inference boundary
The browser-side CNN integration lives in `src/utils/cnn-tf.js` and `src/utils/cnn.js`. These modules load/use the packaged model data and expose CNN computations to the visual layers rather than calling a backend service. Model artifacts are static public assets:
- `public/assets/data/model.json`
- `public/assets/data/group1-shard1of1.bin`
- `public/assets/data/nn_10.json`

The separate training provenance is a Python/TensorFlow-style Tiny VGG project, not part of the browser runtime:
- `tiny-vgg/tiny-vgg.py`
- `tiny-vgg/environment.yaml`
- `tiny-vgg/data.zip`

#### Network overview stage
The overview provides the high-level CNN pipeline and interactive selection/navigation into individual operations. Rendering and geometry are separated into drawing-focused modules:
- `src/overview/Overview.svelte`
- `src/overview/overview-draw.js`
- `src/overview/intermediate-draw.js`

`src/overview/intermediate-utils.js` and `src/overview/flatten-draw.js` support layer/intermediate representation display, while `src/overview/Modal.svelte` handles contextual overlay interaction. This stage consumes model/intermediate state and updates shared stores to drive detail views.

#### Layer-detail visualization stage
The detail-view subsystem explains the selected CNN operation with operation-specific Svelte panels and animations. Architecturally important operation families are:
- Convolution: `src/detail-view/Convolutionview.svelte`, `src/detail-view/ConvolutionAnimator.svelte`
- Activation/pooling: `src/detail-view/Activationview.svelte`, `src/detail-view/Poolview.svelte`
- Classification/math: `src/detail-view/Softmaxview.svelte`, `src/detail-view/KernelMathView.svelte`

`src/detail-view/Dataview.svelte` and `src/detail-view/DetailviewUtils.js` provide common presentation/data behavior. Hyperparameter-specific interactions are isolated in `Hyperparameterview.svelte`, `HyperparameterDataview.svelte`, and `HyperparameterAnimator.svelte`.

#### Educational narrative and media
The explainer combines interactive model views with article-style instructional content:
- `src/article/Article.svelte`
- `src/article/Youtube.svelte`
- `src/Explainer.svelte`

This is a presentation boundary: article/media content explains concepts, while overview/detail modules render interactive computation and state.

#### Delivery and infrastructure
The deployable artifact is static hosting compatible with GitHub Pages. Build/development orchestration is defined by:
- `package.json`
- `rollup.config.js`
- `rollup_start_dev.js`

GitHub Actions runs the build at `.github/workflows/build.yml`; `deploy-gh-page.sh` supports publishing. Public styles, images, fonts, figures, and model data are delivered directly from `public/`, with no indicated server API or database dependency.

Main entry points: [`src/Explainer.svelte`](https://github.com/poloclub/cnn-explainer/blob/master/src/Explainer.svelte) (Explainer composition), [`src/overview/Overview.svelte`](https://github.com/poloclub/cnn-explainer/blob/master/src/overview/Overview.svelte) (Network overview), [`src/App.svelte`](https://github.com/poloclub/cnn-explainer/blob/master/src/App.svelte) (App coordinator), [`rollup.config.js`](https://github.com/poloclub/cnn-explainer/blob/master/rollup.config.js) (Rollup build)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser application"]
  node_entry["Browser entry<br/>HTML / JS entry<br/>[index.html]"]
  node_main["Svelte bootstrap<br/>application entry<br/>[main.js]"]
  node_app["App coordinator<br/>Svelte root<br/>[App.svelte]"]
  node_navigation["Header and config<br/>navigation<br/>[Header.svelte]"]
  node_explainer["Explainer composition<br/>presentation coordinator<br/>[Explainer.svelte]"]
  node_stores[("Shared reactive state<br/>Svelte stores<br/>[stores.js]")]
  node_overview["Network overview<br/>interactive Svelte view<br/>[Overview.svelte]"]
  node_overview_rendering["Overview rendering<br/>drawing modules<br/>[overview-draw.js]"]
  node_overview_modal["Overview modal<br/>contextual overlay<br/>[Modal.svelte]"]
  node_detail_views["Operation detail views<br/>Svelte panels"]
  node_hyperparameter_views["Hyperparameter interaction<br/>Svelte panels and animation"]
  node_article["Article and media<br/>instructional content<br/>[Article.svelte]"]
end

subgraph group_cnn["CNN runtime"]
  node_cnn_integration{{"CNN integration<br/>browser inference<br/>[cnn-tf.js]"}}
  node_model_artifacts[("Packaged model artifacts<br/>static model data<br/>[model.json]")]
end

subgraph group_training["Model provenance"]
  node_training_project["Tiny VGG training<br/>Python/TensorFlow project<br/>[tiny-vgg.py]"]
end

subgraph group_delivery["Build and delivery"]
  node_build{{"Rollup build<br/>build orchestration<br/>[rollup.config.js]"}}
  node_ci["GitHub Actions build<br/>CI workflow<br/>[build.yml]"]
  node_static_site["Static hosting<br/>deployment target<br/>[deploy-gh-page.sh]"]
end

node_entry -->|"loads"| node_main
node_main -->|"mounts"| node_app
node_app -->|"renders"| node_navigation
node_app -->|"renders"| node_explainer
node_explainer -->|"shows overview"| node_overview
node_explainer -->|"shows selected operation"| node_detail_views
node_explainer -->|"presents narrative"| node_article
node_overview -->|"draws with"| node_overview_rendering
node_overview -->|"opens"| node_overview_modal
node_overview -->|"updates selection"| node_stores
node_stores -->|"drives selected layer"| node_detail_views
node_detail_views -->|"includes"| node_hyperparameter_views
node_cnn_integration -->|"loads"| node_model_artifacts
node_cnn_integration -->|"provides CNN state"| node_stores
node_model_artifacts -.->|"produced by"| node_training_project
node_build -->|"packages"| node_entry
node_ci -->|"runs"| node_build
node_build -->|"publishes static assets"| node_static_site

click node_entry "https://github.com/poloclub/cnn-explainer/blob/master/public/index.html"
click node_main "https://github.com/poloclub/cnn-explainer/blob/master/src/main.js"
click node_app "https://github.com/poloclub/cnn-explainer/blob/master/src/App.svelte"
click node_navigation "https://github.com/poloclub/cnn-explainer/blob/master/src/Header.svelte"
click node_explainer "https://github.com/poloclub/cnn-explainer/blob/master/src/Explainer.svelte"
click node_stores "https://github.com/poloclub/cnn-explainer/blob/master/src/stores.js"
click node_overview "https://github.com/poloclub/cnn-explainer/blob/master/src/overview/Overview.svelte"
click node_overview_rendering "https://github.com/poloclub/cnn-explainer/blob/master/src/overview/overview-draw.js"
click node_overview_modal "https://github.com/poloclub/cnn-explainer/blob/master/src/overview/Modal.svelte"
click node_detail_views "https://github.com/poloclub/cnn-explainer/blob/master/src/detail-view/Convolutionview.svelte"
click node_hyperparameter_views "https://github.com/poloclub/cnn-explainer/blob/master/src/detail-view/Hyperparameterview.svelte"
click node_article "https://github.com/poloclub/cnn-explainer/blob/master/src/article/Article.svelte"
click node_cnn_integration "https://github.com/poloclub/cnn-explainer/blob/master/src/utils/cnn-tf.js"
click node_model_artifacts "https://github.com/poloclub/cnn-explainer/blob/master/public/assets/data/model.json"
click node_training_project "https://github.com/poloclub/cnn-explainer/blob/master/tiny-vgg/tiny-vgg.py"
click node_build "https://github.com/poloclub/cnn-explainer/blob/master/rollup.config.js"
click node_ci "https://github.com/poloclub/cnn-explainer/blob/master/.github/workflows/build.yml"
click node_static_site "https://github.com/poloclub/cnn-explainer/blob/master/deploy-gh-page.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_main,node_app,node_navigation,node_explainer,node_stores,node_overview,node_overview_rendering,node_overview_modal,node_detail_views,node_hyperparameter_views,node_article toneBlue
class node_cnn_integration,node_model_artifacts toneAmber
class node_training_project toneMint
class node_build,node_ci,node_static_site toneRose
```

## Components

### Browser application

Client-side Svelte explainer.

- [Browser entry](https://github.com/poloclub/cnn-explainer/blob/master/public/index.html): HTML / JS entry · `public/index.html`
- [Svelte bootstrap](https://github.com/poloclub/cnn-explainer/blob/master/src/main.js): application entry · `src/main.js`
- [App coordinator](https://github.com/poloclub/cnn-explainer/blob/master/src/App.svelte): Svelte root · Assembles navigation and explainer views. · `src/App.svelte`
- [Header and config](https://github.com/poloclub/cnn-explainer/blob/master/src/Header.svelte): navigation · `src/Header.svelte`
- [Explainer composition](https://github.com/poloclub/cnn-explainer/blob/master/src/Explainer.svelte): presentation coordinator · Combines interactive and educational content. · `src/Explainer.svelte`
- [Shared reactive state](https://github.com/poloclub/cnn-explainer/blob/master/src/stores.js): Svelte stores · Coordinates selection, features, and detail panels. · `src/stores.js`
- [Network overview](https://github.com/poloclub/cnn-explainer/blob/master/src/overview/Overview.svelte): interactive Svelte view · CNN pipeline navigation and layer selection. · `src/overview/Overview.svelte`
- [Overview rendering](https://github.com/poloclub/cnn-explainer/blob/master/src/overview/overview-draw.js): drawing modules · Draws network geometry and intermediate representations. · `src/overview/overview-draw.js`
- [Overview modal](https://github.com/poloclub/cnn-explainer/blob/master/src/overview/Modal.svelte): contextual overlay · `src/overview/Modal.svelte`
- [Operation detail views](https://github.com/poloclub/cnn-explainer/blob/master/src/detail-view/Convolutionview.svelte): Svelte panels · Convolution, activation, pooling, softmax, and kernel math explanations. · `src/detail-view/Convolutionview.svelte`
- [Hyperparameter interaction](https://github.com/poloclub/cnn-explainer/blob/master/src/detail-view/Hyperparameterview.svelte): Svelte panels and animation · `src/detail-view/Hyperparameterview.svelte`
- [Article and media](https://github.com/poloclub/cnn-explainer/blob/master/src/article/Article.svelte): instructional content · Narrative concepts and embedded video. · `src/article/Article.svelte`

### CNN runtime

Packaged inference and visualization data.

- [CNN integration](https://github.com/poloclub/cnn-explainer/blob/master/src/utils/cnn-tf.js): browser inference · Loads packaged model data and exposes CNN computations. · `src/utils/cnn-tf.js`
- [Packaged model artifacts](https://github.com/poloclub/cnn-explainer/blob/master/public/assets/data/model.json): static model data · TensorFlow model, weights, and network visualization data. · `public/assets/data/model.json`

### Model provenance

Separate Tiny VGG training project.

- [Tiny VGG training](https://github.com/poloclub/cnn-explainer/blob/master/tiny-vgg/tiny-vgg.py): Python/TensorFlow project · Offline training provenance; not browser runtime. · `tiny-vgg/tiny-vgg.py`

### Build and delivery

Static-site build and publishing.

- [Rollup build](https://github.com/poloclub/cnn-explainer/blob/master/rollup.config.js): build orchestration · Bundles the Svelte application into static assets. · `rollup.config.js`
- [GitHub Actions build](https://github.com/poloclub/cnn-explainer/blob/master/.github/workflows/build.yml): CI workflow · `.github/workflows/build.yml`
- [Static hosting](https://github.com/poloclub/cnn-explainer/blob/master/deploy-gh-page.sh): deployment target · GitHub Pages-compatible published assets. · `deploy-gh-page.sh`

## Connections

- Browser entry → Svelte bootstrap: loads
- Svelte bootstrap → App coordinator: mounts
- App coordinator → Header and config: renders
- App coordinator → Explainer composition: renders
- Explainer composition → Network overview: shows overview
- Explainer composition → Operation detail views: shows selected operation
- Explainer composition → Article and media: presents narrative
- Network overview → Overview rendering: draws with
- Network overview → Overview modal: opens
- Network overview → Shared reactive state: updates selection
- Shared reactive state → Operation detail views: drives selected layer
- Operation detail views → Hyperparameter interaction: includes
- CNN integration → Packaged model artifacts: loads
- CNN integration → Shared reactive state: provides CNN state
- Packaged model artifacts → Tiny VGG training: produced by
- Rollup build → Browser entry: packages
- GitHub Actions build → Rollup build: runs
- Rollup build → Static hosting: publishes static assets
