Paozhu: A Full-Stack Web Framework for Rapid C++ Development
Overview
Paozhu (炮竹 🧨) 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.
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.
Core Architecture
Paozhu's dual-pool design is inspired by Go's goroutine scheduler:
- I/O Coroutine Pool — handles all network I/O, parsing, and protocol processing via Asio coroutines. Lightweight and non-blocking.
- User-Code Thread Pool — runs heavy business logic in dedicated OS threads, so CPU-bound work never blocks the I/O loop.
Business code freely chooses between coroutine functions (asio::awaitable) and synchronous functions (std::string). The framework automatically routes each request to the appropriate pool, keeping the scheduling transparent.
Feature Modules
1. HTTP Server & Protocol Stack
| Capability | Description |
|---|---|
| HTTP/1.1 + HTTP/2 (h2c) | Full hand-rolled parsers for both protocols, including HPACK encoding and flow control |
| Multi-domain + SSL | Virtual hosting with per-domain configuration, SNI, and multi-certificate support |
| ACME Integration | Automatic SSL certificate issuance and renewal via Let's Encrypt, with OCSP stapling |
| Compression | Gzip and Brotli output compression with static-file caching |
| Static Files | Built-in directory listing, file upload/download, and PHP-FPM FastCGI bridge |
2. Built-in ORM
Paozhu's native ORM is one of the very few C++ ORMs with a hand-written MySQL protocol implementation in production. It supports three databases with a unified API:
- MySQL (native binary protocol)
- PostgreSQL (native binary protocol)
- SQLite (file-based)
Key features:
- Coroutine mode (
async_fetch,async_update) and synchronous mode (fetch,update) — same API, different execution path - CLI tool (
paozhu_cli) auto-generates C++ entity classes from database schemas - Fluent chain API:
where().asc().page().fetch() - Connection pooling with configurable max connections
- Namespace isolation per database (
orm::cms::User,orm::erp::User) - Lazy reconnection and prepared statement support
3. Real-time Communication
| Module | Protocol | Mode |
|---|---|---|
| WebSocket Server/Client | RFC 6455 | Sync + Coroutine |
| TCP Socket Server/Client | Raw TCP | Sync + Coroutine |
| MQTT Broker Client | MQTT v3.1/v5 | Sync + Coroutine |
| Redis Pub/Sub | Redis RESP | Sync + Coroutine |
| RPC Server/Client | HTTP-annotated URL functions | Sync + Coroutine |
All long-connection clients support SSL/TLS and background task loops with configurable timeouts.
4. Annotation-Driven Routing
Zero-config URL registration via C++ annotations in controller .cpp files:
//@urlpath(islogin, admin/listarticle) std::string admin_listarticle(std::shared_ptr<httppeer> peer) { // business logic peer->output="Hello world!"; return ""; } The annotation handler runs at CMake build time, extracts all //@urlpath markers, auto-generates header files, and registers the routing table. Optional middleware chain (e.g., islogin → admin_listarticle) enables clean separation of concerns.
5. View Template System
HTML templates are compiled into C++ code that runs in-process at request time — no disk I/O, no template engine overhead. Templates use <%c ... %> blocks to embed C++ expressions and include_sub() for partials. The compiled views are registered as callable functions in the framework's routing table, keeping the hot path purely in-memory.
6. Built-in Micro Objects
http::obj_val is a 16-byte key-value object with script-language ergonomics — used for JSON I/O, session data, view rendering, and API responses:
http::obj_val hval; hval["name"] = "Alice"; hval["age"] = 30; std::string json = hval.to_json(); // {"name":"Alice","age":30} 7. Authentication & Authorization
- JWT — stateless token authentication with configurable claims and expiration
- OAuth 2.1 — full authorization server implementation (authorization code, PKCE, refresh tokens)
- RBAC — role-based access control with permission catalog and route guards; ships with a complete admin backend demo at
/admin/main
8. Optional Extension Modules (CMake Switches)
Each module is compile-time optional — only enable what you need:
| Switch | Module | Description |
|---|---|---|
ENABLE_PDF | pz::webpdf | HTML-to-PDF conversion with font embedding |
ENABLE_OFFICE | pz::excel, pz::word | .xlsx read/write, .docx ↔ HTML conversion |
ENABLE_ZIP | pz::zip | ZIP archive packaging and extraction |
ENABLE_IMAGE | Image tools | JPG/PNG generation and processing |
ENABLE_CHART | pz::chart | SVG chart generation (line, bar, pie, gauge, candlestick, scatter, radar, funnel, heatmap) |
ENABLE_SMS | SMS sending | Integrated SMS gateway client |
ENABLE_WEBPAY | Payment integration | WeChat Pay v2/v3 and Alipay (QR, QRIS, certificate mode) |
ENABLE_FASTCGI | PHP bridge | PHP-FPM FastCGI proxy for mixed C++/PHP deployments |
ENABLE_REDIS | Redis client | Synchronous and coroutine Redis operations |
9. Infrastructure & DevOps
- Rate Limiting — two-stage sliding window (60-second moving average) per connection
- SaaS Multi-tenancy — per-tenant database isolation, theme customization, and domain routing
- SendMail — synchronous and asynchronous SMTP client
- QR Code / CAPTCHA — built-in generation utilities
- Minimal Dependencies — Asio, OpenSSL, Zlib, Brotli. Everything else is optional
- ASAN + UBSAN — enabled by default in Debug builds; ThreadSanitizer available in Release
Project Layout
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 Runtime Requirements
| Item | Value |
|---|---|
| C++ Standard | C++20 |
| Dependencies | Asio, OpenSSL, Zlib, Brotli |
| Platforms | Linux ≥ 22.04, macOS ≥ 14, Windows ≥ 10 (MSVC 19.25+) |
| Build Systems | CMake / xmake |
Get Started
git clone https://github.com/hggq/paozhu.git myproject cd myproject sh mini_project.sh # strips demo modules, leaves clean scaffold mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release make -j$(nproc) sudo ./bin/paozhu Open http://localhost/hello — you'll see your first response from the Paozhu server.
For the full documentation, visit hggq.github.io/paozhudocs. Paozhu is licensed under MIT.

