# allenbenz/winrt-notification architecture

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

- Interactive diagram: https://gitdiagram.com/allenbenz/winrt-notification
- Repository: https://github.com/allenbenz/winrt-notification

## Overview

##### Project type and purpose
- This is an open-source Rust library (crate) named “winrt-notification” that provides a thin wrapper over the Windows Runtime (WinRT) toast notification API.
- It exposes a simple Rust interface for desktop applications to send Windows toast notifications.

##### File structure
- Top-level files:
- Cargo.toml: crate metadata and dependencies
- README.md, CHANGELOG.md: documentation
- .gitignore, .rustfmt.toml: tooling/config
- Directories:
- src/
– lib.rs: main public API, re-exports and orchestration
– windows_check.rs: logic to detect OS version and load WinRT APIs safely
- examples/: practical usage snippets that consume the crate
- resources/: test assets (e.g., dummy images)

##### README
- Confirms it’s a wrapper over the WinRT toast API.
- Shows usage: building a Toast object, chaining methods (.title, .text1, .sound, .show), and error handling.
- Mentions supported platforms and known limitations.

##### Main components and interactions
a. Client Application Code (examples or external Rust app)
→ calls public API in winrt-notification crate
b. winrt-notification Crate
- lib.rs orchestrates builder pattern (Toast struct)
- windows_check.rs verifies Windows version & initializes WinRT COM interfaces
- FFI layer (WinRT/COM bindings under the hood)
c. Windows Runtime (WinRT) ToastNotificationManager APIs
→ native OS component that schedules and displays notifications
d. Windows Notification Platform
→ delivers toast to Action Center/UI

##### Architectural patterns and design principles
- Builder pattern for the Toast struct to chain configuration calls.
- Separation of concerns:
- Public API (lib.rs) vs. OS/version checks (windows_check.rs)
- No UI code in the crate—pure FFI wrapper + error handling
- Minimal external dependencies—relies on Windows SDK via WinRT

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Application (examples)" 
        direction TB
        Simple["simple.rs"]:::client
        Image["image.rs"]:::client
        ReuseArgs["reuse_arguments.rs"]:::client
        ReuseToast["reuse_toast.rs"]:::client
        WithoutLib["without_library.rs"]:::client
    end

    %% Crate Layer
    subgraph "winrt-notification Crate" 
        direction TB
        ToastBuilder["Public API / Toast Builder"]:::crate
        OSCheck["OS Checker & WinRT Initializer"]:::crate
    end

    %% OS/Runtime Layer
    subgraph "Windows Runtime (WinRT) COM" 
        ToastNotificationManager["ToastNotificationManager API"]:::os
    end

    subgraph "Windows Notification Platform" 
        ActionCenter["Action Center (Notification Platform)"]:::os
    end

    %% Repository Files
    subgraph "Repository Files" 
        direction TB
        Cargo["Cargo.toml"]:::repo
        README["README.md"]:::repo
        Changelog["CHANGELOG.md"]:::repo
        Gitignore[".gitignore"]:::repo
        Rustfmt[".rustfmt.toml"]:::repo
        Resources["resources/"]:::repo
    end

    %% Interactions
    Simple -->|"build & show toast"| ToastBuilder
    Image -->|"build & show toast"| ToastBuilder
    ReuseArgs -->|"build & show toast"| ToastBuilder
    ReuseToast -->|"build & show toast"| ToastBuilder
    WithoutLib -->|"build & show toast"| ToastBuilder

    ToastBuilder -->|"invoke .show()"| OSCheck
    ToastBuilder -->|"invoke ToastNotificationManager API"| ToastNotificationManager
    OSCheck -->|"detect & init WinRT"| ToastNotificationManager
    ToastNotificationManager -->|"schedule/display toast"| ActionCenter

    %% Click Events
    click ToastBuilder "https://github.com/allenbenz/winrt-notification/blob/main/src/lib.rs"
    click OSCheck "https://github.com/allenbenz/winrt-notification/blob/main/src/windows_check.rs"
    click Simple "https://github.com/allenbenz/winrt-notification/blob/main/examples/simple.rs"
    click Image "https://github.com/allenbenz/winrt-notification/blob/main/examples/image.rs"
    click ReuseArgs "https://github.com/allenbenz/winrt-notification/blob/main/examples/reuse_arguments.rs"
    click ReuseToast "https://github.com/allenbenz/winrt-notification/blob/main/examples/reuse_toast.rs"
    click WithoutLib "https://github.com/allenbenz/winrt-notification/blob/main/examples/without_library.rs"
    click Cargo "https://github.com/allenbenz/winrt-notification/blob/main/Cargo.toml"
    click README "https://github.com/allenbenz/winrt-notification/blob/main/README.md"
    click Changelog "https://github.com/allenbenz/winrt-notification/blob/main/CHANGELOG.md"
    click Gitignore "https://github.com/allenbenz/winrt-notification/blob/main/.gitignore"
    click Rustfmt "https://github.com/allenbenz/winrt-notification/blob/main/.rustfmt.toml"
    click Resources "https://github.com/allenbenz/winrt-notification/tree/main/resources/"

    %% Styles
    classDef client fill:#cce5ff,stroke:#004085,color:#004085;
    classDef crate fill:#d4edda,stroke:#155724,color:#155724;
    classDef os fill:#ffe5b4,stroke:#994d00,color:#994d00;
    classDef repo fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
```
