# m-lab/mlab-speedtest architecture

> Architecture diagram of the GitHub repository m-lab/mlab-speedtest, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/m-lab/mlab-speedtest
- Repository: https://github.com/m-lab/mlab-speedtest

## Overview

This repo is a **static web application** (HTML/CSS/vanilla JS) that implements **https://speed.measurementlab.net/**. It is **built with Node-based build scripts** into a `dist/` directory and **deployed to Firebase Hosting via GitHub Actions**.

So the “system” here is not a multi-service backend; it’s primarily:
- a **client-side app** running in the browser
- a **build pipeline** that generates deployable static assets
- a **CI/CD pipeline** that deploys to **Firebase Hosting**
- a **localization workflow** (PO → JSON) used at build time + dynamic language selection at runtime

- Build-time vs runtime responsibilities
- Hosting / CDN layer (Firebase Hosting)
- Where translations come from and how they are consumed
- Deployment environments (Sandbox vs Production) and triggers

##### Top-level
- `src/` – authoritative source for the website: HTML, CSS, JS, assets
- `scripts/` – build tooling:
- `scripts/build.js` – likely orchestrates building `dist/` (copying assets, bundling/minifying if any, generating translation outputs, etc.)
- `scripts/po-to-json.js` – converts `translations/languages/*.po` → JSON for runtime consumption
- `translations/`
- `translations/source/application.pot` – translation template
- `translations/languages/*.po` – language files imported from Transifex
- Firebase hosting config:
- `firebase.json`, `.firebaserc` – hosting targets/projects, rewrites, etc.
- CI/CD:
- `.github/workflows/firebase-hosting-merge.yml` – deploy on merge to `main` (Production)
- `.github/workflows/firebase-hosting-pull-request.yml` – deploy preview (Sandbox)
- `package.json`, `package-lock.json` – Node toolchain (build dependencies, scripts)

##### `src/`
- `src/index.html`, `src/404.html` – entry + error page
- `src/css/main.css` + `src/css/images/` – styling assets
- `src/assets/fonts`, `src/assets/images` – static assets
- `src/js/`
- `app.js` – main app wiring
- `gauge.js` – likely the speed gauge visualization component
- `i18n.js` – runtime language selection/loading translated strings

##### README-derived architecture and flows to capture
Key runtime behavior:
- The built site runs from `dist/` and is served statically (locally via `python3 -m http.server -d dist`).
- Localization:
- build converts `.po` → JSON in `dist/translations/`
- runtime `i18n.js` selects language via:
- `?lang=` query param
- `localStorage`
- browser preference

Key deployment behavior:
- **GitHub Actions → Firebase Hosting**
- PR (same repo) → **Sandbox** (`https://mlab-sandbox.web.app`)
- merge to `main` → **Production** (`https://speed.measurementlab.net`)

External dependency worth showing explicitly:
- **Transifex (OTF Localization Lab)** as the upstream translation management system (even though it’s not automated in this repo, it’s a real dependency in the overall system lifecycle).

##### Runtime (Browser + Hosting)

This will prevent the common mistake of treating build scripts as runtime services.

##### Development / Source
- **Developer workstation**
- runs `npm install`, `npm run build`
- **Repo source tree**
- `src/` (HTML/CSS/JS/assets)
- `translations/languages/*.po`
- `scripts/*.js`
- `firebase.json` / `.firebaserc`
- **Transifex (external)**
- produces `.po` files that get downloaded and committed into `translations/languages/`

##### Build (local + CI)
- **Node.js build pipeline**
- `scripts/build.js`
- `scripts/po-to-json.js`
- **Build output: `dist/`**
- static site assets
- `dist/translations/*.json` (derived artifacts)

##### Deploy + Hosting
- **GitHub Actions**
- PR workflow → deploy to Firebase Hosting (Sandbox)
- merge workflow → deploy to Firebase Hosting (Production)
- **Firebase Hosting**
- serves `dist/` as static hosting for each environment/URL

##### Runtime (what happens in the user’s browser)
- **User browser**
- loads `index.html`, CSS, JS
- **App modules**
- `app.js` (app initialization / test orchestration)
- `gauge.js` (UI viz)
- `i18n.js` (language selection + fetch translation JSON)
- **Browser state**
- `localStorage` (language persistence)
- URL query `?lang=` (override)
- `navigator.language` (fallback)

- **Static site architecture**: all runtime logic executes client-side; hosting serves static artifacts.
- **Build artifact separation**: `src/` and `translations/` are inputs; `dist/` is the deployable output.
- **Internationalization pipeline**:
- build-time conversion (PO → JSON)
- runtime language negotiation (query param → localStorage → browser preference)
- **Environment-based deployment**:
- same artifact type deployed to two Firebase Hosting targets/environments
- deployments gated by GitHub Actions triggers

##### Labels (be explicit)
- “scripts/po-to-json.js”
- “scripts/build.js”
- “src/js/i18n.js”
- “Firebase Hosting (Sandbox: mlab-sandbox.web.app)”
- “Firebase Hosting (Prod: speed.measurementlab.net)”

