# wireguard/wireguard-nt architecture

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

- Interactive diagram: https://gitdiagram.com/wireguard/wireguard-nt
- Repository: https://github.com/wireguard/wireguard-nt

## Overview

- User-Space API (DLL)
- Represented by the contents in the “api” directory. This includes adapter creation, configuration, logging, and hook functions that are intended to be loaded dynamically (via LoadLibraryEx and GetProcAddress).
- Kernel Driver
- Encompasses the “driver” directory, which contains core driver files (e.g., device.c, ioctl.c, logging.c, crypto routines, etc.) that implement the low-level network tunneling and packet processing.
- Setup and Host Component
- The “setupapihost” directory, suggesting a dedicated component for hosting the API or providing additional control over driver initialization on specific Windows versions.
- Example/Demo Application
- A sample application (from the “example” folder) which illustrates using the provided API functions like WireGuardCreateAdapter, WireGuardSetConfiguration, and WireGuardSetAdapterState.

##### Relationships and Interactions
- Connection between the API and the Kernel Driver.
- If applicable, include the “Setup API Host” as a supporting module that may initialize or mediate between the API and driver (especially on older platforms like Windows 7).

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- Clearly distinguish between the API layer (user-space logic and interface) and the kernel driver (low-level, performance-critical networking code).
- Modularization:
- The file tree shows organized modules (e.g., API, driver, and self-test components) that can be separately maintained and tested.
- Clear Interface Definitions:
- Extensibility:
- The division into multiple components (e.g., API host, self-test in the driver) emphasizes an architecture that is built for stability, high performance, and clear extensibility.

##### Relevant Technologies, Frameworks, or Libraries
- Windows-specific technologies:
- Windows SDK and Windows Driver Kit (WDK) as part of the build and deployment environment.
- Visual Studio project files:
- That the solution file (wireguard-nt.sln) and associated vcxproj files are used for building both the user-space API and kernel driver, indicating a strongly integrated Microsoft development environment.
- Standard C language and system libraries:
- That the implementation is in C with occasional assembly (e.g., crypto-amd64.asm).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Space"
        EX["Example Application"]:::userSpace
        API["User-Space API (DLL)"]:::userSpace
        HOST["Setup/Host Component"]:::userSpace
    end

    subgraph "Kernel Space"
        DRIVER["Kernel Driver"]:::kernel
    end

    EX -->|"calls"| API
    API -->|"sends_IOCTL"| DRIVER
    HOST -->|"initializes"| DRIVER
    DRIVER -->|"logging_feedback"| API

    click API "https://github.com/wireguard/wireguard-nt/tree/master/api/"
    click DRIVER "https://github.com/wireguard/wireguard-nt/tree/master/driver/"
    click HOST "https://github.com/wireguard/wireguard-nt/tree/master/setupapihost/"
    click EX "https://github.com/wireguard/wireguard-nt/tree/master/example/"

    classDef userSpace fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef kernel fill:#F5B041,stroke:#7D6608,stroke-width:2px;
```
