# myraui/myra architecture

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

- Interactive diagram: https://gitdiagram.com/myraui/myra
- Repository: https://github.com/myraui/myra

## Overview

#### Purpose and Build Entry Points
Myra is a .NET game UI library targeting MonoGame, FNA, Stride, and a platform-agnostic adapter model. Build solution selection is runtime-specific: `build/Myra.MonoGame.sln`, `build/Myra.FNA.Core.sln`, `build/Myra.Stride.sln`, and `build/Myra.PlatformAgnostic.sln`. The core package variants are `src/Myra/Myra.MonoGame.csproj`, `src/Myra/Myra.FNA.Core.csproj`, `src/Myra/Myra.Stride.csproj`, and `src/Myra/Myra.PlatformAgnostic.csproj`.

#### UI Runtime and Widget Tree
The central retained-mode UI model is `Widget`, arranged under containers and managed by `Desktop`. Widgets perform layout, rendering, and input participation; containers compose controls into panel, grid, stack, scroll, and split layouts.
- `src/Myra/Graphics2D/UI/Widget.cs`
- `src/Myra/Graphics2D/UI/Desktop.cs`
- `src/Myra/Graphics2D/UI/Containers/Grid.cs`

#### Input, Events, and Windowing
Host input enters through `MyraEnvironment` and platform abstractions, is routed by `Desktop`/`InputEventsManager`, then delivered to widgets using Myra event types and handling strategies. Desktop-level facilities also own dialogs, windows, focus, and modal/non-modal interaction boundaries.
- `src/Myra/MyraEnvironment.Input.cs`
- `src/Myra/Graphics2D/UI/InputEventsManager.cs`
- `src/Myra/Events/MyraEventArgs.cs`

#### Rendering and Platform Boundary
Core UI rendering targets abstract `IMyraRenderer` and `IMyraPlatform` contracts rather than a single graphics API. `RenderContext` and texture-atlas primitives provide the shared 2D draw model; engine-specific projects supply graphics/input integration. Platform-agnostic sample adapters demonstrate implementations for MonoGame, OpenTK, Raylib, and Silk.NET.
- `src/Myra/Platform/IMyraRenderer.cs`
- `src/Myra/Platform/IMyraPlatform.cs`
- `src/Myra/Graphics2D/RenderContext.cs`

#### Assets, Skins, and MML
MML is an XML serialization layer that loads/saves widget trees and property values through contexts, serializers, and attached-property registration. Stylesheets resolve widget visual styles, fonts, and texture regions; default skin assets ship with the library. Asset-manager extension points bridge these resources into supported engines.
- `src/Myra/MML/LoadContext.cs`
- `src/Myra/Graphics2D/UI/Styles/Stylesheet.cs`
- `src/Myra/MyraAssetManagerExtensions.cs`

#### Tools and Consumer Entry Points
MyraPad is the standalone WYSIWYG MML designer: its executable starts at `src/MyraPad/Program.cs`, coordinates editor state in `src/MyraPad/Studio.cs`, and exports generated C# via `src/MyraPad/ExporterCS.cs`. MyraViewer is a separate MML viewing executable at `src/MyraViewer/Program.cs`. Samples are integration entry points, especially `samples/Myra.Samples.AllWidgets/Program.cs`.

#### Delivery and External Dependencies
The repository is a .NET library/tooling workspace published through GitHub Actions release and beta workflows, with NuGet as the primary distribution service. Material runtime integrations are MonoGame, FNA, and Stride; clipboard support is implemented per OS through the embedded TextCopy-derived layer.
- `.github/workflows/build-and-publish-release.yml`
- `src/Myra/TextCopy/Clipboard.cs`
- `src/Myra/TextCopy/LinuxClipboard.cs`

