# mythicapp/mythic architecture

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

## Overview

##### Project type and purpose
- From the file tree and README, Mythic is a Swift/SwiftUI macOS application—an open-source game launcher and GUI frontend for the Legendary CLI.
- It coordinates multiple subsystems (Engine for DirectX support, Wine, Legendary CLI, Epic Games auth, Discord RPC, auto-updates via Sparkle) to manage, download, and launch Windows games on macOS.

##### High-level architecture layers
- Presentation Layer
- All SwiftUI views under `Mythic/Views` (Navigation, Unified modules, Sheets, Windows)
- `MythicApp.swift`, `ContentView.swift` → entry point and root view
- ViewModel / Presentation Logic
- ViewModel classes in `Mythic/Views/Unified/Models` (e.g., `GameCardVM`, `GameListEvoVM`)
- Bind the UI to business services
- Domain/Business Logic Layer
- `Mythic/Utilities`
– Engine interfaces (`Engine.swift`, `EngineExt.swift`) for DirectX
– `LegendaryInterface.swift` & `LegendaryInterfaceExt.swift` call the embedded Legendary Python CLI
– `WineInterface.swift` & `WineInterfaceExt.swift` invoke Wine to run Windows binaries
– `LocalGames.swift` / `LocalGamesExt.swift` manage scanning local game containers
– `VariableManager.swift`, `FileLocations.swift` manage env vars and file paths
– `SparkleController.swift` for auto-update checks
– `NetworkMonitor.swift` for offline/online state
- Data Access / Utilities
- JSON parsing via SwiftyJSON
- ZIP handling via ZIPFoundation
- SemanticVersion for version parsing
- Caching images via swiftui-cached-asyncimage
- Persistence
- UserDefaults (via extension) for settings
- On-disk container metadata and downloaded game files
- External / Third-party Dependencies
- Legendary CLI (embedded Python environment in `Mythic/legendary/_internal`)
- Wine (dynamic libs under `Mythic/Utilities/Wine`)
- Metal-based UI libs: ColorfulX, Glur
- Sparkle (auto-updates)
- Discord RPC (via SwordRPC extension)
- Epic Games WebAuth (via SwiftUI WebView)

##### Relationships and interactions
- UI Layer → ViewModels → calls Business Logic services
- Business Logic → invokes external engines/CLIs (Engine, Legendary, Wine)
- Business Logic → reads/writes container metadata & game downloads on the file system
- Business Logic → persists settings to UserDefaults
- SparkleController periodically checks for updates → notifies UI
- NetworkMonitor broadcasts connectivity changes to Presentation Layer
- Epic WebAuth window issues authentication → returns tokens to LegendaryInterface

