How leonovk/wg-rest-api works
Project Type and Purpose
• This is an open-source, Docker-packaged REST API service (written in Ruby) for managing a WireGuard VPN server.
• It exposes HTTP endpoints to create/list/update/delete WireGuard clients, read server stats, generate QR codes/configs, and send webhooks on client connect/disconnect events.
File Structure
• Top-level files: Dockerfile, config.ru (Rack entry), app.rb (Sinatra/Grape-style endpoints).
• app/api: HTTP controllers, serializers, validators under two namespaces: /api/clients and /api/server.
• lib/wire_guard: service objects for key generation, config building/updating, stat parsing.
• lib/utils & lib/webhooks: QR‐code and config‐file builders, webhook aggregation and sending.
• config: environment settings, Puma, Sentry, dependency wiring.
• bin/wgpass: CLI tool to generate hashed tokens.
• tasks/*.rake: operational Rake tasks (backups, stats, events).
• spec/: comprehensive test coverage (controllers, serializers, service objects).
• No database—configuration is persisted directly as WireGuard files on the host filesystem under /etc/wireguard (bind-mounted via Docker).
README for Additional Insights
• Service runs single-threaded Puma (configurable threads/workers, but not thread-safe).
• Auth via bearer token or SHA256 hash.
• Exposes health check, client CRUD, format variations (QR/png or .conf), and server stats.
• Webhook notifications are optional “beta” feature.
• Deployment expected via Docker with NET_ADMIN capability.
Don’t Overthink—Capture All Essential Elements
• How they connect under the Docker container boundary.
• Be explicit about volumes (/etc/wireguard) and kernel calls (wireguard-tools).
• Clearly distinguish synchronous flows (API requests) from asynchronous/outbound flows (webhooks, Rake tasks, Sentry).