# igorkha/wireguard-mikrotik architecture

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

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

## Overview

#### Purpose and execution

This repository is a single-host Bash CLI generator for configuring a WireGuard VPN server on MikroTik. Its only application entry point is `wireguard-mikrotik.sh`, run interactively as superuser. It generates MikroTik RouterOS import scripts plus per-client WireGuard configurations and QR codes; it does not configure MikroTik directly.

#### Runtime and dependencies

The runtime is Bash on Ubuntu, Debian, Fedora, CentOS, Arch, Oracle Linux, and experimentally macOS via Homebrew. Core external executables are `wireguard-tools` for key/config operations and `qrencode` for client QR artifacts. The generated VPN design tunnels client traffic through the MikroTik server, whose NAT exposes the server’s public IP. Implementation: `wireguard-mikrotik.sh`.

#### Interactive orchestration

`wireguard-mikrotik.sh` owns the full control flow: environment/privilege validation, interactive collection of interface/server parameters, and selection between creating a server or adding clients to an existing interface. Re-running the script is the intended lifecycle mechanism for extending an existing server’s client set.

#### Server configuration generation

For each named WireGuard interface, the script creates persistent local state under a generated `wireguard/<interface>/` tree. It emits:
- a server WireGuard configuration (`wg0.conf`-style),
- retained parameter/state data (`params`),
- a RouterOS script under `mikrotik/<interface>.rsc`.

The RouterOS output is a deployment boundary: operators paste/import it into MikroTik rather than invoking a router API. Source generator: `wireguard-mikrotik.sh`.

#### Client provisioning

Client creation is a subordinate stage of the same script. Each client receives an isolated directory beneath `wireguard/<interface>/client/<user>/`, containing:
- a standard client `.conf`,
- a QR-encoded `.png`,
- a MikroTik peer `.rsc` for server-side peer registration.

This separates endpoint onboarding material from the base interface script while retaining all generated credentials/configuration locally. Generator: `wireguard-mikrotik.sh`.

#### Network and protocol boundaries

WireGuard is the cryptographic tunnel protocol; generated configs support IPv4 and IPv6. MikroTik RouterOS is the server-side target and applies NAT for tunneled client egress. Client config files and QR images are endpoint-facing outputs, while RouterOS `.rsc` files cross the administrator-to-router operational boundary. Primary implementation: `wireguard-mikrotik.sh`.

#### Repository shape

The repository deliberately concentrates product behavior in `wireguard-mikrotik.sh`; GitHub workflows and pre-commit files govern contribution hygiene rather than runtime architecture. Generated `wireguard/` state is created beside the script at execution time and is not represented as checked-in source.