##### Architectural patterns & design principles
- MVVM: Views bind to ViewModels, which orchestrate domain services
- Layered architecture: clear separation of Presentation, Domain Logic, Data/Infrastructure, External Services
- Dependency inversion: protocols/extensions allow mocking Legendary/Wine interfaces for testing
- Single responsibility: each Utility class focuses on one subsystem (Engine, Wine, Legendary, Networking)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "macOS Application"
        subgraph "Presentation Layer"
            A1["MythicApp"]:::presentation
            A2["ContentView"]:::presentation
            A3["Navigation Views"]:::presentation
            A4["Unified Modules"]:::presentation
            A5a["Sheets"]:::presentation
            A5b["Windows"]:::presentation
        end

        subgraph "ViewModel Layer"
            B1["GameCardVM"]:::viewmodel
            B2["GameListEvoVM"]:::viewmodel
        end

        subgraph "Domain Services"
            C1["EngineService"]:::domain
            C2["LegendaryService"]:::domain
            C3["WineService"]:::domain
            C4["LocalGamesService"]:::domain
            C5["SparkleController"]:::domain
            C6["NetworkMonitor"]:::domain
            C7["VariableManager\n& FileLocations"]:::domain
        end

        subgraph "Data & Persistence"
            D1["UserDefaults"]:::data
            D2["SemanticVersion"]:::data
        end

        subgraph "External & Dependencies"
            E1["Legendary Python CLI"]:::external
            E2["Wine dylibs"]:::external
            E3["Discord RPC"]:::external
            E4["Epic Games WebAuth"]:::external
            E5["Sparkle Updater"]:::external
        end
    end

    %% Relationships
    A1 -->|launches| A2
    A2 -->|navigates to| A3
    A3 -->|opens| A4
    A4 -->|presents| A5a
    A4 -->|presents| A5b

    A4 -->|binds to| B1
    A4 -->|binds to| B2

    B1 -->|calls| C1
    B1 -->|calls| C2
    B1 -->|calls| C4
    B2 -->|calls| C2
    B2 -->|calls| C3

    C1 -->|uses| E2
    C2 -->|invokes| E1
    C3 -->|invokes| E2
    C4 -->|reads/writes| D1
    C5 -->|checks updates via| E5
    C6 -.->|notifies| A1
    C7 -->|stores config in| D1
    C7 -->|parses versions with| D2

    C2 -->|auth via| E4
    C3 -->|RPC via| E3

    %% Click Events
    click A1 "https://github.com/mythicapp/mythic/blob/main/Mythic/MythicApp.swift"
    click A2 "https://github.com/mythicapp/mythic/blob/main/Mythic/Views/Navigation/ContentView.swift"
    click A3 "https://github.com/mythicapp/mythic/tree/main/Mythic/Views/Navigation"
    click A4 "https://github.com/mythicapp/mythic/tree/main/Mythic/Views/Unified/Modules"
    click A5a "https://github.com/mythicapp/mythic/tree/main/Mythic/Views/Unified/Sheets"
    click A5b "https://github.com/mythicapp/mythic/tree/main/Mythic/Views/Unified/Windows"
    click B1 "https://github.com/mythicapp/mythic/blob/main/Mythic/Views/Unified/Models/GameCardVM.swift"
    click B2 "https://github.com/mythicapp/mythic/blob/main/Mythic/Views/Unified/Models/GameListEvoVM.swift"
    click C1 "https://github.com/mythicapp/mythic/blob/main/Mythic/Utilities/Engine/Engine.swift"
    click C2 "https://github.com/mythicapp/mythic/blob/main/Mythic/Utilities/Legendary/LegendaryInterface.swift"
    click C3 "https://github.com/mythicapp/mythic/blob/main/Mythic/Utilities/Wine/WineInterface.swift"
    click C4 "https://github.com/mythicapp/mythic/blob/main/Mythic/Utilities/Local/LocalGames.swift"
    click C5 "https://github.com/mythicapp/mythic/blob/main/Mythic/Utilities/SparkleController.swift"
    click C6 "https://github.com/mythicapp/mythic/blob/main/Mythic/Utilities/NetworkMonitor.swift"
    click C7 "https://github.com/mythicapp/mythic/blob/main/Mythic/Utilities/VariableManager.swift"
    click D1 "https://github.com/mythicapp/mythic/blob/main/Mythic/Utilities/Extensions/Built-in/UserDefaults.swift"
    click D2 "https://github.com/mythicapp/mythic/blob/main/Mythic/Utilities/Extensions/Built-in/SemanticVersion.swift"
    click E1 "https://github.com/mythicapp/mythic/tree/main/Mythic/legendary/_internal"
    click E3 "https://github.com/mythicapp/mythic/blob/main/Mythic/Utilities/Extensions/SwordRPC.swift"
    click E4 "https://github.com/mythicapp/mythic/blob/main/Mythic/Views/Unified/Windows/EpicWebAuthView.swift"

    %% Styles
    classDef presentation fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef viewmodel fill:#D0FFD6,stroke:#333,stroke-width:1px
    classDef domain fill:#C8E6C9,stroke:#333,stroke-width:1px
    classDef data fill:#EEEEEE,stroke:#333,stroke-width:1px
    classDef external fill:#FFE0B2,stroke:#333,stroke-width:1px
```