- “build step”
- “deploy artifact”
- “HTTP GET static assets”
- “HTTP GET translations JSON”
- “language selection precedence”

Use this as the initial layout (then refine with exact filenames/paths):

- **External**: Transifex
→ **translations/languages/*.po** (repo)

- **Repo**: `src/**`, `scripts/**`, `translations/**`, `firebase.json`
→ **Node Build (scripts/build.js + scripts/po-to-json.js)**
→ **Artifact: dist/** (includes dist/translations/*.json)

- **CI/CD**:
- GitHub Actions PR workflow → Firebase Hosting (Sandbox)
- GitHub Actions merge workflow → Firebase Hosting (Production)

- **Runtime**:
- User Browser ←(HTTP)→ Firebase Hosting
- Browser loads `app.js`, `gauge.js`, `i18n.js`
- `i18n.js` reads `?lang=`, `localStorage`, `navigator.language`
- `i18n.js` fetches `dist/translations/<lang>.json`

That’s the “most components possible” breakdown without inventing services that aren’t present.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% =========================
    %% LAYER 1: Development / Source (Git repo)
    %% =========================
    subgraph "Development / Source (Git repo)"
        DEV["Developer Workstation"]:::actor

        subgraph "Repo Contents"
            PKG["Node toolchain (package.json)"]:::config
            LOCK["Dependency lock (package-lock.json)"]:::config

            subgraph "Client source (src/)"
                HTML["UI shell (index.html)"]:::source
                E404["Error page (404.html)"]:::source

                CSS["Styling (main.css)"]:::source
                CSSIMG["CSS images (src/css/images/)"]:::asset
                IMG["Static images (src/assets/images/)"]:::asset
                FONTS["Static fonts (src/assets/fonts/)"]:::asset

                APP["App wiring (src/js/app.js)"]:::source
                GAUGE["Gauge visualization (src/js/gauge.js)"]:::source
                I18N["Runtime i18n (src/js/i18n.js)"]:::source
            end

            subgraph "Localization sources (translations/)"
                POT["Translation template (application.pot)"]:::i18n
                PO["Language PO files (translations/languages/)"]:::i18n
            end

            subgraph "Build scripts (scripts/)"
                BUILD["Build orchestrator (scripts/build.js)"]:::build
                PO2JSON["PO→JSON converter (scripts/po-to-json.js)"]:::build
            end

            FBCONF["Firebase Hosting config (firebase.json)"]:::config
            FBRC["Firebase targets/projects (.firebaserc)"]:::config

            subgraph "CI/CD workflows (.github/workflows/)"
                GH_PR["PR deploy workflow (firebase-hosting-pull-request.yml)"]:::cicd
                GH_MERGE["Main merge deploy workflow (firebase-hosting-merge.yml)"]:::cicd
            end
        end

        TX["Transifex (OTF Localization Lab)"]:::external
    end

    %% =========================
    %% LAYER 2: Build (local + CI)
    %% =========================
    subgraph "Build (local + CI)"
        NODE["Node.js build pipeline"]:::build
        DIST["Build artifact (dist/)"]:::artifact
        DIST_I18N["dist/translations/*.json"]:::artifact
        DIST_SITE["dist/** (HTML/CSS/JS/assets)"]:::artifact
    end

    %% =========================
    %% LAYER 3: Deploy (CI/CD) + Hosting
    %% =========================
    subgraph "Deploy (CI/CD) + Hosting"
        GHA["GitHub Actions runners"]:::cicd

        subgraph "Firebase Hosting"
            FBSBX["Sandbox Hosting (mlab-sandbox.web.app)"]:::cloud
            FBPROD["Production Hosting (speed.measurementlab.net)"]:::cloud
        end
    end

    %% =========================
    %% LAYER 4: Runtime (Browser)
    %% =========================
    subgraph "Runtime (User Browser)"
        USER["User"]:::actor
        BROWSER["Browser (client-side runtime)"]:::runtime

        subgraph "Loaded modules"
            R_APP["app.js"]:::runtime
            R_GAUGE["gauge.js"]:::runtime
            R_I18N["i18n.js"]:::runtime
        end

        QS["URL query (?lang=)"]:::state
        LS["localStorage"]:::state
        NAV["navigator.language"]:::state
    end

    %% =========================
    %% Build-time flows
    %% =========================
    TX -->|"manual_download/commit"| PO
    DEV -->|"npm_install/build"| NODE

    PKG -->|"defines_scripts/deps"| NODE
    LOCK -->|"pins_deps"| NODE

    BUILD -->|"orchestrates"| NODE
    PO2JSON -->|"converts"| NODE

    PO -->|"input"| PO2JSON
    POT -->|"template_reference"| PO

    HTML -->|"input"| BUILD
    E404 -->|"input"| BUILD
    CSS -->|"input"| BUILD
    CSSIMG -->|"input"| BUILD
    IMG -->|"input"| BUILD
    FONTS -->|"input"| BUILD
    APP -->|"input"| BUILD
    GAUGE -->|"input"| BUILD
    I18N -->|"input"| BUILD

    NODE -->|"build_step"| DIST
    PO2JSON -->|"build_step"| DIST_I18N
    BUILD -->|"build_step"| DIST_SITE
    DIST_I18N -->|"part_of"| DIST
    DIST_SITE -->|"part_of"| DIST

    %% =========================
    %% Deploy-time flows
    %% =========================
    GH_PR -->|"trigger:pull_request"| GHA
    GH_MERGE -->|"trigger:merge_to_main"| GHA

    FBCONF -->|"used_by_deploy"| GHA
    FBRC -->|"used_by_deploy"| GHA

    GHA -->|"deploy_artifact"| FBSBX
    GHA -->|"deploy_artifact"| FBPROD
    DIST -->|"uploaded_as_static_assets"| FBSBX
    DIST -->|"uploaded_as_static_assets"| FBPROD

    %% =========================
    %% Runtime flows
    %% =========================
    USER -->|"uses"| BROWSER
    BROWSER -->|"HTTP_GET:/index.html+assets"| FBPROD
    BROWSER -->|"HTTP_GET:/index.html+assets"| FBSBX

    BROWSER -->|"loads"| R_APP
    BROWSER -->|"loads"| R_GAUGE
    BROWSER -->|"loads"| R_I18N

    R_APP <-->|"renders/updates"| R_GAUGE

    R_I18N -->|"lang_precedence:queryparam"| QS
    R_I18N -->|"lang_precedence:localStorage"| LS
    R_I18N -->|"lang_precedence:navigator"| NAV

    R_I18N -->|"HTTP_GET:/translations/<lang>.json"| FBPROD
    R_I18N -->|"HTTP_GET:/translations/<lang>.json"| FBSBX
    R_I18N -->|"stores_selected_lang"| LS

    %% =========================
    %% Click events (component mapping)
    %% =========================
    click HTML "https://github.com/m-lab/mlab-speedtest/blob/main/src/index.html"
    click E404 "https://github.com/m-lab/mlab-speedtest/blob/main/src/404.html"
    click CSS "https://github.com/m-lab/mlab-speedtest/blob/main/src/css/main.css"
    click CSSIMG "https://github.com/m-lab/mlab-speedtest/tree/main/src/css/images/"
    click IMG "https://github.com/m-lab/mlab-speedtest/tree/main/src/assets/images/"
    click FONTS "https://github.com/m-lab/mlab-speedtest/tree/main/src/assets/fonts/"
    click APP "https://github.com/m-lab/mlab-speedtest/blob/main/src/js/app.js"
    click GAUGE "https://github.com/m-lab/mlab-speedtest/blob/main/src/js/gauge.js"
    click I18N "https://github.com/m-lab/mlab-speedtest/blob/main/src/js/i18n.js"
    click BUILD "https://github.com/m-lab/mlab-speedtest/blob/main/scripts/build.js"
    click PO2JSON "https://github.com/m-lab/mlab-speedtest/blob/main/scripts/po-to-json.js"
    click POT "https://github.com/m-lab/mlab-speedtest/blob/main/translations/source/application.pot"
    click PO "https://github.com/m-lab/mlab-speedtest/tree/main/translations/languages/"
    click GH_MERGE "https://github.com/m-lab/mlab-speedtest/blob/main/.github/workflows/firebase-hosting-merge.yml"
    click GH_PR "https://github.com/m-lab/mlab-speedtest/blob/main/.github/workflows/firebase-hosting-pull-request.yml"
    click FBCONF "https://github.com/m-lab/mlab-speedtest/blob/main/firebase.json"
    click FBRC "https://github.com/m-lab/mlab-speedtest/blob/main/.firebaserc"
    click PKG "https://github.com/m-lab/mlab-speedtest/blob/main/package.json"
    click LOCK "https://github.com/m-lab/mlab-speedtest/blob/main/package-lock.json"

    %% =========================
    %% Styles
    %% =========================
    classDef actor fill:#0ea5e9,stroke:#075985,color:#ffffff,stroke-width:1px
    classDef source fill:#60a5fa,stroke:#1d4ed8,color:#0b1220,stroke-width:1px
    classDef asset fill:#93c5fd,stroke:#1d4ed8,color:#0b1220,stroke-width:1px
    classDef build fill:#fb923c,stroke:#9a3412,color:#0b1220,stroke-width:1px
    classDef artifact fill:#fcd34d,stroke:#92400e,color:#0b1220,stroke-width:1px
    classDef cicd fill:#a78bfa,stroke:#5b21b6,color:#0b1220,stroke-width:1px
    classDef cloud fill:#d1d5db,stroke:#374151,color:#111827,stroke-width:1px
    classDef runtime fill:#22c55e,stroke:#166534,color:#0b1220,stroke-width:1px
    classDef state fill:#34d399,stroke:#065f46,color:#0b1220,stroke-width:1px
    classDef i18n fill:#f472b6,stroke:#9d174d,color:#0b1220,stroke-width:1px
    classDef config fill:#fca5a5,stroke:#991b1b,color:#0b1220,stroke-width:1px
    classDef external fill:#9ca3af,stroke:#374151,color:#111827,stroke-width:1px
```