Main entry points: [`wireguard-mikrotik.sh`](https://github.com/igorkha/wireguard-mikrotik/blob/main/wireguard-mikrotik.sh) (Bash CLI generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_generator["Local generator"]
  node_operator(("Administrator<br/>actor"))
  node_generator_script["Bash CLI generator"]
  node_wg_tools["wireguard-tools<br/>dependency"]
  node_qrencode["qrencode<br/>dependency"]
  node_client_provisioning["Client provisioning<br/>generation-stage"]
end

subgraph group_outputs["Generated local artifacts"]
  node_interface_state[("Interface state<br/>generated-state")]
  node_server_config["Server WireGuard config"]
  node_base_routeros_script["Base RouterOS script<br/>routeros-script"]
  node_client_directory["Client onboarding bundle<br/>generated-artifacts"]
  node_client_config["Client WireGuard config<br/>endpoint-config"]
  node_client_qr["Client QR image<br/>qr-artifact"]
  node_peer_routeros_script["Peer RouterOS script<br/>routeros-script"]
end

subgraph group_target["VPN deployment"]
  node_mikrotik{{"MikroTik RouterOS<br/>server-target"}}
  node_wireguard_tunnel["WireGuard tunnel<br/>vpn-protocol"]
  node_public_egress["Public IP egress<br/>network-boundary"]
end

node_operator -->|"runs interactively"| node_generator_script
node_generator_script -->|"uses"| node_wg_tools
node_generator_script -->|"uses"| node_qrencode
node_generator_script -->|"creates and reuses"| node_interface_state
node_generator_script -->|"emits"| node_server_config
node_generator_script -->|"emits"| node_base_routeros_script
node_generator_script -->|"invokes"| node_client_provisioning
node_client_provisioning -->|"creates"| node_client_directory
node_client_provisioning -->|"emits"| node_client_config
node_client_provisioning -->|"encodes"| node_client_qr
node_client_provisioning -->|"emits"| node_peer_routeros_script
node_base_routeros_script -->|"paste or import"| node_mikrotik
node_peer_routeros_script -->|"paste or import"| node_mikrotik
node_server_config -->|"defines server side"| node_wireguard_tunnel
node_client_config -->|"defines endpoint side"| node_wireguard_tunnel
node_mikrotik -->|"terminates"| node_wireguard_tunnel
node_wireguard_tunnel -->|"routes through NAT"| node_public_egress

click node_generator_script "https://github.com/igorkha/wireguard-mikrotik/blob/main/wireguard-mikrotik.sh"
click node_client_provisioning "https://github.com/igorkha/wireguard-mikrotik/blob/main/wireguard-mikrotik.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_operator,node_generator_script,node_wg_tools,node_qrencode,node_client_provisioning toneBlue
class node_interface_state,node_server_config,node_base_routeros_script,node_client_directory,node_client_config,node_client_qr,node_peer_routeros_script toneAmber
class node_mikrotik,node_wireguard_tunnel,node_public_egress toneMint
```

## Components

### Local generator

- **Administrator**: actor · Runs the generator interactively as superuser.
- [Bash CLI generator](https://github.com/igorkha/wireguard-mikrotik/blob/main/wireguard-mikrotik.sh): bash · Owns validation, prompts, server creation, and client extension. · `wireguard-mikrotik.sh`
- **wireguard-tools**: dependency · Generates WireGuard keys and configuration material.
- **qrencode**: dependency · Produces client QR PNG artifacts.
- [Client provisioning](https://github.com/igorkha/wireguard-mikrotik/blob/main/wireguard-mikrotik.sh): generation-stage · Adds clients when creating or extending an interface. · `wireguard-mikrotik.sh`

### Generated local artifacts

- **Interface state**: generated-state · Retained parameters and credentials for a named interface.
- **Server WireGuard config**: config
- **Base RouterOS script**: routeros-script · Operator imports this to create the server interface and base rules.
- **Client onboarding bundle**: generated-artifacts · Isolated per-user endpoint and peer-registration material.
- **Client WireGuard config**: endpoint-config · IPv4/IPv6 tunnel configuration for an endpoint.
- **Client QR image**: qr-artifact
- **Peer RouterOS script**: routeros-script · Registers an individual client peer on the router.

### VPN deployment

- **MikroTik RouterOS**: server-target · Applies imported scripts and NAT for tunneled client egress.
- **WireGuard tunnel**: vpn-protocol · Cryptographic IPv4/IPv6 tunnel between clients and MikroTik.
- **Public IP egress**: network-boundary · Client traffic exits through MikroTik NAT.

## Connections

- Administrator → Bash CLI generator: runs interactively
- Bash CLI generator → wireguard-tools: uses
- Bash CLI generator → qrencode: uses
- Bash CLI generator → Interface state: creates and reuses
- Bash CLI generator → Server WireGuard config: emits
- Bash CLI generator → Base RouterOS script: emits
- Bash CLI generator → Client provisioning: invokes
- Client provisioning → Client onboarding bundle: creates
- Client provisioning → Client WireGuard config: emits
- Client provisioning → Client QR image: encodes
- Client provisioning → Peer RouterOS script: emits
- Base RouterOS script → MikroTik RouterOS: paste or import
- Peer RouterOS script → MikroTik RouterOS: paste or import
- Server WireGuard config → WireGuard tunnel: defines server side
- Client WireGuard config → WireGuard tunnel: defines endpoint side
- MikroTik RouterOS → WireGuard tunnel: terminates
- WireGuard tunnel → Public IP egress: routes through NAT
