# fuqunaga/headquarters architecture

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

- Interactive diagram: https://gitdiagram.com/fuqunaga/headquarters
- Repository: https://github.com/fuqunaga/headquarters

## Overview

##### Main Components

a. Presentation Layer (UI)
- MainWindow and its supporting pages: The “Headquarters/MainWindow” directory contains the entry point (MainWindow.xaml and its corresponding view model). This includes sub-components (tabs, dialogs, IP list, script chain pages) designed as individual pages (for example, MainTab, ParameterInputField, Profile, ScriptChainPage).
- Dialogs and Controls: There are dedicated directories for UI dialogs (e.g. “Dialog” and “IpList”) and reusable UI controls in “UIUtility.” This clearly indicates an MVVM approach with separate view models and views.

b. Business Logic / Application Layer
- Parameter and Settings Management: The “Parameter” directory organizes global parameters, IP parameter sets, and script parameter definitions. “Setting” inside MainWindow manages application settings, and profile management is also present for handling user and script profiles.
- Service and Helper Classes: Classes for dialog management, validation, and profile management (e.g., DialogService, SettingManager, SymbolicLinkService) mediate user interactions and data flow.

c. Scripting and Execution Layer
- PowerShell Integration: The “PowerShellScript” directory is where the core integration lies. It contains the script runner, session management, event subscribers, and custom attributes needed to execute remote PowerShell commands.
- Script Chain and Output Management: Within “MainWindow/ScriptChainPage” there is a clear flow for initiating a script chain, monitoring execution (ScriptRunPage, ScriptPage), and presenting output (OutputField components). This process outlines how scripts are started, executed, and reported back.

d. Data and Configuration Layer
- Persistent Storage: The project uses JSON settings (e.g., “setting.json”) to save the state, profiles, and parameters.
- Resources and External Modules: Under “Resources” there are images, modules (like 7Zip, TaskContextUtility), and scripts (tutorial and operational scripts) which play into both the configuration and operational aspects of the tool.

e. External Dependencies and Libraries
- External Libraries: The README lists several key dependencies such as MaterialDesignInXamlToolkit, Dragablz, IPAddressRange, Json.NET, and others. These libraries are used for enhanced UI behavior, JSON handling, and PowerShell integration.
- Build/Tooling: References to Fody (Costura.Fody, FodyWeavers.xml) indicate compile-time processes for assembly merging and weaving.

##### Relationships and Interactions

- The User interacts with the Presentation Layer (e.g., MainWindow) which then invokes commands on the ViewModels.
- The ViewModels call services (DialogService, SettingManager, Profile management) to retrieve or persist information, triggering changes in the parameter and profile management components.
- When a script is to be executed, the UI layer hands over control to the script execution layer (via the PowerShellRunner, SessionManager, etc.) which conducts remote execution on targeted PCs.
- The results (script output) flow back to the UI where they are displayed in dedicated output fields.
- External configuration (scripts in Resources, modules) support the dynamic and extensible nature of the tool.

##### Architectural Patterns & Design Principles

- MVVM Pattern: Evident in the separation of XAML views and their corresponding view models for modularity and testability.
- Modular Design: Different concerns (UI, parameters, scripts, configuration) are organized in separate directories, promoting separation of concerns.
- Remote Execution Flow: The tool encapsulates the power of PS Remoting, with isolated responsibility for preparing and executing remote commands.
- Extensibility: The design supports adding new scripts, parameters, and profiles without major changes to core functionality.

b. Relationships:
- Additionally, indicate external flows such as network communication via PowerShell remoting, possibly marking a “Remote PC” as an external entity receiving commands.

