Architecture Overview
AVNC is designed with a clean, decoupled architecture relying heavily on Android's ViewModel and modern Kotlin features, interfacing with a C/C++ native layer for the VNC protocol.
High-Level Diagram
+---------------------------------------------------------------------------------------------------------------+
UI
+------------------+ +------------------+ +------------------+ +------------------+
| [HomeActivity] | | [VncActivity] | | [PrefsActivity] | | [AboutActivity] |
+--------+---------+ +--------+---------+ +--------+---------+ +------------------+
| | | |
| | | |
+------------------------|-------------------------|-------------------------|----------------------------------+
ViewModel | | |
v v v
+------------------+ +------------------+ +------------------+
| [HomeViewModel] | | [VncViewModel] | | [PrefsViewModel] |
+------------------+ +------------------+ +------------------+
A A +--------------+
| | | Services |
| | +--------------+
+------------------------|-------------------------|------------------------------------------------------------+
Model & Client | |
V V
+------------------+ +------------------+
| [ServerProfile] | | [VncClient] |
| | | |
| Database | | LibVNCClient |
+------------------+ +------------------+
+---------------------------------------------------------------------------------------------------------------+
Core Layers
1. UI Layer
HomeActivity: The main entry point. Houses the URL bar for quick connects, tabs for Saved/Discovered servers, and profile editors.VncActivity: Drives the active VNC session. It renders the remote framebuffer viaFrameView(OpenGL) and handles complex inputs viaInputHandler.PrefsActivity: Manages global application settings.IntentReceiverActivity: Entry point for deep links (vnc://URIs) and Android App Shortcuts.
2. ViewModel Layer
HomeViewModel: Handles local database queries, triggers Zeroconf discovery, and navigates states.VncViewModel: Manages the connection lifecycle, delegates input to theMessenger, handles SSH tunnelling integration, and holds theFrameState(zoom, pan data).EditorViewModel: Maintains ephemeral state for the advanced server profile editor.PrefsViewModel: Handles background tasks for importing/exporting JSON server profiles.
3. Model & Client Layer
- Database (
MainDb): Uses Android Room to persistServerProfileentities locally. VncClient: A Kotlin wrapper encapsulating JNI methods to interface with the nativerfbClientfrom thelibvncserverC library.Messenger: A dedicated single-thread executor class that ensures VNC inputs (keys, pointer events) are sent sequentially to the native layer.
4. Background Services
- Discovery (
Discovery.kt): UsesNsdManagerto discover local_rfb._tcpmDNS broadcasts. - SshTunnel (
SshTunnel.kt): Wrapssshlib(Trilead) to establish secure local port forwarding before connecting the VNC client.