# biaogo/foundation-sunshine-linux architecture

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

- Interactive diagram: https://gitdiagram.com/biaogo/foundation-sunshine-linux
- Repository: https://github.com/biaogo/foundation-sunshine-linux

## Overview

Sunshine is a self-hosted Moonlight game-streaming host. The principal workflow is client pairing and configuration, application launch, capture and encoding of host audio/video, then delivery to Moonlight; client input returns to the host. The map also preserves platform capture/display capabilities, virtual displays, and network discovery. The README and tree establish these product areas, but the sampled source is partial, so uncertain internal call wiring is omitted.

Main entry points: [`src/stream.cpp`](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/stream.cpp) (Stream coordination), [`src/network.cpp`](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/network.cpp) (Network transport), [`src/main.cpp`](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/main.cpp) (Application entry), [`src/confighttp.cpp`](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/confighttp.cpp) (HTTP management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_management["Management"]
  node_main["Application entry<br/>[main.cpp]"]
  node_config["Configuration<br/>[config.cpp]"]
  node_http["HTTP management<br/>[confighttp.cpp]"]
  node_files["Web assets<br/>[file_handler.cpp]"]
  node_pairing["Client pairing<br/>[nvhttp.cpp]"]
  node_state[("Runtime state<br/>[globals.cpp]")]
end

subgraph group_session["Streaming session"]
  node_apps["Application launch<br/>[process.cpp]"]
  node_rtsp["RTSP sessions<br/>[rtsp.cpp]"]
  node_stream["Stream coordination<br/>[stream.cpp]"]
end

subgraph group_media["Media pipeline"]
  node_video["Video capture<br/>[video.cpp]"]
  node_encoder["NVENC encoding<br/>[nvenc_base.cpp]"]
  node_audio["Audio capture<br/>[audio.cpp]"]
  node_mic["Microphone stream<br/>[mic_stream.cpp]"]
end

subgraph group_platform["Platform I/O"]
  node_input["Client input<br/>[input.cpp]"]
  node_display["Display management<br/>[display_device.cpp]"]
  node_virtualdisplay["Linux virtual display"]
  node_capture["Linux capture<br/>[kmsgrab.cpp]"]
end

subgraph group_networking["Networking"]
  node_transport["Network transport<br/>[network.cpp]"]
  node_discovery["UPnP discovery<br/>[upnp.cpp]"]
end

node_moonlight(("Moonlight client"))
node_browser(("Web browser"))
node_host{{"Host display and devices"}}

node_browser -->|"configures via"| node_http
node_http -->|"updates settings"| node_config
node_http -->|"serves UI"| node_files
node_moonlight -->|"pairs with"| node_pairing
node_pairing -->|"records client"| node_state
node_main -->|"loads settings"| node_config
node_main -->|"refreshes apps"| node_apps
node_moonlight -->|"requests session"| node_rtsp
node_rtsp -->|"coordinates session"| node_stream
node_stream -->|"launches app"| node_apps
node_stream -->|"requests frames"| node_video
node_video -->|"captures frames"| node_capture
node_capture -->|"reads display"| node_host
node_video -->|"encodes frames"| node_encoder
node_stream -->|"requests audio"| node_audio
node_audio -->|"reads audio"| node_host
node_stream -->|"sends media"| node_transport
node_transport -->|"delivers stream"| node_moonlight
node_moonlight -->|"sends input"| node_transport
node_transport -->|"dispatches input"| node_input
node_input -->|"controls devices"| node_host
node_moonlight -->|"sends microphone audio"| node_mic
node_mic -->|"outputs audio"| node_host
node_display -->|"manages displays"| node_host
node_display -.->|"offers virtual display"| node_virtualdisplay
node_virtualdisplay -.->|"configures display"| node_host
node_main -.->|"supports discovery"| node_discovery
node_transport -.->|"maps ports"| node_discovery

click node_main "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/main.cpp"
click node_config "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/config.cpp"
click node_http "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/confighttp.cpp"
click node_files "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/file_handler.cpp"
click node_pairing "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/nvhttp.cpp"
click node_apps "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/process.cpp"
click node_rtsp "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/rtsp.cpp"
click node_stream "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/stream.cpp"
click node_video "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/video.cpp"
click node_encoder "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/nvenc/nvenc_base.cpp"
click node_audio "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/audio.cpp"
click node_mic "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/mic_stream.cpp"
click node_input "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/input.cpp"
click node_display "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/display_device.cpp"
click node_virtualdisplay "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/platform/linux/virtual_display.cpp"
click node_capture "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/platform/linux/kmsgrab.cpp"
click node_transport "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/network.cpp"
click node_discovery "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/upnp.cpp"
click node_state "https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/globals.cpp"

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_main,node_config,node_http,node_files,node_pairing,node_state,node_moonlight,node_browser toneBlue
class node_apps,node_rtsp,node_stream toneAmber
class node_video,node_encoder,node_audio,node_mic toneMint
class node_input,node_display,node_virtualdisplay,node_capture toneRose
class node_transport,node_discovery,node_host toneIndigo
```

## Components

### Management

- [Application entry](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/main.cpp): `src/main.cpp`
- [Configuration](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/config.cpp): `src/config.cpp`
- [HTTP management](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/confighttp.cpp): `src/confighttp.cpp`
- [Web assets](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/file_handler.cpp): `src/file_handler.cpp`
- [Client pairing](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/nvhttp.cpp): `src/nvhttp.cpp`
- [Runtime state](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/globals.cpp): `src/globals.cpp`

### Streaming session

- [Application launch](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/process.cpp): `src/process.cpp`
- [RTSP sessions](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/rtsp.cpp): `src/rtsp.cpp`
- [Stream coordination](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/stream.cpp): `src/stream.cpp`

### Media pipeline

- [Video capture](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/video.cpp): `src/video.cpp`
- [NVENC encoding](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/nvenc/nvenc_base.cpp): `src/nvenc/nvenc_base.cpp`
- [Audio capture](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/audio.cpp): `src/audio.cpp`
- [Microphone stream](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/mic_stream.cpp): `src/mic_stream.cpp`

### Platform I/O

- [Client input](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/input.cpp): `src/input.cpp`
- [Display management](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/display_device.cpp): `src/display_device.cpp`
- [Linux virtual display](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/platform/linux/virtual_display.cpp): `src/platform/linux/virtual_display.cpp`
- [Linux capture](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/platform/linux/kmsgrab.cpp): `src/platform/linux/kmsgrab.cpp`

### Networking

- [Network transport](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/network.cpp): `src/network.cpp`
- [UPnP discovery](https://github.com/biaogo/foundation-sunshine-linux/blob/refork/linux/src/upnp.cpp): `src/upnp.cpp`

### Other components

- **Moonlight client**
- **Web browser**
- **Host display and devices**

## Connections

- Web browser → HTTP management: configures via
- HTTP management → Configuration: updates settings
- HTTP management → Web assets: serves UI
- Moonlight client → Client pairing: pairs with
- Client pairing → Runtime state: records client
- Application entry → Configuration: loads settings
- Application entry → Application launch: refreshes apps
- Moonlight client → RTSP sessions: requests session
- RTSP sessions → Stream coordination: coordinates session
- Stream coordination → Application launch: launches app
- Stream coordination → Video capture: requests frames
- Video capture → Linux capture: captures frames
- Linux capture → Host display and devices: reads display
- Video capture → NVENC encoding: encodes frames
- Stream coordination → Audio capture: requests audio
- Audio capture → Host display and devices: reads audio
- Stream coordination → Network transport: sends media
- Network transport → Moonlight client: delivers stream
- Moonlight client → Network transport: sends input
- Network transport → Client input: dispatches input
- Client input → Host display and devices: controls devices
- Moonlight client → Microphone stream: sends microphone audio
- Microphone stream → Host display and devices: outputs audio
- Display management → Host display and devices: manages displays
- Display management → Linux virtual display: offers virtual display
- Linux virtual display → Host display and devices: configures display
- Application entry → UPnP discovery: supports discovery
- Network transport → UPnP discovery: maps ports