c. Labeling & Notation:
- Component and module has a clear, descriptive label.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        P_MainWindow("MainWindow (UI)") 
        P_MainTab("MainTab")
        P_ParameterInput("ParameterInputField")
        P_IpList("IP List")
        P_Profile("Profile")
        P_Dialogs("Dialogs")
        P_ScriptChain("ScriptChainPage")
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        BL_SettingManager("SettingManager")
        BL_DialogService("DialogService")
        BL_UIUtility("UIUtility Services")
        BL_ParameterMgmt("Parameters Management")
    end

    %% Scripting Execution Layer
    subgraph "Scripting Execution Layer"
        S_PowerShell("PowerShell Runner & SessionManager")
        S_ScriptOutput("Script Execution & Output")
    end

    %% Data & Configuration Layer
    subgraph "Data & Configuration Layer"
        D_JSONResources("JSON Settings & Resources")
    end

    %% External Dependencies
    subgraph "External Dependencies"
        E_Libraries("External Libraries")
        E_RemotePC("Remote Windows PCs")
    end

    %% Internal connections within Presentation Layer
    P_MainWindow -->|"contains"| P_MainTab
    P_MainWindow -->|"contains"| P_ParameterInput
    P_MainWindow -->|"contains"| P_IpList
    P_MainWindow -->|"contains"| P_Profile
    P_MainWindow -->|"contains"| P_Dialogs
    P_MainWindow -->|"contains"| P_ScriptChain

    %% Connections from Presentation to Business Logic
    P_MainWindow -->|"triggers"| BL_SettingManager
    P_MainWindow -->|"triggers"| BL_DialogService
    P_MainWindow -->|"uses"| BL_UIUtility
    P_MainWindow -->|"reads"| BL_ParameterMgmt

    %% Connection from Presentation to Scripting Layer
    P_ScriptChain -->|"executes"| S_PowerShell
    S_PowerShell -->|"returns"| S_ScriptOutput
    S_ScriptOutput -->|"updates"| P_MainWindow

    %% Business Logic & Data Sync
    BL_ParameterMgmt <-->|"syncs"| D_JSONResources

    %% External Dependencies influence
    E_Libraries -->|"enhances"| P_MainWindow
    S_PowerShell -->|"remoting"| E_RemotePC

    %% Class definitions for styling
    classDef presentation fill:#AED6F1,stroke:#21618C,stroke-width:2px;
    classDef business fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef scripting fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef data fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#922B21,stroke-width:2px;

    class P_MainWindow,P_MainTab,P_ParameterInput,P_IpList,P_Profile,P_Dialogs,P_ScriptChain presentation;
    class BL_SettingManager,BL_DialogService,BL_UIUtility,BL_ParameterMgmt business;
    class S_PowerShell,S_ScriptOutput scripting;
    class D_JSONResources data;
    class E_Libraries,E_RemotePC external;

    %% Click Events for Component Mapping
    click P_MainWindow "https://github.com/fuqunaga/headquarters/tree/main/Headquarters/MainWindow"
    click P_Dialogs "https://github.com/fuqunaga/headquarters/tree/main/Headquarters/MainWindow/Dialog"
    click P_IpList "https://github.com/fuqunaga/headquarters/tree/main/Headquarters/MainWindow/IpList"
    click P_ParameterInput "https://github.com/fuqunaga/headquarters/tree/main/Headquarters/MainWindow/ParameterInputField"
    click P_Profile "https://github.com/fuqunaga/headquarters/tree/main/Headquarters/MainWindow/Profile"
    click BL_SettingManager "https://github.com/fuqunaga/headquarters/tree/main/Headquarters/MainWindow/Setting"
    click BL_UIUtility "https://github.com/fuqunaga/headquarters/tree/main/Headquarters/UIUtility"
    click BL_ParameterMgmt "https://github.com/fuqunaga/headquarters/tree/main/Headquarters/Parameter"
    click S_PowerShell "https://github.com/fuqunaga/headquarters/tree/main/Headquarters/PowerShellScript"
    click P_ScriptChain "https://github.com/fuqunaga/headquarters/tree/main/Headquarters/MainWindow/ScriptChainPage"
    click D_JSONResources "https://github.com/fuqunaga/headquarters/tree/main/Headquarters/Resources"
```
