# wqweto/vbasyncsocket architecture

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

- Interactive diagram: https://gitdiagram.com/wqweto/vbasyncsocket
- Repository: https://github.com/wqweto/vbasyncsocket

## Overview

##### Project type and purpose
- This is a VB6-based networking library that wraps Windows WinSock APIs (`cAsyncSocket`) and provides transparent TLS support (`cTlsSocket`) with three interchangeable backends (`mdTlsThunks`, `mdTlsNative`, `mdTlsSodium`).
- It targets VB6 client and server applications needing asynchronous or blocking TCP and TLS 1.2/1.3 communication without external dependencies (or with optional libsodium).

##### File structure
- Top-level directories:
- src/ – core classes and TLS backends in VB6 modules.
- lib/ – C implementations of cryptographic primitives (ASM thunks, mini-gmp, ChaCha20, AES-GCM, curve25519, RSA, etc.) and a prebuilt certificate.
- contrib/ – optional VB6 wrappers for HTTP (cHttpDownload, cHttpRequest), rate limiter, WinSock remastering, plus DLL projects for native HTTP and TLS controls.
- samples/ – example VB6 apps demonstrating basic sockets, TLS socket tests, HTTP replacement, VBScript snippets.
- test/ – extensive VB6 test harnesses covering bare-bones TLS, basic socket, chat server/client, crypto operations, secure connections with certificates, various WinSock demos.
- Config and build files: `.gitmodules`, Visual Studio/C++ project files under lib/thunks and contrib/dll.

##### README for additional insights
- Describes the library’s layering:
- `cAsyncSocket` – non-blocking socket wrapper.
- `cTlsSocket` – subclass of `cAsyncSocket` that delegates TLS encryption/decryption to a chosen backend.
- Backends:
– `mdTlsThunks` – pure VB6 + ASM thunks, no external deps, optimized for AES-NI.
– `mdTlsNative` – uses Windows SSPI/Schannel via VB6 declarations.
– `mdTlsSodium` – relies on libsodium DLL, compact.
- Shows sample code flow: plain socket → STARTTLS → TLS handshake → secure send/receive.

##### Detailed elements
- Three branches from “TLS Backend” to: “mdTlsThunks (ASM/C)” , “mdTlsNative (SSPI)” , “mdTlsSodium (libsodium)”
- Overlay: “contrib/cHttpRequest” sitting on top of cTlsSocket for HTTP integration

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Application Layer"
        Samples["Samples / VB6 Apps"]:::app
        Tests["Tests / VB6 Harnesses"]:::app
    end

    subgraph "Transport Layer"
        cAsyncSocket["cAsyncSocket"]:::transport
        cTlsSocket["cTlsSocket"]:::transport
        subgraph "HTTP Adapter (contrib)"
            cHttpRequest["cHttpRequest"]:::adapter
            cHttpDownload["cHttpDownload"]:::adapter
        end
    end

    subgraph "TLS Backends"
        mdTlsThunks["mdTlsThunks"]:::backend
        mdTlsNative["mdTlsNative"]:::backend
        mdTlsSodium["mdTlsSodium"]:::backend
    end

    subgraph "Crypto Primitives (lib/thunks)" 
        ThunksLib["AES, ChaCha20, RSA..."]:::crypto
        Cert["ISRG_Root_X1.cer"]:::crypto
    end

    subgraph "OS / External"
        WinSock["WinSock API"]:::os
        SSPI["SSPI / Schannel"]:::os
        SodiumDLL["libsodium.dll"]:::os
        Network["Network (TCP 443)"]:::os
    end

    Samples -->|"uses"| cAsyncSocket
    Samples -->|"uses"| cTlsSocket
    Tests -->|"tests"| cAsyncSocket
    Tests -->|"tests"| cTlsSocket

    cTlsSocket -->|"wraps"| cAsyncSocket
    cTlssocket -->|"for HTTP"| cHttpRequest
    cTlsSocket -->|"for HTTP"| cHttpDownload

    cAsyncSocket -->|"calls"| WinSock
    cTlsSocket -->|"delegates TLS"| mdTlsThunks
    cTlsSocket -->|"delegates TLS"| mdTlsNative
    cTlsSocket -->|"delegates TLS"| mdTlsSodium

    mdTlsThunks -->|"uses primitives"| ThunksLib
    mdTlsThunks -->|"certificate"| Cert
    mdTlsNative -->|"via SSPI"| SSPI
    mdTlsSodium -->|"calls DLL"| SodiumDLL

    ThunksLib -->|"I/O over"| WinSock
    SSPI -->|"I/O over"| WinSock
    SodiumDLL -->|"I/O over"| WinSock
    WinSock -->|"network traffic"| Network

    click Samples "https://github.com/wqweto/vbasyncsocket/tree/master/samples/"
    click Tests "https://github.com/wqweto/vbasyncsocket/tree/master/test/"
    click cAsyncSocket "https://github.com/wqweto/vbasyncsocket/blob/master/src/cAsyncSocket.cls"
    click cTlsSocket "https://github.com/wqweto/vbasyncsocket/blob/master/src/cTlsSocket.cls"
    click cHttpRequest "https://github.com/wqweto/vbasyncsocket/blob/master/contrib/cHttpRequest.cls"
    click cHttpDownload "https://github.com/wqweto/vbasyncsocket/blob/master/contrib/cHttpDownload.cls"
    click mdTlsThunks "https://github.com/wqweto/vbasyncsocket/blob/master/src/mdTlsThunks.bas"
    click mdTlsNative "https://github.com/wqweto/vbasyncsocket/blob/master/src/mdTlsNative.bas"
    click mdTlsSodium "https://github.com/wqweto/vbasyncsocket/blob/master/src/mdTlsSodium.bas"
    click ThunksLib "https://github.com/wqweto/vbasyncsocket/tree/master/lib/thunks/"
    click Cert "https://github.com/wqweto/vbasyncsocket/blob/master/lib/ISRG_Root_X1.cer"

    classDef app fill:#cce5ff,stroke:#00529B,color:#00529B
    classDef transport fill:#d4edda,stroke:#27632a,color:#27632a
    classDef adapter fill:#d4edda,stroke:#27632a,color:#27632a
    classDef backend fill:#fff4e5,stroke:#a16a00,color:#a16a00
    classDef crypto fill:#fff4e5,stroke:#a16a00,color:#a16a00
    classDef os fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
