# alanrpost/nightjar architecture

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

- Interactive diagram: https://gitdiagram.com/alanrpost/nightjar
- Repository: https://github.com/alanrpost/nightjar

## Overview

#### Purpose and execution model
Nightjar is a Windows desktop VPN client that converts imported proxy links into sing-box configurations and runs a system-wide TUN VPN. It supports VLESS, Shadowsocks, Trojan, Hysteria2, and TUIC, with profile-based connection management, kill switch, autostart, reconnect behavior, and application split tunneling.

Primary launch/build entry points are `run.py`, `app/main.py`, and `Nightjar.spec`. The application is packaged for Windows with `installer.iss`.

#### Desktop application shell
`app/main.py` owns application startup and the primary GUI lifecycle. `app/tray_app.py` provides system-tray interaction, allowing connection control after the main window is hidden or closed. UI workflows are implemented as dialogs rather than a web/API layer, including profile editing and raw JSON editing.

Relevant paths:
- `app/main.py`
- `app/tray_app.py`
- `app/edit_profile_dialog.py`

#### Profile ingestion and persistence
Connection links enter through clipboard or QR import, are parsed into normalized profile data, then persist in the local profile store. Protocol detection is automatic based on the imported URI scheme. Profile management is the boundary between user-facing configuration and sing-box-specific runtime configuration.

Relevant paths:
- `app/qr_import.py`
- `app/profile_parser.py`
- `app/profile_store.py`

#### sing-box configuration compilation
`app/singbox_config.py` translates a selected normalized profile plus application settings into the sing-box JSON configuration. This is the key adapter boundary: the rest of Nightjar works with its own profile/settings model, while sing-box receives its required outbound, TUN, routing, DNS, and logging configuration.

Relevant paths:
- `app/singbox_config.py`
- `app/profile_parser.py`
- `app/settings.py`

#### VPN process lifecycle and privileged networking
`app/singbox_manager.py` owns launching, monitoring, stopping, and recovering the external sing-box process. It is the core runtime control plane for connect/disconnect and operational status. TUN mode requires administrator privileges; startup elevation and cleanup of stale processes are handled outside the normal UI flow.

Relevant paths:
- `app/singbox_manager.py`
- `app/autostart.py`
- `app/cleanup.py`

#### Traffic policy and connection features
Traffic handling is expressed through generated sing-box routing policy. Split tunneling selects applications whose traffic receives special routing treatment; the kill switch and full-tunnel TUN behavior protect or redirect system traffic. GeoIP data can support geographic/routing decisions. Runtime statistics and speed testing feed connection visibility in the desktop UI.

Relevant paths:
- `app/split_tunnel_dialog.py`
- `app/geoip.py`
- `app/stats.py`

#### Local platform integration and state
The application is Windows-specific in its packaging, installation, elevation, process handling, and autostart behavior. `app/paths.py` centralizes filesystem locations, including the documented `%APPDATA%\vless-client\singbox.log` runtime log location. Settings, persisted profiles, and generated/runtime artifacts remain local; the principal external runtime is the sing-box executable/process rather than a hosted service.

Relevant paths:
- `app/paths.py`
- `app/settings.py`
- `installer.iss`

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop Shell"]
  node_main["Application startup<br/>desktop entry point<br/>[main.py]"]
  node_tray["System tray controls<br/>tray UI<br/>[tray_app.py]"]
  node_profile_editor["Profile editor<br/>dialog"]
  node_split_tunnel["Split tunnel selection<br/>dialog"]
end

subgraph group_profiles["Profiles &amp; Config"]
  node_qr_import["Clipboard / QR import<br/>import UI<br/>[qr_import.py]"]
  node_parser["Profile parser<br/>URI normalization<br/>[profile_parser.py]"]
  node_profile_store[("Local profile store<br/>persistence<br/>[profile_store.py]")]
  node_settings[("Application settings<br/>local settings<br/>[settings.py]")]
  node_config_compiler["sing-box config compiler<br/>configuration adapter<br/>[singbox_config.py]"]
