# switchbrew/libnx architecture

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

- Interactive diagram: https://gitdiagram.com/switchbrew/libnx
- Repository: https://github.com/switchbrew/libnx

## Overview

libnx is a Nintendo Switch AArch64 userland library: it gives homebrew applications runtime support and C APIs for kernel operations, system services, applets, and hardware-facing features. The typical path is application code → libnx runtime or feature API → IPC/syscall boundary → Horizon services or kernel → result returned to the application. The tree and excerpts support the major capability areas below; many individual service implementations were not sampled, so their internal wiring is intentionally summarized.

Main entry points: [`nx/include/switch/kernel`](https://github.com/switchbrew/libnx/tree/master/nx/include/switch/kernel) (Kernel APIs), [`nx/source/services`](https://github.com/switchbrew/libnx/tree/master/nx/source/services) (System services), [`nx/include/switch/sf/service.h`](https://github.com/switchbrew/libnx/blob/master/nx/include/switch/sf/service.h) (Service IPC), [`nx/source/runtime/init.c`](https://github.com/switchbrew/libnx/blob/master/nx/source/runtime/init.c) (Runtime setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and kernel"]
  node_runtime_init["Runtime setup<br/>[init.c]"]
  node_runtime_devices["Runtime devices"]
  node_kernel_api["Kernel APIs"]
end

subgraph group_ipc["IPC and services"]
  node_sf_ipc["Service IPC<br/>[service.h]"]
  node_session_mgr["Session manager<br/>[sessionmgr.c]"]
  node_system_services["System services"]
  node_applet_service["Applet service<br/>[applet.c]"]
  node_filesystem["Filesystem service<br/>[fs.c]"]
end

subgraph group_user_features["User-facing features"]
  node_applets["Applet wrappers"]
end

subgraph group_hardware["Hardware APIs"]
  node_display["Display and buffers"]
  node_audio["Audio engine"]
  node_nvidia["NVIDIA GPU"]
end

subgraph group_utilities["Utility APIs"]
  node_crypto["Cryptography"]
  node_network["Network runtime"]
  node_bluetooth["Bluetooth runtime<br/>[btdev.c]"]
end

node_application(("Homebrew application"))
node_kernel_os{{"Horizon kernel"}}
node_switch_os{{"Horizon services"}}

node_application -->|"starts through"| node_runtime_init
node_application -->|"uses"| node_kernel_api
node_application -->|"calls"| node_system_services
node_application -->|"launches"| node_applets
node_runtime_init -->|"initializes"| node_kernel_api
node_runtime_devices -->|"uses"| node_kernel_api
node_kernel_api -->|"issues syscalls"| node_kernel_os
node_system_services -->|"sends requests"| node_sf_ipc
node_sf_ipc -->|"transfers IPC"| node_switch_os
node_session_mgr -->|"synchronizes via"| node_kernel_api
node_applets -->|"launches through"| node_applet_service
node_applet_service -->|"sends requests"| node_sf_ipc
node_display -->|"uses services"| node_system_services
node_audio -->|"uses services"| node_system_services
node_nvidia -->|"uses syscalls"| node_kernel_api
node_bluetooth -->|"calls"| node_system_services
node_filesystem -->|"sends requests"| node_sf_ipc

click node_runtime_init "https://github.com/switchbrew/libnx/blob/master/nx/source/runtime/init.c"
click node_runtime_devices "https://github.com/switchbrew/libnx/tree/master/nx/source/runtime/devices"
click node_kernel_api "https://github.com/switchbrew/libnx/tree/master/nx/include/switch/kernel"
click node_sf_ipc "https://github.com/switchbrew/libnx/blob/master/nx/include/switch/sf/service.h"
click node_session_mgr "https://github.com/switchbrew/libnx/blob/master/nx/source/sf/sessionmgr.c"
click node_system_services "https://github.com/switchbrew/libnx/tree/master/nx/source/services"
click node_applets "https://github.com/switchbrew/libnx/tree/master/nx/source/applets"
click node_applet_service "https://github.com/switchbrew/libnx/blob/master/nx/source/services/applet.c"
click node_display "https://github.com/switchbrew/libnx/tree/master/nx/source/display"
click node_audio "https://github.com/switchbrew/libnx/tree/master/nx/source/audio"
click node_nvidia "https://github.com/switchbrew/libnx/tree/master/nx/source/nvidia"
click node_crypto "https://github.com/switchbrew/libnx/tree/master/nx/source/crypto"
click node_network "https://github.com/switchbrew/libnx/tree/master/nx/source/runtime"
click node_bluetooth "https://github.com/switchbrew/libnx/blob/master/nx/source/runtime/btdev.c"
click node_filesystem "https://github.com/switchbrew/libnx/blob/master/nx/source/services/fs.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_runtime_init,node_runtime_devices,node_kernel_api toneBlue
class node_sf_ipc,node_session_mgr,node_system_services,node_applet_service,node_filesystem toneAmber
class node_applets toneMint
class node_display,node_audio,node_nvidia toneRose
class node_crypto,node_network,node_bluetooth,node_application,node_kernel_os,node_switch_os toneIndigo
```

## Components

### Runtime and kernel

- [Runtime setup](https://github.com/switchbrew/libnx/blob/master/nx/source/runtime/init.c): `nx/source/runtime/init.c`
- [Runtime devices](https://github.com/switchbrew/libnx/tree/master/nx/source/runtime/devices): `nx/source/runtime/devices`
- [Kernel APIs](https://github.com/switchbrew/libnx/tree/master/nx/include/switch/kernel): `nx/include/switch/kernel`

### IPC and services

- [Service IPC](https://github.com/switchbrew/libnx/blob/master/nx/include/switch/sf/service.h): `nx/include/switch/sf/service.h`
- [Session manager](https://github.com/switchbrew/libnx/blob/master/nx/source/sf/sessionmgr.c): `nx/source/sf/sessionmgr.c`
- [System services](https://github.com/switchbrew/libnx/tree/master/nx/source/services): `nx/source/services`
- [Applet service](https://github.com/switchbrew/libnx/blob/master/nx/source/services/applet.c): `nx/source/services/applet.c`
- [Filesystem service](https://github.com/switchbrew/libnx/blob/master/nx/source/services/fs.c): `nx/source/services/fs.c`

### User-facing features

- [Applet wrappers](https://github.com/switchbrew/libnx/tree/master/nx/source/applets): `nx/source/applets`

### Hardware APIs

- [Display and buffers](https://github.com/switchbrew/libnx/tree/master/nx/source/display): `nx/source/display`
- [Audio engine](https://github.com/switchbrew/libnx/tree/master/nx/source/audio): `nx/source/audio`
- [NVIDIA GPU](https://github.com/switchbrew/libnx/tree/master/nx/source/nvidia): `nx/source/nvidia`

### Utility APIs

- [Cryptography](https://github.com/switchbrew/libnx/tree/master/nx/source/crypto): `nx/source/crypto`
- [Network runtime](https://github.com/switchbrew/libnx/tree/master/nx/source/runtime): `nx/source/runtime`
- [Bluetooth runtime](https://github.com/switchbrew/libnx/blob/master/nx/source/runtime/btdev.c): `nx/source/runtime/btdev.c`

### Other components

- **Homebrew application**
- **Horizon kernel**
- **Horizon services**

## Connections

- Homebrew application → Runtime setup: starts through
- Homebrew application → Kernel APIs: uses
- Homebrew application → System services: calls
- Homebrew application → Applet wrappers: launches
- Runtime setup → Kernel APIs: initializes
- Runtime devices → Kernel APIs: uses
- Kernel APIs → Horizon kernel: issues syscalls
- System services → Service IPC: sends requests
- Service IPC → Horizon services: transfers IPC
- Session manager → Kernel APIs: synchronizes via
- Applet wrappers → Applet service: launches through
- Applet service → Service IPC: sends requests
- Display and buffers → System services: uses services
- Audio engine → System services: uses services
- NVIDIA GPU → Kernel APIs: uses syscalls
- Bluetooth runtime → System services: calls
- Filesystem service → Service IPC: sends requests
