How alexlenail/nn-svg works
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