# cemu-project/cemu architecture

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

- Interactive diagram: https://gitdiagram.com/cemu-project/cemu
- Repository: https://github.com/cemu-project/cemu

## Overview

##### Project type and purpose
- Cemu is a native desktop application (Wii U emulator) written in C/C++.
- It’s a monolithic emulator with multiple subsystems: CPU, GPU, OS service emulation, audio, input, filesystem, GUI, networking, etc.
- The README confirms: “Cemu is a Wii U emulator… runs games, homebrew… Windows, Linux, macOS.”

##### File structure
- Top-level:
- cmake/, CMakeLists.txt, vcpkg.json – build system & package management
- dependencies/ – third-party libraries (Discord RPC, h264, gamemode, etc.)
- src/ – all emulator code, broken into logical modules (Cafe, Cemu, Common, audio, config, gui, input, resource, tools, util, etc.)
- bin/, dist/ – runtime resources, profiles, translations, packaging scripts
- Notice clear layering under src/:
- “Cafe” – Wii U CPU (Espresso), GPU (Latte), filesystem, game patch and profile
- “IOSU” & “OS” – emulated OS services and libraries
- “audio” – host audio backends (Cubeb, XAudio2, DirectSound)
- “input” – host and emulated controller layers
- “gui” & “imgui” – UI implemented with wxWidgets and ImGui backends (OpenGL/Vulkan)
- “Cemu” – glue code: expression parser, file cache, Discord presence, napi, networking (nex)
- “util” & “Common” – platform abstraction, threading, memory mapping, crypto, XML, etc.

##### Architecture extraction from README
- Core emulator engine → runs CPU & GPU subsystems
- GUI front-end → user interacts via windows, dialogs, debug views
- External Services → graphics (OpenGL/Vulkan/DX), audio APIs, input APIs, networking (nex), filesystem
- Configuration & resource loader → parses XML, .ini, embedded resources

##### Detail
- Every major subsystem even if internal (e.g., FileCache, DownloadManager, ExpressionParser).
- Inter-module calls and shared utilities (e.g., ExceptionHandler, SysAllocator).
- Avoid over-simplification: Cemu is a complex layered emulator, so it pays off to show all layers.

## Diagram (Mermaid)

