# yoshi-782/swab2 architecture

> Architecture diagram of the GitHub repository yoshi-782/swab2, 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/yoshi-782/swab2
- Repository: https://github.com/yoshi-782/swab2

## Overview

##### Main Components
- User Interface (UI) Layer:
- MainWindow.xaml and its code-behind (MainWindow.xaml.cs) represent the primary WPF window.
- App.xaml & App.xaml.cs: Application entry point and global resources.
- Configuration & Resources:
- App.config: Holds application configuration settings.
- Resources directory: Contains HTML templates (Template.html, index.html, setting.html) for generating and loading pages.
- Business Logic & Functionality:
- File operations: Logic to create new templates, open existing HTML files and reload them.
- WebServer.cs: Likely acts as an internal server or a controller for managing HTML file serving and integrations.
- Callee.cs & Setting.cs & Swab2.csproj: Contain the core business logic, including the interoperability aspects (JavaScript invoking C# functions).
- External Tools & Integration:
- Integration with Chrome’s CefSharp (as indicated by the README): for rendering the HTML content within the application.
- Developer tools: Functionality to show the browser development tools.

##### Relationships and Interactions
- The UI layer (MainWindow) drives user interactions such as file operations (new, open, reload, exit).
- When a user opens or creates a file:
- The application loads the respective HTML template from the Resources directory.
- These HTML files are displayed using the embedded browser (CefSharp).
- JavaScript within these HTML files can invoke C# functions (handled in Callee.cs), establishing a bidirectional communication between the front-end content and the back-end application logic.
- WebServer.cs might manage the communication or local hosting aspects for dynamically loaded content.

##### Architectural Patterns & Design Principles
- Separation of Concerns: The UI, the business logic (file and event handling), and resource management are clearly separated.
- Inter-component communication is achieved via explicit function calls (e.g., from JavaScript to C# via the Callee class), demonstrating an integration pattern typical for hybrid applications.
- The design relies on both WPF and embedded browser technologies (CefSharp) to deliver rich, dynamic content while leveraging the robustness of a desktop .NET application.

##### Relevant Technologies & Frameworks
- C#, WPF for the UI layer.
- .NET Framework 4.7.2 for the overall application runtime.
- CefSharp to embed a Chrome-like browser into the application.
- Visual Studio 2019 as the development environment, with files like .sln and .csproj managing the project structure.

- Each main component should be clearly labeled (UI layer, Configuration/Resources, Business Logic, External Services like CefSharp).
- From the user’s input in the MainWindow, to invoking actions in the business logic.
- From the business logic to loading resources (HTML templates) and dispatching them to the embedded web view.
- From JavaScript running in the web view back to the C# functions in Callee.cs.
- Backend processing components (another style),
- Annotations that mention configuration files (App.config) and explain the role of each core file/directory (like the Resources folder for templates).

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::user

    subgraph "UI Layer"
        MW_XAML["MainWindow.xaml"]:::ui
        MW_CODE["MainWindow.xaml.cs"]:::ui
        APP_XAML["App.xaml"]:::ui
        APP_CODE["App.xaml.cs"]:::ui
    end

    subgraph "Configuration & Resources"
        APPCFG["App.config"]:::config
        RESOURCES["Resources (Template.html, index.html, setting.html)"]:::config
    end

    subgraph "Business Logic & File Operations"
        CALLEE["Callee.cs"]:::logic
        SETTING["Setting.cs"]:::logic
        CSPROJ["Swab2.csproj"]:::logic
    end

    subgraph "Internal Web Server/Content Management"
        WEBSERVER["WebServer.cs"]:::server
    end

    subgraph "External Integration"
        CEF["CefSharp Integration"]:::external
    end

    %% Flow Relationships
    User -->|"launches"| APP_XAML
    APP_XAML -->|"initializes"| MW_XAML
    APP_XAML --> APP_CODE
    MW_XAML -->|"triggers file operations"| CALLEE
    MW_CODE -->|"integrates embedded browser"| CEF
    APP_CODE -->|"loads global config"| APPCFG

    %% File operations and resource flow
    User -->|"opens/creates file"| RESOURCES
    RESOURCES -->|"loaded by"| CEF
    CEF -->|"renders HTML to"| MW_XAML

    %% JavaScript-to-C# interop
    CEF -->|"JS-calls C# functions"| CALLEE

    %% Business Logic interactions
    CALLEE -->|"manages settings"| SETTING
    CALLEE -->|"communicates with"| WEBSERVER
    WEBSERVER -->|"serves HTML from"| RESOURCES

    %% Class Definitions for styling
    classDef ui fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef config fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef logic fill:#ffcccb,stroke:#000,stroke-width:2px;
    classDef server fill:#f4a460,stroke:#000,stroke-width:2px;
    classDef external fill:#dda0dd,stroke:#000,stroke-width:2px;
    classDef user fill:#ffffe0,stroke:#000,stroke-width:2px;

    %% Click Events for UI Layer
    click MW_XAML "https://github.com/yoshi-782/swab2/blob/master/source/MainWindow.xaml"
    click MW_CODE "https://github.com/yoshi-782/swab2/blob/master/source/MainWindow.xaml.cs"
    click APP_XAML "https://github.com/yoshi-782/swab2/blob/master/source/App.xaml"
    click APP_CODE "https://github.com/yoshi-782/swab2/blob/master/source/App.xaml.cs"

    %% Click Events for Configuration & Resources
    click APPCFG "https://github.com/yoshi-782/swab2/blob/master/source/App.config"
    click RESOURCES "https://github.com/yoshi-782/swab2/tree/master/source/Resources"

    %% Click Events for Business Logic & File Operations
    click CALLEE "https://github.com/yoshi-782/swab2/blob/master/source/Callee.cs"
    click SETTING "https://github.com/yoshi-782/swab2/blob/master/source/Setting.cs"
    click CSPROJ "https://github.com/yoshi-782/swab2/blob/master/source/Swab2.csproj"

    %% Click Event for Internal Web Server
    click WEBSERVER "https://github.com/yoshi-782/swab2/blob/master/source/WebServer.cs"
```
