# navigraph/cargo-msfs architecture

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

- Interactive diagram: https://gitdiagram.com/navigraph/cargo-msfs
- Repository: https://github.com/navigraph/cargo-msfs

## Overview

##### Project Type and Purpose
- Cargo MSFS is a **command-line utility** (Rust) for managing and building WASM modules targeted at Microsoft Flight Simulator (versions 2020 & 2024).
- Its primary functions are: installing/removing/updating the MSFS SDK, building Rust crates into WASM (invoking external tools), and reporting installed SDK info.

##### File Structure
- Top-level files:
- `action.yml`, `.github/workflows/test.yml`, `Dockerfile` → CI/CD and containerization.
- `Cargo.toml` → Rust project configuration & dependencies.
- `README.md`, `LICENSE.md` → documentation.
- `src/main.rs` → entry point and CLI parser.
- `src/sdk.rs` → SDK management logic (install/remove/update/info).
- No explicit “frontend” vs “backend” layers—this is a single binary with internal modules.

##### README for Insights
- External dependencies:
- Clang 17 (must be present on host).
- `wasm-opt` (invoked automatically during `build`).
- Command hierarchy: `install`, `remove`, `update`, `build`, `info`.
- Flags: `--in-folder`, `--out-wasm`.

##### Main Components to Highlight
a. **CLI Interface** (main.rs)
- Arg parsing (StructOpt/clap).
- Dispatch to command handlers.
b. **Command Dispatcher / Controller**
- Implements the Command pattern—maps user commands to internal operations.
c. **SDK Manager Module** (sdk.rs)
- install(), remove(), update(), info() sub-functions.
- Handles downloads/unpacks, file-system operations (e.g., where SDKs live).
d. **Build Engine**
- Orchestrates:
- Invoking `cargo build --release` with WASM target.
- Invoking `wasm-opt` for post-processing.
- Accepts input folder & output path.
e. **External Tools / Dependencies**
- **Clang 17** (system tool)
- **wasm-opt** (from Binaryen)
- **Cargo/Rust toolchain**
f. **File System / SDK Storage**
- Directory where MSFS SDKs are installed.
- Crate source & output WASM file paths.
g. **CI/CD & Containerization** (optional)
- GitHub Actions workflow.
- Dockerfile for packaging/testing.

##### Relationships & Data Flow
- **User** → CLI Interface (stdin/args)
- CLI → Command Dispatcher →
- If SDK command: → SDK Manager → File System / Network (download)
- If build command: → Build Engine → External Tools → File System
- If info: → SDK Manager → Read File System → CLI (stdout)

##### Architectural Patterns & Design Principles
- **Command Pattern**: each Cargo MSFS subcommand is encapsulated in its own handler.
- **Single Responsibility**: `main.rs` only parses and routes commands; `sdk.rs` only manages SDK.
- **Modular Design**: future commands (e.g., packaging) can be added as new modules.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Actor
    U["User"]:::actor
    U -->|"cargo-msfs <cmd>"| CLI["CLI Interface\n(src/main.rs)"]:::module

    %% Internal Modules
    CLI -->|"install/remove/update/info"| SK["SDK Manager\n(src/sdk.rs)"]:::module
    CLI -->|"build"| BE["Build Engine"]:::module

    %% SDK Manager interactions
    SK -->|"download SDK"| NW["Network"]:::external
    SK -->|"store SDK"| FS["SDK Storage\n(File System)"]:::storage
    SK -->|"read SDK info"| FS

    %% Build Engine interactions
    BE -->|"invoke Cargo build"| CT["Clang 17"]:::external
    BE -->|"invoke wasm-opt"| WO["wasm-opt"]:::external
    BE -->|"write .wasm"| FS

    %% Project Configuration & Documentation
    subgraph "Project Artifacts"
        CFG["Cargo.toml"]:::config
        README["README.md"]:::docs
        LICENSE["LICENSE.md"]:::docs
    end

    %% CI/CD & Containerization
    subgraph "CI/CD & Containerization"
        GH["GitHub Actions\n(.github/workflows/test.yml)"]:::cicd
        DOCK["Dockerfile"]:::cicd
        ACT["action.yml"]:::cicd
    end

    %% Click Events
    click CLI "https://github.com/navigraph/cargo-msfs/blob/main/src/main.rs"
    click SK "https://github.com/navigraph/cargo-msfs/blob/main/src/sdk.rs"
    click CFG "https://github.com/navigraph/cargo-msfs/blob/main/Cargo.toml"
    click GH "https://github.com/navigraph/cargo-msfs/blob/main/.github/workflows/test.yml"
    click DOCK "https://github.com/navigraph/cargo-msfs/tree/main/Dockerfile"
    click ACT "https://github.com/navigraph/cargo-msfs/blob/main/action.yml"
    click README "https://github.com/navigraph/cargo-msfs/blob/main/README.md"
    click LICENSE "https://github.com/navigraph/cargo-msfs/blob/main/LICENSE.md"

    %% Styles
    classDef actor fill:#F0F0F0,stroke:#333,stroke-width:1px
    classDef module fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef external fill:#90EE90,stroke:#333,stroke-width:1px
    classDef storage fill:#FFD700,stroke:#333,stroke-width:1px
    classDef cicd fill:#FFA500,stroke:#333,stroke-width:1px
    classDef config fill:#E6E6FA,stroke:#333,stroke-width:1px
    classDef docs fill:#FFEFD5,stroke:#333,stroke-width:1px
```
