How webui-dev/webui works
Project type and purpose
• This is WebUI v2.5.0-beta.4, a portable C/C++ library that lets you build desktop GUIs using any web browser or embedded WebView. It bundles a tiny HTTP server (civetweb), platform-specific WebView adapters, and a JS/TS bridge so your backend code (C, C++, Zig, etc.) can talk to front-end HTML/JavaScript.
File structure
• Top level:
• Build scripts & meta (CMakeLists.txt, Makefile, GNUmakefile, build.zig, conanfile.py, vcpkg.json, GitHub Actions under .github/workflows)
• / (public headers: webui.h, webui.hpp)
• src/
– core engine (src/webui.c)
– embedded HTTP server (src/civetweb/)
– platform WebView adapters (src/webview/)
• bridge/ (JS/TS code, js2c tool, webui_bridge.h to embed JS as C arrays)
• examples/ (C and C++ demos showing call_js_from_cpp, call_cpp_from_js, serve_a_folder, text-editor, etc.)
• Patterns: single-process client-server arrangement, cross-platform abstraction, pluggable JS bridge.
Key insights from README
• “All it needs is a web browser.”
• Supports native WebView2 (Windows), GTK WebView (Linux), WKWebView (macOS), or any external browser.
• Optional TLS via OpenSSL.
Main components & their interactions
a. Components
1. User Application (C/C++/other)
2. WebUI Core Library
• HTTP/WS Server (civetweb module)
• Platform WebView Launcher & Bridge (WebView2/GTK/WKWebView)
• JS client loader (embedded via bridge/js2c)
3. Front-end UI (HTML, CSS, JS served by the server)
4. External dependencies
• Native frameworks (Cocoa/WebKit, WebView2, GTK)
• Optional OpenSSL for TLS
b. Interactions & data flow
• App calls WebUI API → library spins up HTTP or WebSocket server → library launches browser/WebView instance pointing to localhost URL → front-end assets (HTML/JS) are served → JS uses WebUI client API to send events/commands back over WS → library unmarshals, invokes App callbacks → App state changes → library pushes updated UI messages back over WS → browser updates DOM.
c. Architectural patterns
• Embedded HTTP Server Pattern (self-contained web server)
• Client-Server within one process
• Cross-platform adapter pattern for WebView hosts
• Code-generation bridge (js2c → embed JS/TS files as C arrays)
d. Technologies & frameworks
• C/C++ (webui.c, webui.hpp)
• civetweb (lightweight HTTP/WS server)
• WebView2, GTK WebKit, WKWebView
• JavaScript/TypeScript bridge code (bridge/)
• Build tools: CMake, GNU Make, Zig, Conan, vcpkg
• CI: GitHub Actions
Detail
• Build pipeline as an inset or footer: CI → cross-platform builds → library artifacts
• Example flow (e.g., “webui_show(html)” → browser.render → onClick JS → WebUI.invoke(…) → C callback)
• Every module: bridge/js2c tool, examples folder (as consumers), include/ headers.