How navigraph/msfs-navigation-data-interface works
Main Components
• WASM Module – (located in src/wasm): This component is built with Rust and handles downloading the navigation database file, interfacing via the commbus to communicate with the gauge, and providing the runtime functionality for the MSFS simulation. It includes modules such as the dispatcher, network helpers, download (with zip_handler), and JSON struct serializers.
• Database Layer – (located in src/database): A pure Rust implementation that manages interfacing with the DFD SQLite-based navigation data. This module encapsulates functions for executing SQL queries and handling data output (such as airport, airspace, airway, procedures, etc.).
• JavaScript Interface – (located in src/js): Provides a wrapper for invoking functionality from both the WASM module and potentially the Rust database. This component integrates with the CommBus API used by MSFS gauges, enabling JS code to trigger events (e.g., “NAVIGRAPH_CallFunction”) and listen for results.
• Examples & Demonstration Components – (examples/aircraft and examples/gauge): These sample implementations demonstrate how to integrate the interface components (both gauge UI elements and the aircraft panel integration) into an actual MSFS project.
• Build & Deployment Tools – (scripts, Cargo/TOML configuration files, Dockerfile, GitHub workflows): Although more on the operational side, these indicate how the project is built, tested, and integrated into CI/CD pipelines.
Relationships and Interactions
• The MSFS environment (or the aircraft panel) interacts with the WASM module (via the gauge configuration in Panel.cfg) using the CommBus event API.
• The WASM module communicates with the Rust Database layer by using the shared logic to process the DFD SQLite file. Although the database module is separate, it is conceptually “plugged into” the WASM module for handling SQL queries.
• The JavaScript interface layer acts as an alternative or complementary abstraction that exposes commands such as “GetAirport” or “ExecuteSQLQuery” – these calls eventually route through the CommBus to the WASM module.
• There’s a clear data flow from the initial request (either from JS or directly from the gauge in the sim) to the WASM module, which then may call into the database routines to retrieve or update navigation data.
• External deployment or update flows exist to download/build the WASM module (as mentioned in the README) and then include it in the aircraft’s panel folder.
Architectural Patterns and Design Principles
• Modularity: The project separates concerns by isolating the database handling, WASM functionalities, and the JavaScript API.
• Dual Interface Support: It supports interactions via both native WebAssembly and JavaScript, with the common communication channel (CommBus) used for exchanging messages.
• Layered Architecture: At the bottom is the core database layer; above, we have WASM and JS wrappers; on the top layer, the simulation environment (MSFS) integrates through panels and gauges.
• Event-Driven Communication: Emphasize the use of the CommBus for initiating function calls and receiving asynchronous responses.
Incorporate Relevant Technologies
• Rust/Cargo – for the core modules (database and WASM)
• WebAssembly (WASM) – for running performance-critical code within MSFS
• JavaScript and Node.js – wrapping and building the JS interface layer, along with tools like ESLint, TypeScript, and Rollup.
• SQLite (via DFD format) – as the underlying format for navigation data persistence.
• Docker, GitHub Actions CI/CD – (as indicated by Dockerfile, .github/workflows) tools for building and testing.
• CommBus API – the simulation-specific communication mechanism linking the gauge (whether JS or WASM) to the flight simulation environment.