end

subgraph group_runtime["VPN Runtime"]
  node_manager["sing-box lifecycle manager<br/>runtime control plane<br/>[singbox_manager.py]"]
  node_singbox{{"sing-box process<br/>external VPN runtime"}}
  node_stats["Runtime stats &amp; speed test<br/>connection telemetry<br/>[stats.py]"]
  node_geoip[("GeoIP routing data<br/>[geoip.py]")]
end

subgraph group_platform["Windows Integration"]
  node_paths["Local paths &amp; log location<br/>filesystem layout<br/>[paths.py]"]
  node_autostart["Windows autostart<br/>startup integration<br/>[autostart.py]"]
  node_cleanup["Elevated cleanup<br/>privileged process cleanup<br/>[cleanup.py]"]
  node_installer["Windows installer<br/>installer definition<br/>[installer.iss]"]
end

node_main -->|"hosts"| node_tray
node_main -->|"opens"| node_profile_editor
node_main -->|"imports through"| node_qr_import
node_main -->|"connect / disconnect"| node_manager
node_tray -->|"connection control"| node_manager
node_qr_import -->|"imports links"| node_parser
node_parser -->|"stores normalized profile"| node_profile_store
node_profile_editor -->|"updates"| node_profile_store
node_profile_store -->|"selected profile"| node_config_compiler
node_settings -->|"VPN settings"| node_config_compiler
node_split_tunnel -->|"saves app policy"| node_settings
node_geoip -->|"routing decisions"| node_config_compiler
node_config_compiler -->|"generated configuration"| node_manager
node_manager -->|"launches and monitors"| node_singbox
node_singbox -->|"runtime visibility"| node_stats
node_paths -->|"runtime artifact locations"| node_manager
node_autostart -.->|"starts application"| node_main
node_cleanup -.->|"removes stale processes"| node_singbox
node_installer -->|"packages"| node_main
node_installer -->|"installs integration"| node_autostart

