<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mrhuang</title>
    <description>The latest articles on DEV Community by mrhuang (@huangziquan).</description>
    <link>https://dev.to/huangziquan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F99mvlsfu5tfj9m7ku25d.png</url>
      <title>DEV Community: mrhuang</title>
      <link>https://dev.to/huangziquan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/huangziquan"/>
    <language>en</language>
    <item>
      <title>C++20 Web framework paozhu</title>
      <dc:creator>mrhuang</dc:creator>
      <pubDate>Fri, 04 Dec 2026 14:01:30 +0000</pubDate>
      <link>https://dev.to/huangziquan/c20-web-framework-paozhu-5be0</link>
      <guid>https://dev.to/huangziquan/c20-web-framework-paozhu-5be0</guid>
      <description>&lt;h2&gt;
  
  
  Paozhu: A Full-Stack Web Framework for Rapid C++ Development
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Overview
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Paozhu&lt;/strong&gt; (炮竹 🧨) is a high-performance full-stack web framework purpose-built for rapid C++ development. Founded in 2022 and battle-tested across 20+ production projects — including WeChat Mini Programs, foreign-trade platforms, multi-tenant SaaS, enterprise applications, and IoT smart devices — Paozhu brings scripting-language development velocity to the C++ world, enabling teams to ship up to 1,000 lines of business code per day with a single binary.&lt;/p&gt;

&lt;p&gt;Paozhu ships with a fully hand-rolled native protocol stack: HTTP/1.1, HTTP/2 (including h2c), WebSocket, MySQL, PostgreSQL, SQLite, and Redis — no third-party HTTP/ORM dependencies. Written in C++20 on top of Asio coroutines, it runs on Linux, macOS, and Windows with zero memory leaks or crashes reported in production.&lt;/p&gt;




&lt;h3&gt;
  
  
  Core Architecture
&lt;/h3&gt;

&lt;p&gt;Paozhu's dual-pool design is inspired by Go's goroutine scheduler:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;I/O Coroutine Pool&lt;/strong&gt; — handles all network I/O, parsing, and protocol processing via Asio coroutines. Lightweight and non-blocking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User-Code Thread Pool&lt;/strong&gt; — runs heavy business logic in dedicated OS threads, so CPU-bound work never blocks the I/O loop.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Business code freely chooses between coroutine functions (&lt;code&gt;asio::awaitable&lt;/code&gt;) and synchronous functions (&lt;code&gt;std::string&lt;/code&gt;). The framework automatically routes each request to the appropriate pool, keeping the scheduling transparent.&lt;/p&gt;




&lt;h3&gt;
  
  
  Feature Modules
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. HTTP Server &amp;amp; Protocol Stack
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Capability&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;HTTP/1.1 + HTTP/2 (h2c)&lt;/td&gt;
&lt;td&gt;Full hand-rolled parsers for both protocols, including HPACK encoding and flow control&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multi-domain + SSL&lt;/td&gt;
&lt;td&gt;Virtual hosting with per-domain configuration, SNI, and multi-certificate support&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ACME Integration&lt;/td&gt;
&lt;td&gt;Automatic SSL certificate issuance and renewal via Let's Encrypt, with OCSP stapling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Compression&lt;/td&gt;
&lt;td&gt;Gzip and Brotli output compression with static-file caching&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Static Files&lt;/td&gt;
&lt;td&gt;Built-in directory listing, file upload/download, and PHP-FPM FastCGI bridge&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  2. Built-in ORM
&lt;/h4&gt;

