# proconsule/nxmp architecture

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

- Interactive diagram: https://gitdiagram.com/proconsule/nxmp
- Repository: https://github.com/proconsule/nxmp

## Overview

##### Project Type & Purpose
- NXMP is a native C++ video‐player application for the Nintendo Switch, built atop the MPV playback engine.
- It supports local and networked sources (HTTP, FTP, SFTP, Samba, NFS, Enigma2), hardware decoding via Tegra X1/Deko3D, playlist management, and UI via ImGui.

##### High-Level Layers & Main Components
a. Presentation / UI Layer
- ImGui front-end (source/UI/*, include/UIHelpers.h)
- Input & navigation (touchcontrols, mapping of Switch buttons)
- Popups, menus, file browsers, video OSD
b. Application Logic
- Playback controller (main.cpp, utils.cpp)
- Media probing (source/mediaprobe)
- Playlist management (source/playlist)
- Settings & configuration (iniparser + config.ini)
- Localization (source/i18n + langs/*.json)
- Updater (source/updater)
- Logger & stats (source/logger, source/stats)
c. Data Access / I/O Layer
- Local file systems (source/localfs/*, USB support)
- MTP (source/curldownloader + mtpclass)
- Remote file systems: Enigma2, HTTPDir, UPNP (source/remotefs/…)
- Network shares: Samba, NFS (via libs/libsmb2, libs/libnfs)
- SQLite database for caching (source/database)
d. Playback & Rendering
- libmpv wrapper (source/libmpv)
- Hardware‐accelerated decode backends (source/backends/native-deko3d)
- Generic rendering abstraction (source/backends/nxmp-render)
- Shader assets in romfs/shaders
e. External Dependencies & Libraries
- ImGui (libs/imgui, libs/imgui_toggle)
- libnfs, libsmb2 for network FS
- simpleini, sqlite3, iniparser for config/DB
- libusbhsfs for USB support
- MPV, FFmpeg hints for HW decode

##### Interactions & Data Flow
- On startup, the Config module reads config.ini via iniparser → Settings are passed to UI, file modules, playback engine.
- UI Layer issues commands (open folder, play file, add network source) → calls Application Logic.
- Playback Controller invokes libmpv wrapper, passing URI.
- libmpv uses appropriate FS/Network module to fetch data.
- Data flows through decode backend (Deko3D) into render abstraction → display via ImGui surface.
- Logger & Stats record events, errors, performance metrics.
- Updater connects to GitHub (via HTTPDir/curldownloader) for version checks.

##### Architectural Patterns & Design Principles
- Layered architecture: clear separation between UI, business logic, data access, hardware/rendering.
- Plugin-style backends: each remote FS and render backend implements a common interface.
- Single Responsibility: each folder under source/* focuses on one domain (e.g., networkshareclass, mediaprobe).
- Configuration-driven initialization: iniparser central for extensibility.
- Resource separation: romfs holds shaders and static assets; libs folder contains external projects.

##### Final Recommendations
- Drill down into each layer to show modular subcomponents.
- Review with engineers responsible for each module to ensure accuracy of interfaces and data flows.

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Hardware / External"
    HW1["Tegra X1 GPU/Decoder"]:::hw
    Ext1["HTTP Server"]:::ext
    Ext2["FTP Server"]:::ext
    Ext3["Samba/NFS Shares"]:::ext
    Ext4["Enigma2 Box"]:::ext
  end

  subgraph "Data Access / I/O Layer"
    LocalFS["Local FS"]:::io
    MTP["MTP & HTTP Downloader"]:::io
    RemoteFS_Enigma2["Enigma2 FS"]:::io
    RemoteFS_HTTP["HTTPDir FS"]:::io
    RemoteFS_UPNP["UPNP FS"]:::io
    NetShares["Samba/NFS"]:::io
    SQLiteDB["SQLite Cache"]:::data
  end

  subgraph "Persistence"
    Iniparser["iniparser"]:::data
    Config["Settings & Config (ini)"]:::data
  end

  subgraph "Playback & Rendering"
    LibMPV["libmpv Wrapper"]:::logic
    Deko3D["Native Deko3D Backend"]:::logic
    RenderAbst["Rendering Abstraction"]:::logic
    Shaders["Shaders"]:::data
  end

  subgraph "Application Logic"
    PlaybackCtrl["Playback Controller"]:::logic
    Utils["Utils"]:::logic
    MediaProbe["Media Probe"]:::logic
    Playlist["Playlist Manager"]:::logic
    Localization["Localization"]:::logic
    Updater["Updater"]:::logic
    LoggerStats["Logger & Stats"]:::logic
  end

  subgraph "Presentation / UI Layer"
    ImGui["ImGui Front-End"]:::ui
    Touch["Touch Controls"]:::ui
    Popups["Popups & Menus"]:::ui
    FileBrowser["File Browser & OSD"]:::ui
  end

  Iniparser -->|parses ini| Config
  Config -->|provides settings| ImGui
  Config -->|provides settings| LocalFS
  Config -->|provides settings| PlaybackCtrl

  Touch -->|input| ImGui
  Popups --> ImGui
  FileBrowser --> ImGui
  ImGui -->|user commands| PlaybackCtrl

  PlaybackCtrl -->|uses utils| Utils
  PlaybackCtrl -->|controls playback| LibMPV
  PlaybackCtrl -->|manages playlist| Playlist
  PlaybackCtrl -->|probes media| MediaProbe
  PlaybackCtrl --> LoggerStats

  Utils --> Playlist

  LibMPV --> LocalFS
  LibMPV --> MTP
  LibMPV --> RemoteFS_Enigma2
  LibMPV --> RemoteFS_HTTP
  LibMPV --> RemoteFS_UPNP
  LibMPV --> NetShares
  LibMPV --> SQLiteDB

  LibMPV --> Deko3D
  Deko3D --> RenderAbst
  RenderAbst --> Shaders
  RenderAbst --> ImGui

  LocalFS --> HW1
  MTP --> Ext1
  MTP --> Ext2
  RemoteFS_HTTP --> Ext1
  RemoteFS_Enigma2 --> Ext4
  RemoteFS_UPNP --> Ext4
  NetShares --> Ext3

  Playlist --> SQLiteDB
  LoggerStats --> SQLiteDB
  Updater --> Ext1

  Localization -->|loads JSON| ImGui

  classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
  classDef logic fill:#98FB98,stroke:#000,stroke-width:1px
  classDef io fill:#FFA500,stroke:#000,stroke-width:1px
  classDef data fill:#20B2AA,stroke:#000,stroke-width:1px
  classDef hw fill:#D3D3D3,stroke:#000,stroke-width:1px
  classDef ext fill:#D3D3D3,stroke:#000,stroke-width:1px

  %% Click Events
  click UIHelpers "https://github.com/proconsule/nxmp/blob/master/include/UIHelpers.h"
  click AppPopups "https://github.com/proconsule/nxmp/blob/master/include/apppopups.h"
  click AppWindows "https://github.com/proconsule/nxmp/blob/master/include/appwindows.h"
  click GUI "https://github.com/proconsule/nxmp/blob/master/include/gui.h"
  click PlayerWindows "https://github.com/proconsule/nxmp/blob/master/include/playerwindows.h"
  click ImGui "https://github.com/proconsule/nxmp/tree/master/source/UI/"
  click Touch "https://github.com/proconsule/nxmp/blob/master/source/touchcontrols/touchcontrols.cpp"
  click PlaybackCtrl "https://github.com/proconsule/nxmp/blob/master/source/main.cpp"
  click Utils "https://github.com/proconsule/nxmp/blob/master/source/utils.cpp"
  click MediaProbe "https://github.com/proconsule/nxmp/blob/master/source/mediaprobe/mediaprobe.cpp"
  click Playlist "https://github.com/proconsule/nxmp/blob/master/source/playlist/playlist.cpp"
  click Iniparser "https://github.com/proconsule/nxmp/blob/master/source/iniparser/iniparser.cpp"
  click Config "https://github.com/proconsule/nxmp/blob/master/source/iniparser/iniparser.h"
  click Localization "https://github.com/proconsule/nxmp/blob/master/source/i18n/nxmp-i18n.cpp"
  click Updater "https://github.com/proconsule/nxmp/blob/master/source/updater/updater.cpp"
  click LoggerStats "https://github.com/proconsule/nxmp/blob/master/source/logger/logger.cpp"
  click LocalFS "https://github.com/proconsule/nxmp/blob/master/source/localfs/localFs.cpp"
  click MTP "https://github.com/proconsule/nxmp/blob/master/source/curldownloader/curldownloader.cpp"
  click RemoteFS_Enigma2 "https://github.com/proconsule/nxmp/blob/master/source/remotefs/Enigma2/Enigma2.cpp"
  click RemoteFS_HTTP "https://github.com/proconsule/nxmp/blob/master/source/remotefs/HTTPDir/HTTPDir.cpp"
  click RemoteFS_UPNP "https://github.com/proconsule/nxmp/blob/master/source/remotefs/UPNP/NX-UPNP.cpp"
  click NetShares "https://github.com/proconsule/nxmp/tree/master/libs/libsmb2/"
  click SQLiteDB "https://github.com/proconsule/nxmp/blob/master/source/database/SQLiteDB.cpp"
  click LibMPV "https://github.com/proconsule/nxmp/blob/master/source/libmpv/libmpv.cpp"
  click Deko3D "https://github.com/proconsule/nxmp/blob/master/source/backends/native-deko3d/imgui_deko3d.cpp"
  click RenderAbst "https://github.com/proconsule/nxmp/blob/master/source/backends/nxmp-render.cpp"
  click Shaders "https://github.com/proconsule/nxmp/blob/master/romfs/shaders/imgui_fsh.dksh"
```
