# emoacht/monitorian architecture

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

- Interactive diagram: https://gitdiagram.com/emoacht/monitorian
- Repository: https://github.com/emoacht/monitorian

## Overview

##### Project Type and Purpose
- This is a Windows desktop application (WPF) called Monitorian.
- It follows an MVVM pattern: a thin “Monitorian” WPF host, a rich “Monitorian.Core” library containing Models, ViewModels, Views, and several supporting class libraries.

##### File‐Structure Analysis
- Top‐level projects under Source/:
- Monitorian (WPF EXE)
- Monitorian.Core (class library: MVVM implementation)
- ScreenFrame (class library: window drawing, movers, watchers)
- StartupAgency (class library / EXE: registry/startup task broker)
- Installer (WiX installer)
- Monitorian.Test (unit tests)
- Resources and assets stored under Images/, docs/, and Localization (.resx files).
- Build scripts and configs: .sln, Directory.Build.props, *.csproj, App.configs, WiX .wxs.

a. Presentation Layer
- Monitorian.exe: WPF “App.xaml → AppController → ViewManager”
- UI Windows: MainWindow, MenuWindow
b. Application/Core Layer
- Monitorian.Core:
- Models: MonitorManager, DdcMonitorItem, DisplayInformationProvider, SettingsCore, Logger, etc.
- ViewModels: MainWindowViewModel, MenuWindowViewModel, MonitorViewModel
- Views: XAML, Behaviors, Controls, Converters, Themes
- Services: AppDataService, LanguageService, ConsoleService
- MVVM pattern: Views ←→ ViewModels ←→ Models
c. Infrastructure/Platform Layer
- ScreenFrame.dll: window painting, watchers (WindowWatcher, NotifyIconHelper, WindowPainter, Movers)
- StartupAgency.exe/dll: StartupTaskBroker, BridgeWorker, RegistryWorker (manages “Start on sign in” registry entry or scheduled task)
- OS & External Interfaces:
- DDC/CI brightness control (via native APIs)
- WMI for system events (SessionWatcher, PowerWatcher)
- File system (settings under %LOCALAPPDATA%\Monitorian)
- Registry (HKCU\…\Run)
d. Installer
- WiX project (.wixproj) builds MSI, drops Monitorian.exe, StartupAgent, ScreenFrame, Monitorian.Core, etc., and registers startup agent if needed.
e. Unit Tests
- Monitorian.Test: DeviceConversionTest, MonitorConfigurationTest (validates core algorithms).

##### Relationships and Data Flows
- View binds to MainWindowViewModel → invokes MonitorManager (Model) → queries DisplayInformationProvider → native DDC/CI calls → returns brightness/contrast
- User moves sliders → ViewModel calls MonitorManager.SetBrightness → DDC/CI command → Model raises event → ViewModel updates View
- Settings changes → AppDataService persists JSON/XML under AppData
- On “Start on sign in,” Monitorian.exe uses StartupAgency API to register the agent in registry or task scheduler
- ScreenFrame.WindowWatcher tracks window focus events, DPI changes → notifies core

