# divslayer/anydeskapp architecture

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

- Interactive diagram: https://gitdiagram.com/divslayer/anydeskapp
- Repository: https://github.com/divslayer/anydeskapp

## Overview

##### Project Type and Purpose
- This is a lightweight Python-based client-server remote desktop application (in the style of AnyDesk).
- It comprises two runtime roles:
a) **Server (remote_machine.py)**: Captures the desktop, encodes frames, streams them over a secure WebSocket, and listens for incoming mouse/keyboard events.
b) **Client/Viewer (viewer.py)**: Connects to the server’s WebSocket, decodes and displays video frames, and sends user input events back.

##### File Structure Analysis
- Top-level scripts:
- gui.py – Tkinter GUI that lets you choose “Be Remote Machine” or “Connect to Remote.”
- remote_machine.py – The server process.
- viewer.py – The client process.
- get_local_ip.py – Utility to discover local IP addresses.
- test.py – (Presumably simple smoke tests or examples.)
- SSL certificates: cert.pem, key.pem (for TLS).
- requirements.txt – Lists dependencies (websockets, mss, OpenCV, pyautogui, etc.).

##### Architecture Insights from README
- Uses a secure WebSocket (wss://) connection for bidirectional comms.
- Video frames are JPEG-encoded via OpenCV and sent over the socket.
- Input events (mouse/keyboard) are captured client-side (pyautogui) and injected server-side.
- GUI is Tkinter, offering a simple launcher.

##### Main Components
a. **Launcher GUI (gui.py)**
- Branches into either Server or Client mode.
b. **Server Process**
- **Screen Capture Module** (mss or pyautogui for screenshots)
- **Encoder Module** (OpenCV JPEG encoder)
- **WebSocket Server** (websockets + ssl.wrap_socket)
- **Input Handler** (pyautogui to inject events)
c. **Client/Viewer Process**
- **WebSocket Client** (connects to wss://server:port)
- **Decoder Module** (OpenCV JPEG decoder)
- **Display Window** (OpenCV imshow or Tkinter canvas)
- **Input Capturer** (captures local mouse/keyboard events)
d. **SSL/TLS Layer**
- Self-signed certificates (cert.pem, key.pem) securing the WebSocket channel.
e. **Network**

##### Relationships & Interactions
- The Launcher GUI spins up either the Server or the Client.
- In **Server Mode**:
- → Encode → WebSocket Send → Network
- WebSocket Receive → Input Handler → Inject into OS
- In **Client Mode**:
- WebSocket Receive → Decode → Render → Display Window
- Input Capture → WebSocket Send → Network

##### Architectural Patterns & Principles
- **Client-Server Architecture**: Clear separation of responsibilities.
- **Modular Design**: Distinct modules for capture, encode/decode, transport, and input handling.
- **Secure Communication**: All network traffic runs over TLS.
- **Event-Driven I/O**: WebSocket callbacks drive video and input pipelines.

##### Technologies & Frameworks
- Python 3.7+
- Tkinter (GUI launcher)
- websockets (asyncio-based WebSocket server/client)
- ssl (native Python TLS)
- mss or pyautogui (screen capture)
- OpenCV (cv2) for JPEG encoding/decoding
- pyautogui for input injection

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Launcher GUI
    GUI["Launcher GUI"]:::gui
    click GUI "https://github.com/divslayer/anydeskapp/blob/main/gui.py"

    %% Server Mode Pipeline
    subgraph "Server Mode"
        direction TB
        RM["Server Process\n(remote_machine.py)"]:::backend
        click RM "https://github.com/divslayer/anydeskapp/blob/main/remote_machine.py"
        Capture["Screen Capture Module"]:::os
        Encoder["Encoder Module\n(OpenCV JPEG)"]:::backend
        WS_Server["WebSocket Server\n(wss://)"]:::network
        InputHandler["Input Handler\n(pyautogui)"]:::os

        RM -->|launch| Capture
        Capture -->|captures frames| Encoder
        Encoder -->|JPEG frames| WS_Server
        WS_Server -->|send video stream| Network
        Network -->|control events| WS_Server
        WS_Server -->|received events| InputHandler
    end

    %% Network Layer
    Network["Network\nSecure WebSocket (TLS)"]:::network
    subgraph "Certificates"
        direction LR
        Cert[(cert.pem)]:::backend
        click Cert "https://github.com/divslayer/anydeskapp/blob/main/cert.pem"
        Key[(key.pem)]:::backend
        click Key "https://github.com/divslayer/anydeskapp/blob/main/key.pem"
    end
    Network --> Cert
    Network --> Key

    %% Client Mode Pipeline
    subgraph "Client Mode"
        direction TB
        Viewer["Client Process\n(viewer.py)"]:::backend
        click Viewer "https://github.com/divslayer/anydeskapp/blob/main/viewer.py"
        WS_Client["WebSocket Client\n(wss://)"]:::network
        Decoder["Decoder Module\n(OpenCV JPEG)"]:::backend
        Display["Display Window\n(OpenCV/Tkinter)"]:::gui
        InputCapture["Input Capturer\n(mouse/keyboard)"]:::os

        Network -->|video stream| WS_Client
        WS_Client -->|receive frames| Decoder
        Decoder -->|decoded frames| Display
        Display -->|renders screen| User["User"]:::external

        InputCapture -->|capture events| WS_Client
        WS_Client -->|send events| Network
    end

    %% Utilities & Docs
    subgraph "Utilities & Docs"
        direction TB
        IPUtil["IP Discovery Utility"]:::backend
        click IPUtil "https://github.com/divslayer/anydeskapp/blob/main/get_local_ip.py"
        Req["requirements.txt"]:::backend
        click Req "https://github.com/divslayer/anydeskapp/blob/main/requirements.txt"
        Readme["Project Documentation"]:::backend
        click Readme "https://github.com/divslayer/anydeskapp/blob/main/README.md"
        Test["Test Scripts"]:::backend
        click Test "https://github.com/divslayer/anydeskapp/blob/main/test.py"
    end

    %% Connections from Launcher
    GUI -->|Be Remote Machine| RM
    GUI -->|Connect to Remote| Viewer

    %% Styles
    classDef gui fill:#fff8b5,stroke:#333,stroke-width:1px
    classDef network fill:#b3e5fc,stroke:#333,stroke-width:1px
    classDef os fill:#c8e6c9,stroke:#333,stroke-width:1px
    classDef backend fill:#eeeeee,stroke:#333,stroke-width:1px
    classDef external fill:#f5f5f5,stroke:#666,stroke-dasharray: 2 2
```