click node_main "https://github.com/alanrpost/nightjar/blob/main/app/main.py"
click node_tray "https://github.com/alanrpost/nightjar/blob/main/app/tray_app.py"
click node_profile_editor "https://github.com/alanrpost/nightjar/blob/main/app/edit_profile_dialog.py"
click node_split_tunnel "https://github.com/alanrpost/nightjar/blob/main/app/split_tunnel_dialog.py"
click node_qr_import "https://github.com/alanrpost/nightjar/blob/main/app/qr_import.py"
click node_parser "https://github.com/alanrpost/nightjar/blob/main/app/profile_parser.py"
click node_profile_store "https://github.com/alanrpost/nightjar/blob/main/app/profile_store.py"
click node_settings "https://github.com/alanrpost/nightjar/blob/main/app/settings.py"
click node_config_compiler "https://github.com/alanrpost/nightjar/blob/main/app/singbox_config.py"
click node_manager "https://github.com/alanrpost/nightjar/blob/main/app/singbox_manager.py"
click node_stats "https://github.com/alanrpost/nightjar/blob/main/app/stats.py"
click node_geoip "https://github.com/alanrpost/nightjar/blob/main/app/geoip.py"
click node_paths "https://github.com/alanrpost/nightjar/blob/main/app/paths.py"
click node_autostart "https://github.com/alanrpost/nightjar/blob/main/app/autostart.py"
click node_cleanup "https://github.com/alanrpost/nightjar/blob/main/app/cleanup.py"
click node_installer "https://github.com/alanrpost/nightjar/blob/main/installer.iss"

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_tray,node_profile_editor,node_split_tunnel toneBlue
class node_qr_import,node_parser,node_profile_store,node_settings,node_config_compiler toneAmber
class node_manager,node_singbox,node_stats,node_geoip toneMint
class node_paths,node_autostart,node_cleanup,node_installer toneRose
```

## Components

### Desktop Shell

- [Application startup](https://github.com/alanrpost/nightjar/blob/main/app/main.py): desktop entry point · Owns GUI lifecycle. · `app/main.py`
- [System tray controls](https://github.com/alanrpost/nightjar/blob/main/app/tray_app.py): tray UI · Keeps connection controls available when the window is hidden. · `app/tray_app.py`
- [Profile editor](https://github.com/alanrpost/nightjar/blob/main/app/edit_profile_dialog.py): dialog · `app/edit_profile_dialog.py`
- [Split tunnel selection](https://github.com/alanrpost/nightjar/blob/main/app/split_tunnel_dialog.py): dialog · `app/split_tunnel_dialog.py`

### Profiles & Config

- [Clipboard / QR import](https://github.com/alanrpost/nightjar/blob/main/app/qr_import.py): import UI · `app/qr_import.py`
- [Profile parser](https://github.com/alanrpost/nightjar/blob/main/app/profile_parser.py): URI normalization · Detects supported proxy protocols and produces normalized profiles. · `app/profile_parser.py`
- [Local profile store](https://github.com/alanrpost/nightjar/blob/main/app/profile_store.py): persistence · `app/profile_store.py`
- [Application settings](https://github.com/alanrpost/nightjar/blob/main/app/settings.py): local settings · `app/settings.py`
- [sing-box config compiler](https://github.com/alanrpost/nightjar/blob/main/app/singbox_config.py): configuration adapter · Builds sing-box JSON with outbound, TUN, routing, DNS, and logging. · `app/singbox_config.py`

### VPN Runtime

- [sing-box lifecycle manager](https://github.com/alanrpost/nightjar/blob/main/app/singbox_manager.py): runtime control plane · Launches, monitors, stops, and recovers the VPN process. · `app/singbox_manager.py`
- **sing-box process**: external VPN runtime · Provides system-wide TUN VPN networking.
- [Runtime stats & speed test](https://github.com/alanrpost/nightjar/blob/main/app/stats.py): connection telemetry · `app/stats.py`
- [GeoIP routing data](https://github.com/alanrpost/nightjar/blob/main/app/geoip.py): routing data · `app/geoip.py`

### Windows Integration

- [Local paths & log location](https://github.com/alanrpost/nightjar/blob/main/app/paths.py): filesystem layout · Includes the local sing-box runtime log location. · `app/paths.py`
- [Windows autostart](https://github.com/alanrpost/nightjar/blob/main/app/autostart.py): startup integration · `app/autostart.py`
- [Elevated cleanup](https://github.com/alanrpost/nightjar/blob/main/app/cleanup.py): privileged process cleanup · Handles stale-process cleanup outside normal UI flow. · `app/cleanup.py`
- [Windows installer](https://github.com/alanrpost/nightjar/blob/main/installer.iss): installer definition · `installer.iss`

## Connections

- Application startup → System tray controls: hosts
- Application startup → Profile editor: opens
- Application startup → Clipboard / QR import: imports through
- Application startup → sing-box lifecycle manager: connect / disconnect
- System tray controls → sing-box lifecycle manager: connection control
- Clipboard / QR import → Profile parser: imports links
- Profile parser → Local profile store: stores normalized profile
- Profile editor → Local profile store: updates
- Local profile store → sing-box config compiler: selected profile
- Application settings → sing-box config compiler: VPN settings
- Split tunnel selection → Application settings: saves app policy
- GeoIP routing data → sing-box config compiler: routing decisions
- sing-box config compiler → sing-box lifecycle manager: generated configuration
- sing-box lifecycle manager → sing-box process: launches and monitors
- sing-box process → Runtime stats & speed test: runtime visibility
- Local paths & log location → sing-box lifecycle manager: runtime artifact locations
- Windows autostart → Application startup: starts application
- Elevated cleanup → sing-box process: removes stale processes
- Windows installer → Application startup: packages
- Windows installer → Windows autostart: installs integration
