# alexlenail/nn-svg architecture

> Architecture diagram of the GitHub repository alexlenail/nn-svg, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alexlenail/nn-svg
- Repository: https://github.com/alexlenail/nn-svg

## Overview

##### Project type and purpose
- This is a static, client-side JavaScript library and demo site (“NN-SVG”) for programmatically generating neural-network schematics and exporting them as SVG.
- It provides three rendering modes:
- Fully-connected networks (FCNN.js + D3)
- Convolutional networks in LeNet style (LeNet.js + D3)
- Deep CNNs in AlexNet style (AlexNet.js + Three.js)

##### File structure
- Top-level HTML files (index.html, about.html, AlexNet.html, LeNet.html) and paper.* for documentation and examples.
- JavaScript modules:
- FCNN.js, LeNet.js – D3-based SVG generation
- AlexNet.js – Three.js 3D → SVG projection
- util.js – common layout utilities and parameter parsing
- SVGRenderer.js, Projector.js, OrbitControls.js – Three-JS support code
- fonts/ – typeface JSON and licensing for embedding text in SVG.
- README.md, LICENSE – project metadata.

##### Extract insights from the README
- Two rendering pipelines: D3 (2D) and Three.js (3D)

##### Main components
a. User Interface (Browser)
– HTML entry points (index.html, example pages)
– Configuration UI or code snippets loading parameter objects
b. Core Logic Layer
– Parameter parser (util.js)
– Architecture modules (FCNN.js, LeNet.js, AlexNet.js)
c. Rendering Engines
– D3.js (for FCNN + LeNet)
– Three.js (for AlexNet)
– Glue code: SVGRenderer.js, Projector.js, OrbitControls.js
d. Asset Layer
– fonts/helvetiker_regular.typeface.json
e. External Dependencies
– D3 library
– Three.js library
f. Output
– SVG DOM elements
– Downloadable .svg files

##### Relationships and data flows
- Core Logic → Rendering Engines (calls to D3 or Three.js APIs)
- Rendering Engines → DOM (injected SVG code)
- DOM → User Download (export SVG file)
- Util.js services both param parser and layout math for all modules

##### Architectural patterns and principles
- Modular design: each network type is its own module
- Single responsibility: util.js separates common utilities from rendering logic
- Pipeline pattern: parse → build scene graph → render → export
- Pluggable renderers: you could swap in a WebGL or Canvas backend

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Web Server"
        subgraph "UI Layer"
            INDEX[/"index.html"/]:::ui
            ABOUT[/"about.html"/]:::ui
            ALEXPAGE[/"AlexNet.html"/]:::ui
            LENETPAGE[/"LeNet.html"/]:::ui
        end
        subgraph "Core Logic Layer"
            UTIL["util.js"]:::core
            FCNN["FCNN.js"]:::core
            LENETMOD["LeNet.js"]:::core
            ALEXMOD["AlexNet.js"]:::core
        end
        subgraph "Rendering Engines"
            SVGREND["SVGRenderer.js"]:::render
            PROJ["Projector.js"]:::render
            ORB["OrbitControls.js"]:::render
        end
        subgraph "Assets & Documentation"
            FONTJSON["fonts/helvetiker_regular.typeface.json"]:::asset
            FONTLIC["fonts/LICENSE"]:::asset
            FONTREAD["fonts/README"]:::asset
            READMEMD["README.md"]:::asset
            LICENSEF["LICENSE"]:::asset
            PAPERMD["paper.md"]:::asset
            PAPERBIB["paper.bib"]:::asset
            PAPERPDF["paper.pdf"]:::asset
        end
    end
    subgraph "External Dependencies"
        D3["D3.js"]:::ext
        THREE["Three.js"]:::ext
    end

    %% UI to Core Logic
    INDEX -->|loads parameters| UTIL
    ABOUT -->|loads parameters| UTIL
    ALEXPAGE -->|loads parameters| UTIL
    LENETPAGE -->|loads parameters| UTIL

    %% Core Logic to Network Modules
    UTIL --> FCNN
    UTIL --> LENETMOD
    UTIL --> ALEXMOD

    %% Network Modules to Renderers
    FCNN --> SVGREND
    LENETMOD --> SVGREND
    ALEXMOD --> PROJ
    ALEXMOD --> ORB

    %% Glue between External Deps and Renderers
    D3 --> SVGREND
    THREE --> PROJ
    THREE --> ORB

    %% Renderers to Output
    SVGREND --> SVGDOM[/ "SVG DOM elements" /]:::io
    PROJ --> SVGDOM
    ORB --> SVGDOM
    SVGDOM --> DL[/ "Downloadable .svg file" /]:::io

    %% Click events
    click INDEX "https://github.com/alexlenail/nn-svg/blob/master/index.html"
    click ABOUT "https://github.com/alexlenail/nn-svg/blob/master/about.html"
    click ALEXPAGE "https://github.com/alexlenail/nn-svg/blob/master/AlexNet.html"
    click LENETPAGE "https://github.com/alexlenail/nn-svg/blob/master/LeNet.html"
    click UTIL "https://github.com/alexlenail/nn-svg/blob/master/util.js"
    click FCNN "https://github.com/alexlenail/nn-svg/blob/master/FCNN.js"
    click LENETMOD "https://github.com/alexlenail/nn-svg/blob/master/LeNet.js"
    click ALEXMOD "https://github.com/alexlenail/nn-svg/blob/master/AlexNet.js"
    click SVGREND "https://github.com/alexlenail/nn-svg/blob/master/SVGRenderer.js"
    click PROJ "https://github.com/alexlenail/nn-svg/blob/master/Projector.js"
    click ORB "https://github.com/alexlenail/nn-svg/blob/master/OrbitControls.js"
    click FONTJSON "https://github.com/alexlenail/nn-svg/blob/master/fonts/helvetiker_regular.typeface.json"
    click FONTLIC "https://github.com/alexlenail/nn-svg/tree/master/fonts/LICENSE"
    click FONTREAD "https://github.com/alexlenail/nn-svg/tree/master/fonts/README"
    click READMEMD "https://github.com/alexlenail/nn-svg/blob/master/README.md"
    click LICENSEF "https://github.com/alexlenail/nn-svg/tree/master/LICENSE"
    click PAPERMD "https://github.com/alexlenail/nn-svg/blob/master/paper.md"
    click PAPERBIB "https://github.com/alexlenail/nn-svg/blob/master/paper.bib"
    click PAPERPDF "https://github.com/alexlenail/nn-svg/blob/master/paper.pdf"

    %% Styles
    classDef ui fill:#add8e6,stroke:#000,stroke-width:1px
    classDef core fill:#90ee90,stroke:#000,stroke-width:1px
    classDef render fill:#ffcc99,stroke:#000,stroke-width:1px
    classDef asset fill:#d3d3d3,stroke:#000,stroke-width:1px
    classDef ext fill:#e0e0e0,stroke:#000,stroke-width:1px
    classDef io fill:#f4e1f1,stroke:#000,stroke-width:1px
```
