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 via FrameView (OpenGL) and handles complex inputs via InputHandler.
  • 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 the Messenger, handles SSH tunnelling integration, and holds the FrameState (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 persist ServerProfile entities locally.
  • VncClient: A Kotlin wrapper encapsulating JNI methods to interface with the native rfbClient from the libvncserver C 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): Uses NsdManager to discover local _rfb._tcp mDNS broadcasts.
  • SshTunnel (SshTunnel.kt): Wraps sshlib (Trilead) to establish secure local port forwarding before connecting the VNC client.