&lt;p&gt;Paozhu's native ORM is one of the very few C++ ORMs with a hand-written MySQL protocol implementation in production. It supports &lt;strong&gt;three databases&lt;/strong&gt; with a unified API:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MySQL&lt;/strong&gt; (native binary protocol)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PostgreSQL&lt;/strong&gt; (native binary protocol)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SQLite&lt;/strong&gt; (file-based)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Key features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Coroutine mode (&lt;code&gt;async_fetch&lt;/code&gt;, &lt;code&gt;async_update&lt;/code&gt;) and synchronous mode (&lt;code&gt;fetch&lt;/code&gt;, &lt;code&gt;update&lt;/code&gt;) — same API, different execution path&lt;/li&gt;
&lt;li&gt;CLI tool (&lt;code&gt;paozhu_cli&lt;/code&gt;) auto-generates C++ entity classes from database schemas&lt;/li&gt;
&lt;li&gt;Fluent chain API: &lt;code&gt;where().asc().page().fetch()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Connection pooling with configurable max connections&lt;/li&gt;
&lt;li&gt;Namespace isolation per database (&lt;code&gt;orm::cms::User&lt;/code&gt;, &lt;code&gt;orm::erp::User&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Lazy reconnection and prepared statement support&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Real-time Communication
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Module&lt;/th&gt;
&lt;th&gt;Protocol&lt;/th&gt;
&lt;th&gt;Mode&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;WebSocket Server/Client&lt;/td&gt;
&lt;td&gt;RFC 6455&lt;/td&gt;
&lt;td&gt;Sync + Coroutine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TCP Socket Server/Client&lt;/td&gt;
&lt;td&gt;Raw TCP&lt;/td&gt;
&lt;td&gt;Sync + Coroutine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MQTT Broker Client&lt;/td&gt;
&lt;td&gt;MQTT v3.1/v5&lt;/td&gt;
&lt;td&gt;Sync + Coroutine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Redis Pub/Sub&lt;/td&gt;
&lt;td&gt;Redis RESP&lt;/td&gt;
&lt;td&gt;Sync + Coroutine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RPC Server/Client&lt;/td&gt;
&lt;td&gt;HTTP-annotated URL functions&lt;/td&gt;
&lt;td&gt;Sync + Coroutine&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All long-connection clients support SSL/TLS and background task loops with configurable timeouts.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Annotation-Driven Routing
&lt;/h4&gt;

&lt;p&gt;Zero-config URL registration via C++ annotations in controller &lt;code&gt;.cpp&lt;/code&gt; files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;//@urlpath(islogin, admin/listarticle)&lt;/span&gt;
&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="nf"&gt;admin_listarticle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;shared_ptr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;httppeer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;peer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// business logic&lt;/span&gt;
    &lt;span class="n"&gt;peer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Hello world!"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The annotation handler runs at CMake build time, extracts all &lt;code&gt;//@urlpath&lt;/code&gt; markers, auto-generates header files, and registers the routing table. Optional middleware chain (e.g., &lt;code&gt;islogin&lt;/code&gt; → &lt;code&gt;admin_listarticle&lt;/code&gt;) enables clean separation of concerns.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. View Template System
&lt;/h4&gt;

&lt;p&gt;HTML templates are compiled into C++ code that runs in-process at request time — no disk I/O, no template engine overhead. Templates use &lt;code&gt;&amp;lt;%c ... %&amp;gt;&lt;/code&gt; blocks to embed C++ expressions and &lt;code&gt;include_sub()&lt;/code&gt; for partials. The compiled views are registered as callable functions in the framework's routing table, keeping the hot path purely in-memory.&lt;/p&gt;

&lt;h4&gt;
  
  
  6. Built-in Micro Objects
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;http::obj_val&lt;/code&gt; is a 16-byte key-value object with script-language ergonomics — used for JSON I/O, session data, view rendering, and API responses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;obj_val&lt;/span&gt; &lt;span class="n"&gt;hval&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;hval&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Alice"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;hval&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"age"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hval&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// {"name":"Alice","age":30}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  7. Authentication &amp;amp; Authorization
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JWT&lt;/strong&gt; — stateless token authentication with configurable claims and expiration&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OAuth 2.1&lt;/strong&gt; — full authorization server implementation (authorization code, PKCE, refresh tokens)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RBAC&lt;/strong&gt; — role-based access control with permission catalog and route guards; ships with a complete admin backend demo at &lt;code&gt;/admin/main&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  8. Optional Extension Modules (CMake Switches)
&lt;/h4&gt;

&lt;p&gt;Each module is compile-time optional — only enable what you need:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Switch&lt;/th&gt;
&lt;th&gt;Module&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ENABLE_PDF&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;pz::webpdf&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;HTML-to-PDF conversion with font embedding&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ENABLE_OFFICE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;pz::excel&lt;/code&gt;, &lt;code&gt;pz::word&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;.xlsx&lt;/code&gt; read/write, &lt;code&gt;.docx&lt;/code&gt; ↔ HTML conversion&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ENABLE_ZIP&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;pz::zip&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;ZIP archive packaging and extraction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ENABLE_IMAGE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Image tools&lt;/td&gt;
&lt;td&gt;JPG/PNG generation and processing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ENABLE_CHART&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;pz::chart&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;SVG chart generation (line, bar, pie, gauge, candlestick, scatter, radar, funnel, heatmap)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ENABLE_SMS&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;SMS sending&lt;/td&gt;
&lt;td&gt;Integrated SMS gateway client&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ENABLE_WEBPAY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Payment integration&lt;/td&gt;
&lt;td&gt;WeChat Pay v2/v3 and Alipay (QR, QRIS, certificate mode)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ENABLE_FASTCGI&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;PHP bridge&lt;/td&gt;
&lt;td&gt;PHP-FPM FastCGI proxy for mixed C++/PHP deployments&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ENABLE_REDIS&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Redis client&lt;/td&gt;
&lt;td&gt;Synchronous and coroutine Redis operations&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  9. Infrastructure &amp;amp; DevOps
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Rate Limiting&lt;/strong&gt; — two-stage sliding window (60-second moving average) per connection&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SaaS Multi-tenancy&lt;/strong&gt; — per-tenant database isolation, theme customization, and domain routing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SendMail&lt;/strong&gt; — synchronous and asynchronous SMTP client&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;QR Code / CAPTCHA&lt;/strong&gt; — built-in generation utilities&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minimal Dependencies&lt;/strong&gt; — Asio, OpenSSL, Zlib, Brotli. Everything else is optional&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ASAN + UBSAN&lt;/strong&gt; — enabled by default in Debug builds; ThreadSanitizer available in Release&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Project Layout
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;startup/      # Entry points (daemon / dev / docker modes)
common/       # Annotation auto-extraction, route registration, JSON reflection
controller/   # Business controllers — place all //@urlpath functions here
view/         # HTML templates (compiled to C++ via paozhu_cli)
viewsrc/      # Auto-generated C++ view functions (don't edit manually)
models/       # ORM entity classes (auto-generated from DB by paozhu_cli)
orm/          # ORM base + driver layer (MySQL / PG / SQLite)
conf/         # server.conf, orm.conf, SSL certificates
libs/         # Pluggable libraries (oauth, rbac, webpay, github, ipdata, etc.)
websockets/   # Example WebSocket server/client
sockets/      # Example TCP socket server/client
mqtt/         # Example MQTT client
redis/        # Example Redis pub/sub subscriber
tests/        # Stress tests, HTTP2 hpack probes, ORM correctness tests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Runtime Requirements
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Item&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;C++ Standard&lt;/td&gt;
&lt;td&gt;C++20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dependencies&lt;/td&gt;
&lt;td&gt;Asio, OpenSSL, Zlib, Brotli&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Platforms&lt;/td&gt;
&lt;td&gt;Linux ≥ 22.04, macOS ≥ 14, Windows ≥ 10 (MSVC 19.25+)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Build Systems&lt;/td&gt;
&lt;td&gt;CMake / xmake&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  Get Started
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/hggq/paozhu.git myproject
&lt;span class="nb"&gt;cd&lt;/span&gt; myproject
sh mini_project.sh         &lt;span class="c"&gt;# strips demo modules, leaves clean scaffold&lt;/span&gt;
mkdir build &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j&lt;span class="nv"&gt;$(&lt;/span&gt;nproc&lt;span class="o"&gt;)&lt;/span&gt;
sudo ./bin/paozhu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open &lt;code&gt;http://localhost/hello&lt;/code&gt; — you'll see your first response from the Paozhu server.&lt;/p&gt;

&lt;p&gt;For the full documentation, visit &lt;a href="https://hggq.github.io/paozhudocs/" rel="noopener noreferrer"&gt;hggq.github.io/paozhudocs&lt;/a&gt;. Paozhu is licensed under MIT.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
