# openemu/openemu architecture

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

- Interactive diagram: https://gitdiagram.com/openemu/openemu
- Repository: https://github.com/openemu/openemu

## Overview

##### Main Components
- Main OpenEmu Application – This is the native macOS application (written in Swift/Objective-C) that sets up the user interface, handles user interactions, and coordinates the overall workflow.
- Frameworks & Third-Party Libraries – Include supporting components like Sparkle (for auto-updating), UniversalDetector, XADMaster, and system-level frameworks (Cocoa, Metal, Core Animation). These components work behind the scenes and provide essential functionality.
- System Plugins – From the file structure, there is a “SystemPlugins” directory where platform-specific integration (for various consoles’ controller mappings, preferences, images, and system-specific view controllers) resides. Treat this as a sub-category of plugins that interact with both the UI and the core engines.
- Supporting Assets – Resources such as image assets, localized strings, mapping models, and configuration files that ensure the UI and core management operate seamlessly.

##### Relationships and Interactions
- The OpenEmu Application (UI layer) communicates directly with the Plugin/Core Manager.
- The Plugin Manager then dynamically loads the respective emulator cores (each provided as a plugin) based on user selection.
- Data flows from the user interface (using macOS technologies like Cocoa, Metal, and Core Animation) into core-specific adapters. Each plugin is essentially an independent “engine” that receives input from the core manager and outputs video, sound, and game data.
- External frameworks (like Sparkle) interact with the application for updating, and libraries such as UniversalDetector are used to assist with file handling and ROM importing.
- The build system (evident from numerous Xcode workspace, project files, and configuration files) ties together these components for compilation and packaging.

##### Architectural Patterns/Design Principles
- Modular plugin architecture – separate emulator cores from the main UI, promoting extensibility.
- Separation of concerns – clear division between UI rendering, core engine management, and lower-level emulation processing.
- Dynamic loading – the system supports the loading and updating of emulation engines without tightly coupling them to the main application.
- Native macOS integration – emphasizing strong use of Cocoa, Metal, and Core Animation for a first-class user experience.

##### Relevant Technologies and Frameworks
- Languages & Technologies: Objective-C and Swift for the main application code.
- macOS frameworks: Cocoa, Metal, Core Animation.
- Third-party libraries: Sparkle (auto-updating), UniversalDetector, XADMaster.
- Emulator plugins: Individual cores (such as Stella, Nestopia, Mupen64Plus, etc.) each acting as independent modules.

##### Visualization Details
- On the opposite side, list all the “Emulation Engines/Plugins” in a grouped container.
- Additionally, link out to “Supporting Libraries” and “Resources.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    subgraph "Application Layer"
        UI["Main OpenEmu Application (UI)"]:::frontend
        MF["macOS Frameworks (Cocoa,Metal,CoreAnimation)"]:::framework
    end

    %% Core Manager
    CM["Plugin/Core Manager"]:::manager

    %% Emulation Engines/Plugins Layer
    subgraph "Emulation Engines/Plugins"
        PS["Emulation Plugin - Atari 2600 (Stella)"]:::plugin
        PN["Emulation Plugin - NES (Nestopia)"]:::plugin
        PM["Emulation Plugin - N64 (Mupen64Plus)"]:::plugin
        SP["System Plugins"]:::plugin
    end

    %% Frameworks & Third-Party Libraries
    subgraph "Frameworks & Third-Party Libraries"
        UD["UniversalDetector.framework"]:::framework
        XAD["XADMaster.framework"]:::framework
        SPK["Sparkle (Auto-Updating)"]:::framework
    end

    %% Supporting Assets
    subgraph "Supporting Assets"
        GA["Graphics & Assets"]:::asset
        LR["Localized Resources"]:::asset
        MM["Mapping Models"]:::asset
    end

    %% Connections between main layers
    UI -->|"UICommands"| CM
    CM -->|"CoreLoading"| PS
    CM -->|"CoreLoading"| PN
    CM -->|"CoreLoading"| PM
    CM -->|"Manages"| SP
    PS -->|"RenderingOutput"| UI
    PN -->|"RenderingOutput"| UI
    PM -->|"RenderingOutput"| UI

    %% Connections with Frameworks & Assets
    MF ---|"Provides Rendering"| UI
    UD ---|"FileHandling"| CM
    XAD ---|"FileHandling"| CM
    SPK ---|"UpdateCheck"| UI

    GA ---|"AssetUsage"| UI
    LR ---|"Localization"| UI
    MM ---|"ModelMapping"| CM

    %% Styles
    classDef frontend fill:#a8d8ea,stroke:#03396c,stroke-width:2px;
    classDef manager fill:#90be6d,stroke:#006400,stroke-width:2px;
    classDef plugin fill:#ffb347,stroke:#ff7f50,stroke-width:2px;
    classDef framework fill:#d3d3d3,stroke:#808080,stroke-width:2px;
    classDef asset fill:#ffcccb,stroke:#cc0000,stroke-width:2px;

    %% Click Events
    click UI "https://github.com/openemu/openemu/blob/master/OpenEmu/AppDelegate.swift"
    click CM "https://github.com/openemu/openemu/blob/master/OpenEmu/CoreDownload.swift"
    click UD "https://github.com/openemu/openemu/blob/master/OpenEmu/UniversalDetector.framework"
    click XAD "https://github.com/openemu/openemu/blob/master/OpenEmu/XADMaster.framework"
    click SP "https://github.com/openemu/openemu/tree/master/OpenEmu/SystemPlugins"
    click GA "https://github.com/openemu/openemu/blob/master/OpenEmu/Graphics.xcassets"
    click MM "https://github.com/openemu/openemu/blob/master/OpenEmu/*.xcmappingmodel"
    click PS "https://github.com/openemu/openemu/tree/master/Stella"
    click PN "https://github.com/openemu/openemu/tree/master/Nestopia"
    click PM "https://github.com/openemu/openemu/tree/master/Mupen64Plus"
```