```mermaid
graph TB
    %% GUI Layer
    subgraph "GUI Layer" 
        style GUI fill:#fddf9b,stroke:#f6941d
        GUI_WX["wxWidgets GUI"] 
        GUI_ImGui["ImGui Overlay"]
    end

    %% Core Emulation Engine
    subgraph "Core Emulation Engine"
        style Core fill:#9bc1fb,stroke:#3e78b2
        CPU["Espresso CPU\n(Interpreter + JIT)"]
        GPU["Latte GPU\n(Command Processor & Renderers)"]
        MMU["Memory Management & MMU"]
        FS["Filesystem (FST, WUD, WUHB)"]
        IOSU["OS Services (IOSU)"]
        OS_LIB["OS Libraries (OS)"]
    end

    %% Support Subsystems
    subgraph "Support Subsystems"
        style Support fill:#d4bfff,stroke:#8f43cf
        Audio["Audio Subsystem"]
        Input["Input Subsystem"]
        Net["Networking (PRUDP & NEX)"]
        FileCache["File Cache Manager"]
        DownloadMgr["Download Manager"]
        Discord["Discord Presence Integration"]
        Logging["Logging & Debugging Service"]
        ExprParser["Expression Parser"]
        PPCAsm["PPC Assembler"]
    end

    %% Host Abstraction Layer
    subgraph "Host Abstraction Layer"
        style Host fill:#b7e4c7,stroke:#35a16a
        Common["Common Utilities"]
        Util["Platform Abstraction & Utilities"]
        GraphicsAPI["Graphics API Wrappers\n(OpenGL/Vulkan Canvas)"]
    end

    %% External & Build
    subgraph "External & Build"
        style External fill:#eeeeee,stroke:#999999
        Build["Build System & Package Management"]
        Deps["Third-Party Dependencies"]
    end

    %% Relationships
    Build -->|initializes| Common
    Build -->|loads dependencies| Deps
    GUI_WX -->|"user events"| CPU
    GUI_ImGui -->|"overlays"| GPU
    CPU -->|reads/writes| MMU
    CPU -->|syscalls| IOSU
    CPU -->|parses expressions| ExprParser
    CPU -->|assembles code| PPCAsm
    GPU -->|dispatch commands| GraphicsAPI
    FS -->|file I/O| Common
    IOSU -->|OS calls| Common
    OS_LIB -->|library calls| Common
    CPU -->|"audio buffers"| Audio
    CPU -->|"input registers"| Input
    CPU -->|"network calls"| Net
    FileCache -->|caches files| FS
    DownloadMgr -->|downloads resources| FS
    Discord -->|presence updates| Deps
    Logging -->|hooks| CPU
    ExprParser -->|used by| CPU
    PPCAsm -->|used by| CPU
    Audio -->|uses| Deps
    Input -->|providers| Deps
    Net -->|sockets| Util
    GraphicsAPI -->|graphics API| Deps
    Common -->|platform I/O| Util

    %% Click Events
    click GUI_WX "https://github.com/cemu-project/cemu/tree/main/src/gui"
    click GUI_ImGui "https://github.com/cemu-project/cemu/tree/main/src/imgui"
    click CPU "https://github.com/cemu-project/cemu/tree/main/src/Cafe/HW/Espresso"
    click GPU "https://github.com/cemu-project/cemu/tree/main/src/Cafe/HW/Latte"
    click MMU "https://github.com/cemu-project/cemu/tree/main/src/Cafe/HW/MMU"
    click FS "https://github.com/cemu-project/cemu/tree/main/src/Cafe/Filesystem"
    click IOSU "https://github.com/cemu-project/cemu/tree/main/src/Cafe/IOSU"
    click OS_LIB "https://github.com/cemu-project/cemu/tree/main/src/Cafe/OS"
    click Audio "https://github.com/cemu-project/cemu/tree/main/src/audio"
    click Input "https://github.com/cemu-project/cemu/tree/main/src/input"
    click Net "https://github.com/cemu-project/cemu/tree/main/src/Cemu/nex"
    click FileCache "https://github.com/cemu-project/cemu/tree/main/src/Cemu/FileCache"
    click DownloadMgr "https://github.com/cemu-project/cemu/tree/main/src/Cemu/Tools/DownloadManager"
    click Discord "https://github.com/cemu-project/cemu/tree/main/src/Cemu/DiscordPresence"
    click Logging "https://github.com/cemu-project/cemu/tree/main/src/Cemu/Logging"
    click ExprParser "https://github.com/cemu-project/cemu/tree/main/src/Cemu/ExpressionParser"
    click PPCAsm "https://github.com/cemu-project/cemu/tree/main/src/Cemu/PPCAssembler"
    click Common "https://github.com/cemu-project/cemu/tree/main/src/Common"
    click Util "https://github.com/cemu-project/cemu/tree/main/src/util"
    click Build "https://github.com/cemu-project/cemu/blob/main/CMakeLists.txt"
    click Deps "https://github.com/cemu-project/cemu/tree/main/dependencies/"

    %% Styles
    classDef GUI fill:#fddf9b,stroke:#f6941d,color:#000
    classDef Core fill:#9bc1fb,stroke:#3e78b2,color:#000
    classDef Support fill:#d4bfff,stroke:#8f43cf,color:#000
    classDef Host fill:#b7e4c7,stroke:#35a16a,color:#000
    classDef External fill:#eeeeee,stroke:#999999,color:#000

    class GUI_WX,GUI_ImGui GUI
    class CPU,GPU,MMU,FS,IOSU,OS_LIB Core
    class Audio,Input,Net,FileCache,DownloadMgr,Discord,Logging,ExprParser,PPCAsm Support
    class Common,Util,GraphicsAPI Host
    class Build,Deps External
```
