# afinn-s/toggleexternalview architecture

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

- Interactive diagram: https://gitdiagram.com/afinn-s/toggleexternalview
- Repository: https://github.com/afinn-s/toggleexternalview

## Overview

##### Project type and purpose (what you’re diagramming)
This repository is a **small native C++ X-Plane plugin** whose purpose is to **toggle the simulator’s external view**. Evidence:
- `src/ToggleExternalView.cpp` is the sole implementation file → single-purpose plugin logic.
- `subprojects/x-plane-sdk.wrap` → depends on the **X-Plane SDK** (XPLM/XPWidgets headers/libs).
- Build tooling present (`meson.build`, `src/meson.build`) while README shows a CMake+Ninja flow (likely alternative or outdated docs). Either way, it’s a compiled native binary loaded by X-Plane.

##### File-structure-driven architectural decomposition
Use the file tree to drive components (keep it “as many components as possible”, even if small):

##### Runtime (in-simulator) components
- **X-Plane Simulator Host Process**
- **Toggle External View Plugin (compiled binary)**
- **Plugin entrypoints / lifecycle** (typical X-Plane plugin pattern even if not visible in tree: start/stop/enable/disable)
- **Command / hotkey registration** (likely registers a command to toggle view)
- **View toggling logic** (the core behavior in `ToggleExternalView.cpp`)
- **SDK integration layer** (calls to XPLM APIs / datarefs / commands)
- **X-Plane SDK** (external dependency)
- XPLM (plugin manager, command system, datarefs, etc.)
- **User / Input Device**
- Triggers the toggle via keybinding/menu/command

- **Build system**
- Meson (`meson.build`, `src/meson.build`) and/or CMake (per README), with **Ninja** recommended
- **Toolchain**
- MSVC Build Tools on Windows (README prerequisite)
- Clang-format / VSCode settings are dev tooling (optional to include)
- **Third-party dependency retrieval**
- `subprojects/x-plane-sdk.wrap` (Meson wrap mechanism) → fetches/uses X-Plane SDK

##### Level 2 — Container / Runtime Composition (inside the host process)

**Inside “X-Plane Process” boundary**
- “Plugin Manager / Loader” (X-Plane internal)
- “Toggle External View Plugin (DLL/.xpl)” (this repo output)
- “Lifecycle entrypoints”
- “Command registration”
- “Toggle logic”
- “SDK calls”

**Key relationships**
- Loader → Plugin: loads binary, calls start/enable callbacks
- Plugin ↔ SDK: uses headers/libs; calls XPLM functions
- Command system → Plugin: callback invoked on user action

##### Level 3 — Build/Packaging/Deployment (from repo to simulator)

**Nodes**
- Developer machine
- Build system (Meson or CMake) + Ninja
- MSVC toolchain (Windows)
- X-Plane SDK (retrieved via Meson wrap)
- Output artifact: plugin binary (DLL/.xpl)
- Deployment target: X-Plane “plugins” directory

- Build system → Toolchain: compile/link
- Build system → X-Plane SDK: fetch/include/link
- Build output → X-Plane install: copy plugin binary into plugins folder
- X-Plane → Plugin: load at startup

This makes the architecture “complete” by showing how the dependency (`x-plane-sdk.wrap`) participates.

##### Architectural patterns to highlight (specific to this project)
Even though it’s small, it still uses important patterns typical of X-Plane plugins:

- **In-process plugin/module architecture**: the plugin is loaded into X-Plane’s address space.
- **Event/command-driven execution**: user action triggers a registered command callback; no “main server loop.”

Call these out with labels; principal engineers will care about these integration constraints.

##### What technologies to label explicitly (based on repo)
- Language: **C++**
- SDK: **X-Plane SDK (XPLM)**
- Build: **Meson** (from `meson.build`) and/or **CMake + Ninja** (from README)
- Platform note: **Windows MSVC Build Tools 2022** (README)

##### Diagramming rules (so it’s readable and “detailed without overthinking”)
Elements explicitly:

##### Clear labels
- Use exact repo-derived names where possible:
- “Toggle External View Plugin”
- “ToggleExternalView.cpp (toggle logic)”
- “x-plane-sdk.wrap (X-Plane SDK dependency)”

Examples:
- “register command”
- “command callback invoked”
- “read/write dataref” or “execute XPLM command”
- “load plugin binary”

##### Build/Dependency/Deployment (makes the repo structure explicit)

Given how small the code is, this is the best way to be “very detailed” without inventing internal subsystems that don’t exist.

## Diagram (Mermaid)