##### Architectural Patterns and Principles
- MVVM (Model–View–ViewModel) to separate UI from business logic
- Modularization: separate assemblies for core logic, UI utilities, OS interaction, installation, and startup management
- Observer pattern: watchers (TimerWatcher, SessionWatcher) fire events to ViewModels
- Dependency inversion: core services (IAppDataService, ILogger) injected/bound at AppController startup
- Resource-based globalization via .resx files in Monitorian.Core

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        MonitorianExe["Monitorian.exe\n(WPF Host)"]:::presentation
        IconImageExe["IconImage.exe\n(Icon Tool)"]:::presentation
    end

    %% Core Layer
    subgraph "Application/Core Layer"
        MCModels["Models"]:::core
        MCVM["ViewModels"]:::core
        MCViews["Views"]:::core
        CoreServices["Services\n(AppDataService, LanguageService, ConsoleService)"]:::core
        Localization["Resources (.resx)"]:::core
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        ScreenFrame["ScreenFrame.dll\n(WindowDrawing, Watchers)"]:::infra
        StartupAgency["StartupAgency.exe/dll"]:::infra
        Broker["StartupTaskBroker"]:::infra
        RegistryWorker["RegistryWorker"]:::infra
        BridgeWorker["BridgeWorker"]:::infra
    end

    %% Installer & Tests
    Installer["WiX Installer"]:::installer
    Tests["Unit Tests\n(Monitorian.Test)"]:::installer

    %% External/OS & Hardware
    subgraph "External/OS & Hardware"
        DDCCI["DDC/CI API"]:::external
        WMI["WMI"]:::external
        FS["File System"]:::external
        Registry["Registry"]:::external
        Monitors["External Monitors"]:::external
    end

    %% Connections
    ScreenFrame -->|"NotifyIconClick"| MonitorianExe
    MonitorianExe -->|"loads Views"| MCViews
    MonitorianExe -->|"binds to VM"| MCVM
    MCVM -->|"uses Models"| MCModels
    MCModels -->|"GetBrightness()→DDC/CI"| DDCCI
    DDCCI -->|"returns data"| MCModels
    MCVM -->|"updates UI"| MCViews
    MCVM -->|"calls PersistSettings()"| CoreServices
    CoreServices -->|"writes settings"| FS
    MonitorianExe -->|"use Startup API"| StartupAgency
    StartupAgency -->|"invoke Broker"| Broker
    StartupAgency -->|"invoke RegistryWorker"| RegistryWorker
    StartupAgency -->|"invoke BridgeWorker"| BridgeWorker
    MCModels -->|"Session/Power events"| WMI
    MCModels -->|"window events"| ScreenFrame
    Installer -->|"packages Monitorian.exe, StartupAgency, ScreenFrame, Monitorian.Core"| MonitorianExe
    Installer --> MonitorianExe
    Installer --> StartupAgency
    Installer --> ScreenFrame
    Installer --> MCModels
    Tests -->|"validates core"| MCModels
    Monitors --> DDCCI

    %% Click Events
    click MonitorianExe "https://github.com/emoacht/monitorian/tree/master/Source/Monitorian"
    click IconImageExe "https://github.com/emoacht/monitorian/tree/master/Source/IconImage"
    click MCModels "https://github.com/emoacht/monitorian/tree/master/Source/Monitorian.Core/Models"
    click MCVM "https://github.com/emoacht/monitorian/tree/master/Source/Monitorian.Core/ViewModels"
    click MCViews "https://github.com/emoacht/monitorian/tree/master/Source/Monitorian.Core/Views"
    click CoreServices "https://github.com/emoacht/monitorian/tree/master/Source/Monitorian.Core/Models"
    click Localization "https://github.com/emoacht/monitorian/blob/master/Source/Monitorian.Core/Properties/Resources*.resx"
    click ScreenFrame "https://github.com/emoacht/monitorian/tree/master/Source/ScreenFrame"
    click StartupAgency "https://github.com/emoacht/monitorian/tree/master/Source/StartupAgency"
    click Broker "https://github.com/emoacht/monitorian/blob/master/Source/StartupAgency/Bridge/StartupTaskBroker.cs"
    click RegistryWorker "https://github.com/emoacht/monitorian/blob/master/Source/StartupAgency/Worker/RegistryWorker.cs"
    click BridgeWorker "https://github.com/emoacht/monitorian/blob/master/Source/StartupAgency/Worker/BridgeWorker.cs"
    click Installer "https://github.com/emoacht/monitorian/tree/master/Source/Installer"
    click Tests "https://github.com/emoacht/monitorian/blob/master/Source/Monitorian.Test"

    %% Styles
    classDef presentation fill:#1f77b4,stroke:#333,stroke-width:1px,color:#fff;
    classDef core fill:#2ca02c,stroke:#333,stroke-width:1px,color:#fff;
    classDef infra fill:#ff7f0e,stroke:#333,stroke-width:1px,color:#fff;
    classDef installer fill:#7f7f7f,stroke:#333,stroke-width:1px,color:#fff;
    classDef external fill:#bbbbbb,stroke:#333,stroke-width:1px,color:#000;
```
