# scottschiller/soundmanager2 architecture

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

- Interactive diagram: https://gitdiagram.com/scottschiller/soundmanager2
- Repository: https://github.com/scottschiller/soundmanager2

## Overview

##### Project type and purpose
- This is an open-source JavaScript audio library (“SoundManager2”) that provides a unified API for HTML5 Audio and Flash fallback.
- It ships core JS modules, pre-compiled Flash SWFs (for legacy support), extensive demos and documentation, and a build pipeline to recompile both JS and SWF assets.

##### File structure
- Top-level directories:
- script/ – built JS artifacts (soundmanager2.js, .jsmin, nodebug builds)
- src/ – ActionScript sources (AS2, AS3) plus shell scripts/batch files to compile them
- swf/ – compiled SWF binaries (flash8, flash9, debug variants)
- demo/ – dozens of standalone HTML+CSS+JS demos showing widget/animation usage
- doc/ – documentation site (source, generated via docco, demos, getstarted, technotes)
- troubleshoot/ – debug tools & pages
- script/ & build.xml – Ant build file defining JS and SWF compilation tasks
- package.json, bower.json, component.json – package metadata
- Patterns:
- Facade/API layer in JS abstracts HTML5 vs. Flash
- Build pipeline orchestrated by Ant + Closure Compiler + MTASC + Flex SDK

##### README for additional insights
- Core features: load/play/pause/stop/mute/seek, events, HTML5-first with Flash fallback
- Build instructions: Ant targets for JS builds and SWF compilation (AS2 via MTASC, AS3 via mxmlc)
- Documentation & demos are first-class citizens, and the project is versioned by date tags.

##### Elements
- Blue for runtime modules
- Green for build-time tools
- Gray for demos/documentation

##### Detail
- Every essential piece: config files, build scripts, source directories, compiled outputs, and the multiple demo use-cases.

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Source Layer
  subgraph "Source Layer"
    SM2AS2["SoundManager2.as"]:::build
    MakeF8SH["make-flash8.sh"]:::build
    MakeF8BAT["make-flash8.bat"]:::build
    MakeF9SH["make-flash9.sh"]:::build
    MakeF9BAT["make-flash9.bat"]:::build
    SM2AS3["SoundManager2_AS3.as"]:::build
    SMSoundAS3["SoundManager2_SMSound_AS3.as"]:::build
    BuildXML["build.xml"]:::build
    PackageMeta["package.json\nbower.json\ncomponent.json"]:::build
  end

  %% Build Layer
  subgraph "Build Layer"
    Ant["Ant Build (build.xml)"]:::build
    Closure["Google Closure Compiler"]:::build
    MTASC["MTASC (AS2)"]:::build
    MXMLC["Flex SDK (mxmlc)"]:::build
  end

  %% Artifact Outputs
  subgraph "Compiled Artifacts"
    JSArtifacts["script/\n(soundmanager2.js, .jsmin,\nnodebug variants)"]:::runtime
    SWFBinaries["swf/\n(soundmanager2.swf,\n_debug, flash9 variants)"]:::runtime
  end

  %% Runtime Layer
  subgraph "Runtime Layer"
    SM2Core["SM2 JS Core API"]:::runtime
    HTML5Engine["HTML5 Audio Engine"]:::runtime
    FlashEngine["Flash SWF Engine"]:::runtime
  end

  %% Support Layer
  subgraph "Support Layer"
    Demos["demo/ (all demos)"]:::support
    DocsSite["doc/index.html\ngetstarted/\ntechnotes/"]:::support
    DocGen["doc/generated/"]:::support
    Troubleshoot["troubleshoot/"]:::support
  end

  %% Relationships
  SM2AS2 -->|compiles via MTASC| SWFBinaries
  MakeF8SH -->|script executes| SWFBinaries
  MakeF8BAT -->|script executes| SWFBinaries
  MakeF9SH -->|script executes| SWFBinaries
  MakeF9BAT -->|script executes| SWFBinaries
  SM2AS3 -->|compiles via MXMLC| SWFBinaries
  SMSoundAS3 -->|compiles via MXMLC| SWFBinaries
  BuildXML -->|orchestrates| Ant
  PackageMeta -->|metadata for| Ant

  Ant -->|invokes| Closure
  Ant -->|invokes| MTASC
  Ant -->|invokes| MXMLC

  Closure -->|produces| JSArtifacts
  MTASC -->|produces| SWFBinaries
  MXMLC -->|produces| SWFBinaries

  JSArtifacts -->|runtime load| SM2Core
  SM2Core -->|JS facade| HTML5Engine
  SM2Core -->|fallback| FlashEngine

  HTML5Engine -->|uses| HTML5Audio["Audio() API"]:::runtime
  FlashEngine -->|ExternalInterface| SWFBinaries

  JSArtifacts -->|used by| Demos
  JSArtifacts -->|documented in| DocGen
  DocGen -->|integrated into| DocsSite
  SWFBinaries -->|used by| Demos

  Demos -->|examples for| SM2Core
  DocsSite -->|guides for| SM2Core
  Troubleshoot -->|debug tools for| SM2Core

  %% Click Events
  click SM2AS2 "https://github.com/scottschiller/soundmanager2/blob/master/src/SoundManager2.as"
  click MakeF8SH "https://github.com/scottschiller/soundmanager2/blob/master/src/make-flash8.sh"
  click MakeF8BAT "https://github.com/scottschiller/soundmanager2/blob/master/src/make-flash8.bat"
  click MakeF9SH "https://github.com/scottschiller/soundmanager2/blob/master/src/make-flash9.sh"
  click MakeF9BAT "https://github.com/scottschiller/soundmanager2/blob/master/src/make-flash9.bat"
  click SM2AS3 "https://github.com/scottschiller/soundmanager2/blob/master/src/SoundManager2_AS3.as"
  click SMSoundAS3 "https://github.com/scottschiller/soundmanager2/blob/master/src/SoundManager2_SMSound_AS3.as"
  click BuildXML "https://github.com/scottschiller/soundmanager2/blob/master/build.xml"
  click JSArtifacts "https://github.com/scottschiller/soundmanager2/blob/master/script/soundmanager2.js"
  click SWFBinaries "https://github.com/scottschiller/soundmanager2/blob/master/swf/soundmanager2.swf"
  click PackageMeta "https://github.com/scottschiller/soundmanager2/blob/master/package.json"
  click Demos "https://github.com/scottschiller/soundmanager2/tree/master/demo/"
  click DocsSite "https://github.com/scottschiller/soundmanager2/blob/master/doc/index.html"
  click DocGen "https://github.com/scottschiller/soundmanager2/tree/master/doc/generated/"
  click Troubleshoot "https://github.com/scottschiller/soundmanager2/blob/master/troubleshoot/index.html"

  %% Styles
  classDef runtime fill:#add8e6,stroke:#000;
  classDef build fill:#90ee90,stroke:#000;
  classDef support fill:#d3d3d3,stroke:#000;
```