Main entry points: [`src/Myra/Graphics2D/UI/Widget.cs`](https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/Widget.cs) (Widget), [`src/Myra/Graphics2D/UI/Desktop.cs`](https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/Desktop.cs) (Desktop), [`src/Myra/MML/LoadContext.cs`](https://github.com/myraui/myra/blob/master/src/Myra/MML/LoadContext.cs) (MML load context), [`src/Myra/Graphics2D/UI/InputEventsManager.cs`](https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/InputEventsManager.cs) (Input events manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core UI Runtime"]
  node_widget["Widget<br/>retained UI node<br/>[Widget.cs]"]
  node_containers["Layout containers<br/>widget composition<br/>[Grid.cs]"]
  node_desktop["Desktop<br/>UI root manager<br/>[Desktop.cs]"]
  node_environment_input["Myra environment input<br/>host input entry"]
  node_input_router["Input events manager<br/>input router"]
  node_event_types["Myra event types<br/>event contracts<br/>[MyraEventArgs.cs]"]
end

subgraph group_platform["Platform Integration"]
  node_renderer_contract["IMyraRenderer<br/>rendering contract<br/>[IMyraRenderer.cs]"]
  node_platform_contract["IMyraPlatform<br/>platform contract<br/>[IMyraPlatform.cs]"]
  node_render_context["Render context<br/>2D draw model<br/>[RenderContext.cs]"]
  node_clipboard["Clipboard support<br/>OS clipboard layer<br/>[Clipboard.cs]"]
end

subgraph group_assets["Assets and Markup"]
  node_mml_load["MML load context<br/>XML UI serialization<br/>[LoadContext.cs]"]
  node_stylesheets["Stylesheets<br/>skin styling<br/>[Stylesheet.cs]"]
  node_asset_extensions["Asset manager extensions<br/>engine asset bridge"]
end

subgraph group_tools["Tools and Consumers"]
  node_myrapad["MyraPad<br/>WYSIWYG MML designer<br/>[Program.cs]"]
  node_studio["Studio<br/>editor state<br/>[Studio.cs]"]
  node_csharp_exporter["C&#35; exporter<br/>MML code generation<br/>[ExporterCS.cs]"]
  node_myra_viewer["MyraViewer<br/>MML viewer executable<br/>[Program.cs]"]
  node_all_widgets_sample["AllWidgets sample<br/>integration sample<br/>[Program.cs]"]
end

subgraph group_delivery["Build and Delivery"]
  node_build_solutions["Runtime build solutions<br/>solution variants"]
  node_core_packages["Core package variants<br/>project variants"]
  node_release_workflow["Release publishing<br/>GitHub Actions workflow"]
end

node_build_solutions -->|"selects"| node_core_packages
node_core_packages -->|"packages"| node_widget
node_containers -->|"compose"| node_widget
node_desktop -->|"manages"| node_widget
node_environment_input -->|"forwards host input"| node_input_router
node_input_router -->|"routes through"| node_desktop
node_input_router -->|"uses"| node_event_types
node_desktop -->|"delivers input to"| node_widget
node_widget -->|"renders with"| node_render_context
node_render_context -->|"targets"| node_renderer_contract
node_environment_input -->|"uses platform services"| node_platform_contract
node_stylesheets -->|"styles"| node_widget
node_mml_load -->|"constructs"| node_widget
node_mml_load -->|"loads visual resources"| node_stylesheets
node_asset_extensions -->|"bridges assets"| node_stylesheets
node_myrapad -->|"coordinates"| node_studio
node_studio -->|"edits MML"| node_mml_load
node_studio -->|"exports through"| node_csharp_exporter
node_myra_viewer -->|"views"| node_mml_load
node_all_widgets_sample -->|"integrates"| node_desktop
node_clipboard -.->|"implements OS service"| node_platform_contract
node_release_workflow -->|"publishes"| node_core_packages

click node_widget "https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/Widget.cs"
click node_containers "https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/Containers/Grid.cs"
click node_desktop "https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/Desktop.cs"
click node_environment_input "https://github.com/myraui/myra/blob/master/src/Myra/MyraEnvironment.Input.cs"
click node_input_router "https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/InputEventsManager.cs"
click node_event_types "https://github.com/myraui/myra/blob/master/src/Myra/Events/MyraEventArgs.cs"
click node_renderer_contract "https://github.com/myraui/myra/blob/master/src/Myra/Platform/IMyraRenderer.cs"
click node_platform_contract "https://github.com/myraui/myra/blob/master/src/Myra/Platform/IMyraPlatform.cs"
click node_render_context "https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/RenderContext.cs"
click node_mml_load "https://github.com/myraui/myra/blob/master/src/Myra/MML/LoadContext.cs"
click node_stylesheets "https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/Styles/Stylesheet.cs"
click node_asset_extensions "https://github.com/myraui/myra/blob/master/src/Myra/MyraAssetManagerExtensions.cs"
click node_myrapad "https://github.com/myraui/myra/blob/master/src/MyraPad/Program.cs"
click node_studio "https://github.com/myraui/myra/blob/master/src/MyraPad/Studio.cs"
click node_csharp_exporter "https://github.com/myraui/myra/blob/master/src/MyraPad/ExporterCS.cs"
click node_myra_viewer "https://github.com/myraui/myra/blob/master/src/MyraViewer/Program.cs"
click node_all_widgets_sample "https://github.com/myraui/myra/blob/master/samples/Myra.Samples.AllWidgets/Program.cs"
click node_clipboard "https://github.com/myraui/myra/blob/master/src/Myra/TextCopy/Clipboard.cs"
click node_release_workflow "https://github.com/myraui/myra/blob/master/.github/workflows/build-and-publish-release.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_widget,node_containers,node_desktop,node_environment_input,node_input_router,node_event_types toneBlue
class node_renderer_contract,node_platform_contract,node_render_context,node_clipboard toneAmber
class node_mml_load,node_stylesheets,node_asset_extensions toneMint
class node_myrapad,node_studio,node_csharp_exporter,node_myra_viewer,node_all_widgets_sample toneRose
class node_build_solutions,node_core_packages,node_release_workflow toneIndigo
```

## Components

### Core UI Runtime

- [Widget](https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/Widget.cs): retained UI node · Base for layout, rendering, and input participation. · `src/Myra/Graphics2D/UI/Widget.cs`
- [Layout containers](https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/Containers/Grid.cs): widget composition · Panels, grids, stacks, scroll, and split layouts. · `src/Myra/Graphics2D/UI/Containers/Grid.cs`
- [Desktop](https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/Desktop.cs): UI root manager · Owns the widget tree, windows, dialogs, focus, and modal boundaries. · `src/Myra/Graphics2D/UI/Desktop.cs`
- [Myra environment input](https://github.com/myraui/myra/blob/master/src/Myra/MyraEnvironment.Input.cs): host input entry · `src/Myra/MyraEnvironment.Input.cs`
- [Input events manager](https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/InputEventsManager.cs): input router · `src/Myra/Graphics2D/UI/InputEventsManager.cs`
- [Myra event types](https://github.com/myraui/myra/blob/master/src/Myra/Events/MyraEventArgs.cs): event contracts · `src/Myra/Events/MyraEventArgs.cs`

### Platform Integration

- [IMyraRenderer](https://github.com/myraui/myra/blob/master/src/Myra/Platform/IMyraRenderer.cs): rendering contract · `src/Myra/Platform/IMyraRenderer.cs`
- [IMyraPlatform](https://github.com/myraui/myra/blob/master/src/Myra/Platform/IMyraPlatform.cs): platform contract · `src/Myra/Platform/IMyraPlatform.cs`
- [Render context](https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/RenderContext.cs): 2D draw model · Shared rendering and texture-atlas primitives. · `src/Myra/Graphics2D/RenderContext.cs`
- [Clipboard support](https://github.com/myraui/myra/blob/master/src/Myra/TextCopy/Clipboard.cs): OS clipboard layer · Embedded TextCopy-derived implementation. · `src/Myra/TextCopy/Clipboard.cs`

### Assets and Markup

- [MML load context](https://github.com/myraui/myra/blob/master/src/Myra/MML/LoadContext.cs): XML UI serialization · Loads widget trees and property values. · `src/Myra/MML/LoadContext.cs`
- [Stylesheets](https://github.com/myraui/myra/blob/master/src/Myra/Graphics2D/UI/Styles/Stylesheet.cs): skin styling · Resolves widget styles, fonts, and texture regions. · `src/Myra/Graphics2D/UI/Styles/Stylesheet.cs`
- [Asset manager extensions](https://github.com/myraui/myra/blob/master/src/Myra/MyraAssetManagerExtensions.cs): engine asset bridge · `src/Myra/MyraAssetManagerExtensions.cs`

### Tools and Consumers

- [MyraPad](https://github.com/myraui/myra/blob/master/src/MyraPad/Program.cs): WYSIWYG MML designer · Standalone designer executable. · `src/MyraPad/Program.cs`
- [Studio](https://github.com/myraui/myra/blob/master/src/MyraPad/Studio.cs): editor state · `src/MyraPad/Studio.cs`
- [C# exporter](https://github.com/myraui/myra/blob/master/src/MyraPad/ExporterCS.cs): MML code generation · `src/MyraPad/ExporterCS.cs`
- [MyraViewer](https://github.com/myraui/myra/blob/master/src/MyraViewer/Program.cs): MML viewer executable · `src/MyraViewer/Program.cs`
- [AllWidgets sample](https://github.com/myraui/myra/blob/master/samples/Myra.Samples.AllWidgets/Program.cs): integration sample · `samples/Myra.Samples.AllWidgets/Program.cs`

### Build and Delivery

- **Runtime build solutions**: solution variants · MonoGame, FNA, Stride, and platform-agnostic solution entry points.
- **Core package variants**: project variants · Runtime-specific Myra package projects.
- [Release publishing](https://github.com/myraui/myra/blob/master/.github/workflows/build-and-publish-release.yml): GitHub Actions workflow · Publishes library packages to NuGet. · `.github/workflows/build-and-publish-release.yml`

## Connections

- Runtime build solutions → Core package variants: selects
- Core package variants → Widget: packages
- Layout containers → Widget: compose
- Desktop → Widget: manages
- Myra environment input → Input events manager: forwards host input
- Input events manager → Desktop: routes through
- Input events manager → Myra event types: uses
- Desktop → Widget: delivers input to
- Widget → Render context: renders with
- Render context → IMyraRenderer: targets
- Myra environment input → IMyraPlatform: uses platform services
- Stylesheets → Widget: styles
- MML load context → Widget: constructs
- MML load context → Stylesheets: loads visual resources
- Asset manager extensions → Stylesheets: bridges assets
- MyraPad → Studio: coordinates
- Studio → MML load context: edits MML
- Studio → C# exporter: exports through
- MyraViewer → MML load context: views
- AllWidgets sample → Desktop: integrates
- Clipboard support → IMyraPlatform: implements OS service
- Release publishing → Core package variants: publishes