```mermaid
flowchart TD

%% =========================
%% RUNTIME: Context + In-process container
%% =========================
subgraph "Runtime (In-Simulator)"
direction TB

  User["User / Input Device\n(keybinding/menu/command)"]:::external

  subgraph "X-Plane Process (Host)"
  direction TB

    XPlane["X-Plane Simulator\nHost Process"]:::external

    Loader["Plugin Manager / Loader\n(X-Plane internal)"]:::external

    SDK["X-Plane SDK (XPLM)\nCommands / Datarefs / Callbacks"]:::thirdparty

    subgraph "Toggle External View Plugin (C++)"
    direction TB
      Plugin["Plugin Module\n(DLL/.xpl loaded in-process)"]:::repo
      Lifecycle["Plugin Lifecycle Entrypoints\n(start/stop/enable/disable)"]:::repo
      CmdReg["Command / Hotkey Registration"]:::repo
      Toggle["View Toggling Logic\n(ToggleExternalView.cpp)"]:::repo
      SDKLayer["SDK Integration Layer\n(XPLM API calls)"]:::repo
    end
  end

  %% Runtime flows
  User -->|"keypress/menu_action"| XPlane
  XPlane -->|"routes_input_event"| Loader
  Loader -->|"loads_binary_and_calls_entrypoints"| Lifecycle
  Lifecycle -->|"register_command"| CmdReg
  CmdReg -->|"register_callback"| SDK
  SDK -->|"command_callback_invoked"| Toggle
  Toggle -->|"execute_XPLM_command/read-write_dataref"| SDKLayer
  SDKLayer -->|"XPLM_API_calls"| SDK
  SDK -->|"applies_view_state_change"| XPlane

end

%% =========================
%% BUILD / DEPENDENCY / DEPLOYMENT
%% =========================
subgraph "Build / Dependency / Deployment"
direction TB

  Dev["Developer Machine"]:::external

  subgraph "Repo Tooling & Config"
  direction TB
    Readme["Build / Usage Docs\n(CMake+Ninja mentioned)"]:::repo
    ClangFormat["clang-format Rules"]:::devtool
    VSCode["VSCode Settings"]:::devtool
  end

  subgraph "Build System"
  direction TB
    MesonTop["Meson Build (top-level)"]:::build
    MesonSrc["Meson Build (src/)"]:::build
    CMakeAlt["CMake (docs/alternative)"]:::build
    Ninja["Ninja"]:::build
  end

  subgraph "Third-party Dependency Retrieval"
  direction TB
    SubprojectsDir["subprojects/ (wrap storage)"]:::buildtime
    Wrap["Meson Wrap: X-Plane SDK\n(x-plane-sdk.wrap)"]:::buildtime
    SDKPkg["Fetched/Provided X-Plane SDK\n(headers/libs)"]:::thirdparty
  end

  Toolchain["MSVC Build Tools 2022\n(Windows toolchain)"]:::build
  Artifact["Output Artifact\nPlugin Binary (DLL/.xpl)"]:::artifact

  subgraph "X-Plane Installation"
  direction TB
    PluginsDir["X-Plane plugins/ directory"]:::external
    XPlane2["X-Plane Simulator"]:::external
  end

  %% Build/deploy flows
  Dev -->|"configure_build"| MesonTop
  Dev -->|"configure_build"| CMakeAlt
  MesonTop -->|"includes"| MesonSrc
  MesonTop -->|"drives_build"| Ninja
  CMakeAlt -->|"drives_build"| Ninja
  Ninja -->|"compile_link"| Toolchain
  MesonTop -->|"wrap_fetch/use"| Wrap
  Wrap -->|"stores_in"| SubprojectsDir
  Wrap -->|"provides"| SDKPkg
  MesonSrc -->|"include_link"| SDKPkg
  Toolchain -->|"produces"| Artifact
  Artifact -->|"copy_deploy"| PluginsDir
  PluginsDir -->|"loaded_on_startup"| XPlane2

end

%% =========================
%% Click events (from component_mapping)
%% =========================
click Plugin "https://github.com/afinn-s/toggleexternalview/blob/main/src/ToggleExternalView.cpp"
click Toggle "https://github.com/afinn-s/toggleexternalview/blob/main/src/ToggleExternalView.cpp"
click SDKLayer "https://github.com/afinn-s/toggleexternalview/blob/main/src/ToggleExternalView.cpp"
click MesonTop "https://github.com/afinn-s/toggleexternalview/blob/main/meson.build"
click MesonSrc "https://github.com/afinn-s/toggleexternalview/blob/main/src/meson.build"
click Wrap "https://github.com/afinn-s/toggleexternalview/blob/main/subprojects/x-plane-sdk.wrap"
click SubprojectsDir "https://github.com/afinn-s/toggleexternalview/tree/main/subprojects/"
click ClangFormat "https://github.com/afinn-s/toggleexternalview/blob/main/.clang-format"
click VSCode "https://github.com/afinn-s/toggleexternalview/tree/main/.vscode/"
click Readme "https://github.com/afinn-s/toggleexternalview/blob/main/README.md"

%% =========================
%% Styles
%% =========================
classDef external fill:#E5E7EB,stroke:#374151,stroke-width:1px,color:#111827;
classDef repo fill:#DBEAFE,stroke:#1D4ED8,stroke-width:1.2px,color:#0B1F44;
classDef thirdparty fill:#EDE9FE,stroke:#6D28D9,stroke-width:1.2px,color:#1F1147;
classDef build fill:#FFEDD5,stroke:#C2410C,stroke-width:1.2px,color:#3B1A09;
classDef buildtime fill:#FEF3C7,stroke:#B45309,stroke-width:1.2px,color:#3A2206,stroke-dasharray: 6 4;
classDef artifact fill:#D1FAE5,stroke:#047857,stroke-width:1.2px,color:#062C22;
classDef devtool fill:#FCE7F3,stroke:#9D174D,stroke-width:1.2px,color:#3A0B1D,stroke-dasharray: 6 4;
```
