# morkt/garbro architecture

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

- Interactive diagram: https://gitdiagram.com/morkt/garbro
- Repository: https://github.com/morkt/garbro

## Overview

##### Main Components
- Core Archive Format Library (ArcFormats): This directory houses hundreds of classes, each implementing handlers for specific archive types and resources (images, audio, and sometimes encryption components). Highlight that these components may use design patterns (like Strategy or Factory) to determine which format to use.
- Resource Processing Core (GameRes and related libraries): Contains common routines to manipulate binary streams, decode images, calculate checksums, and support resource extraction logic.
- Graphical User Interface (GUI): Built with WPF (XAML files, code-behind) providing the interactive visual interface – main window, dialogs, settings, keybindings (as seen in the README).
- Console Application: A command-line front-end alternative supporting similar functionality.
- Ancillary/Utility Modules: The “Image.Convert,” “Experimental” and “Legacy” directories likely provide additional tools, conversion utilities, or older code that support or extend the core capabilities.
- Configuration and Resource Files: Includes config files (app.config, packages.config, etc.) and resource definitions such as language strings that support internationalization.
- External Dependencies: The project requires .NET Framework v4.6 or newer and references to external libraries (for tasks like audio playback and image conversion, e.g., NAudio).

##### Relationships and Interactions
- The user interacts through the GUI front-end (or alternative console interface), which then calls into the core libraries.
- The GUI layer sends file selection, extraction, or conversion requests to the Archive Format Library. This library identifies the format based on file’s signature or extension and then calls specialized modules.
- The core resource processing modules (GameRes, for example) manage tasks like stream reading, binary parsing, and data conversion for images and audio.
- A common file system abstraction exists which allows the application to treat archives like folders, enabling browsing into nested archive contents.
- Additional experimental or legacy components provide optional or fallback behaviors for formats not handled by the main code base.

##### Architectural Patterns and Design Principles
- Modularization: Functionality is strongly separated – one module per archive or file format, ensuring that handling a new format can be done with minimal impact on others.
- Layered Architecture: A clean separation between UI (GUI/Console) and business logic (archive processing and resource conversion).
- Extensibility: The use of many distinct classes for each archive type suggests an extensible design where adding support for a new format involves implementing a new component.
- Reusability: Core libraries (e.g., for stream handling, checksums, encryption) are shared among multiple format handlers.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interfaces Layer
    subgraph "User Interfaces Layer"
        GUI["GUI (WPF-based)"]:::ui
        Console["Console Application"]:::ui
    end

    %% Business Logic/Core Library Layer
    subgraph "Business Logic/Core Library Layer"
        ArchHandler["Archive Format Handler (ArcFormats)"]:::core
        ResourceProc["Resource Processing Core (GameRes)"]:::core
    end

    %% Data/Utility Layer
    subgraph "Data/Utility Layer"
        Config["Configuration & Resource Files"]:::data
        FileSys["File System Abstraction"]:::data
        Ancillary["Ancillary/Utility Modules"]:::data
    end

    %% Ancillary Detailed Modules
    subgraph "Ancillary/Utility Modules Detailed"
        ImageConvert["Image Conversion Utility"]:::utility
        Experimental["Experimental Modules"]:::utility
        Legacy["Legacy Modules"]:::utility
    end

    %% Data Flow Connections
    GUI -->|"user-interaction"| ArchHandler
    Console -->|"command-input"| ArchHandler
    ArchHandler -->|"format-detection"| ResourceProc
    ResourceProc -->|"process-streams"| Config
    ResourceProc -->|"uses-utilities"| Ancillary
    Config -->|"supplies-config"| ArchHandler
    FileSys -->|"abstracts-files"| ArchHandler
    GUI -->|"loads-strings"| Config

    %% External Dependencies
    Framework[".NET Framework 4.6+ & ThirdParty Libraries"]:::external
    ArchHandler ---|"dependency"| Framework
    ResourceProc ---|"dependency"| Framework
    GUI ---|"dependency"| Framework
    Console ---|"dependency"| Framework

    %% Ancillary Connections
    Ancillary --> ImageConvert
    Ancillary --> Experimental
    Ancillary --> Legacy

    %% Click Events
    click ArchHandler "https://github.com/morkt/garbro/blob/master/ArcFormats/ArcFormats.csproj"
    click ResourceProc "https://github.com/morkt/garbro/blob/master/GameRes/GameRes.csproj"
    click GUI "https://github.com/morkt/garbro/blob/master/GUI/MainWindow.xaml"
    click Console "https://github.com/morkt/garbro/blob/master/Console/ConsoleBrowser.cs"
    click ImageConvert "https://github.com/morkt/garbro/blob/master/Image.Convert/Program.cs"
    click Experimental "https://github.com/morkt/garbro/tree/master/Experimental/"
    click Legacy "https://github.com/morkt/garbro/blob/master/Legacy/Legacy.csproj"
    click Config "https://github.com/morkt/garbro/blob/master/GUI/App.config"

    %% Styles
    classDef ui fill:#D1E8FF,stroke:#0a75ad,stroke-width:2px;
    classDef core fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef data fill:#FFECB3,stroke:#FFA000,stroke-width:2px;
    classDef external fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
    classDef utility fill:#F8BBD0,stroke:#C2185B,stroke-width:2px;
```
