Bootstrap System
"/home/yossef/notes/git/projects/maplibra/modules/Bootstrap System.md"
path: maplibra/modules/Bootstrap System.md
- **fileName**: Bootstrap System
- **Created on**: 2026-06-16 00:48:42
Bootstrap System
Purpose: Orchestrates startup from shell initialization through lazy feature loading.
Related: ../Home.md, ../Architecture.md, ./MVF Loading.md, ./Asset System.md, ../flows/Startup Sequence.md
What It Does
The bootstrap system is a staged pipeline that brings the app from an empty page to an interactive map while deferring heavy work. It is implemented across src/bootstrap/ and coordinated by script.js.
Bootstrap Stages
1. Shell Bootstrap (src/bootstrap/bootstrap-shell.js)
- Initializes theme (light/dark) and applies it to the document
- Sets up global error handling (
ErrorHandler+ErrorToast) - Registers service worker (production only)
- Fixes mobile viewport height (
--app-heightCSS variable)
2. Map Bootstrap (src/bootstrap/bootstrap-map.js)
- Creates the Mapbox GL map instance
- Creates
LayerManagerbound to the map - Creates
UIManagerbound to map + layer manager
3. Data Bootstrap (src/bootstrap/bootstrap-data.js)
- Calls
initApp()(the main app initialization inscript.js) - Stores the app handle for later startup phases
- Exposes
attachDerivedAssetsandprimeMapExperience
4. Deferred Bootstraps
- Routing (
src/bootstrap/bootstrap-routing.js): Lazy-loadsPathfindingControlleronly when needed - Search (
src/bootstrap/bootstrap-search.js): Lazy-loadsSearchBoxon first interaction - Debug (
src/bootstrap/bootstrap-debug.js): Lazy-loads debug layers when requested
App Context
src/bootstrap/create-app-context.js creates a shared context object passed through all stages:
perf— startup performance marks and measurestelemetry— rollout telemetry (opt-in)rollout— requested vs active routing engine and graph formatflags— startup readiness state (routingReady, searchReady, debugReady)services— mutable registry of created instances (map, uiManager, layerManager, pathfindingController, searchBox)
Performance Budget
src/bootstrap/perf-budget.js defines startup time budgets and warns when exceeded.
Rollout Telemetry
src/bootstrap/rollout-telemetry.js provides a fire-and-forget telemetry sink for routing engine fallback and startup performance events. Delivery order: navigator.sendBeacon → fetch({ keepalive: true }) → silent drop.
Runtime Flags
src/bootstrap/runtime-flags.js parses URL query parameters for routing configuration:
routing.engine=js|wasmgraph.format=json|binrouting.telemetry=1|truerouting.wasmParity=1|truerouting.spatialKernel=1|truerouting.spatialParity=1|true
Important Files
src/bootstrap/bootstrap-shell.jssrc/bootstrap/bootstrap-map.jssrc/bootstrap/bootstrap-data.jssrc/bootstrap/bootstrap-routing.jssrc/bootstrap/bootstrap-search.jssrc/bootstrap/bootstrap-debug.jssrc/bootstrap/create-app-context.jssrc/bootstrap/startup-perf.jssrc/bootstrap/runtime-flags.jssrc/bootstrap/rollout-telemetry.jssrc/bootstrap/perf-budget.js
How It Connects
-
Shell → Map → Data → Deferred (routing, search, debug)
-
Each stage stores its output in
appContext.servicesso later stages can read it -
script.jscoordinates the entire flow and exposes the finalwindow.InGuideAPIcontinue:[[]]
before:[[]]