Paozhu 炮竹
为 C++ Web 快速开发而生的全栈AI框架 A Full-stack AI Framework for Rapid C++ Web Development
📚 框架简介 📚 Framework Introduction
Paozhu 炮竹 (🧨) 来源中国传统鞭炮,迅速、响亮。 Paozhu (🧨) Derived from traditional Chinese firecrackers, it is fast and loud.
Paozhu (🧨) 是一款 C++ Web 开发框架,内置 HTTP/1、HTTP/2、C++ ORM,可以轻松优雅地编写 Web 程序,打破以往 C++ 写 Web 程序不方便的问题。 Paozhu (🧨) is a C++ web development framework with built-in HTTP/1, HTTP/2, C++ ORM, making it easy and elegant to write web programs, breaking the previous inconvenience of writing web programs in C++.
Paozhu 编写了 Web 开发底层设施,比如多域名绑定、SSL 证书管理、Cookie、Session、HTML 表单管理、URL 处理、文件上传下载、HttpClient 客户端、数据库连接 ORM、WebSocket、日志、HTML 模板,涵盖 Web 开发基础。 Paozhu has developed the underlying infrastructure for web development, such as multi-domain binding, SSL certificate management, Cookie, Session, HTML form management, URL routing, file upload/download, HttpClient, database ORM, WebSocket, logging, and HTML templates, covering the basics of web development.
框架基于 C++20 标准,开启了 ASAN 和完整错误提示,方便开发阶段发现问题。压力测试可发现多线程数据竞争问题,运行时可结合 coredumpctl 查看内存栈。配合智能指针基本杜绝内存泄露和越界问题。 The framework is based on C++20, enabling ASAN and comprehensive error hints (-Wall) to identify problems during development. Stress testing can detect multi-threaded data race issues. Combined with smart pointers, the framework has essentially eliminated memory leaks and buffer overflow issues.
Paozhu 使用 C++,主要考虑接入大模型(CUDA、文件存储、网络、内存操作)。对比 Go、Java、Rust,各有不足,C++ 更适合 AI 深度整合。ASAN 和 coredumpctl 两个工具可保证 C++ 质量。 Paozhu uses C++ mainly for large model integration (CUDA, file storage, network, memory operations). Compared to Go, Java, and Rust, C++ is better suited for deep AI integration. ASAN and coredumpctl tools help ensure C++ code quality.
💻 Hello World 示例 💻 Hello World Example
📦 项目完整源码已开源,欢迎访问 GitHub: https://github.com/hggq/paozhu 获取全部源码与示例 📦 The full source code is open source. Visit GitHub: https://github.com/hggq/paozhu for all source code and examples
仅需几行代码即可创建一个 Web 接口 testhello.cpp 文件 放在 controller/src 目录下面
Create a web endpoint with just a few lines of code, testhello.cpp in controller/src directory
#include "httppeer.h" #include "testhello.h" namespace http { //@urlpath(null,hello) std::string testhello(std::shared_ptr<httppeer> peer) { httppeer &client = peer->get_peer(); client << " Hello world! Paozhu c++ web framework "; return ""; } }// namespace http
无需编写 testhello.h 文件,框架自动生成这个文件,直接编译 No need to write the testhello.h file, the framework will automatically generate it, Directly compile by running
mkdir build
cd build
cmake ..
make
📁 控制器文件必须放在 controller/src 目录下面
📁 Controller files must be placed in the controller/src directory
//@urlpath 注解自动将函数映射到 /hello 路径 //@urlpath annotation auto-maps function to /hello path
✨ 核心特色 ✨ Core Features
强大的内置功能,助你快速构建高性能 Web 应用 Powerful built-in features to help you build high-performance web apps
🔐 SSL 证书自动续期 🔐 SSL Certificate Auto-Renewal
内置 ACME 协议支持,自动申请与续期 SSL 证书,HTTPS 永不过期 Built-in ACME protocol for automatic SSL certificate issuance and renewal
ACME 自动续期ACME Auto-Renewal
证书到期前自动更新,全程无需人工干预Renews certificates before expiry, fully automated
OCSP StaplingOCSP Stapling
自动 OCSP 装订,提升握手性能与隐私Automatic OCSP stapling for faster, private handshakes
ZeroSSL 支持ZeroSSL Support
内置 ZeroSSL DV 接口,支持 EAB 认证Built-in ZeroSSL DV endpoint with EAB auth
智能续期时机Smart Renewal Timing
可配置到期前天数与每日执行时刻Configurable days-before-expiry and run time
; conf/server.conf ACME 配置ACME settings
acme_auto = 0 自动 SSL 证书更新Auto SSL certificate renewal
acme_every_day = 7 每天几点执行 ACMEDaily hour to run ACME
ocsp_intv_time = 14400 OCSP 更新间隔(秒)OCSP update interval (seconds)
; conf/acme.conf ACME 证书配置ACME certificate config
[info]
acme_path = ./acme ACME 工作目录ACME working directory
cert_path = ./conf 证书存储目录Certificate storage directory
email = your@email.com 邮箱(必须)Email (mandatory)
days_remain = 10 提前多少天更新证书Renew days before expiry
[zerossl]
server_url = https://acme.zerossl.com/v2/DV90 ZeroSSL 接口ZeroSSL endpoint
eab_kid = EAB Key IDEAB Key ID
eab_hmac_key = EAB HMAC KeyEAB HMAC Key
💻 需求环境 💻 System Requirements
框架基于 C++20,确保你的系统支持相应的编译器 Built on C++20, ensure your compiler supports C++20 standard
macOSmacOS
macOS 11 BigSur 以上,推荐 macOS 14 SonomamacOS 11 BigSur+, recommended macOS 14 Sonoma
UbuntuUbuntu
Ubuntu 22.04 以上Ubuntu 22.04 or higher
RockyLinux/AlmaLinuxRockyLinux/AlmaLinux
9.1 以上版本9.1 or higher
WindowsWindows
Win10,编译器 19.25 以上Win10 with compiler 19.25+
依赖第三方开发包: OpenSSL、Zlib、Brotli、ASIORequired dependencies: OpenSSL, Zlib, Brotli, ASIO
🏗️ 技术架构 🏗️ Technical Architecture
框架使用 M:N 并发模型,IO 线程与业务线程分离 Uses M:N concurrency model with separated IO and business threads
+-----------------------+ +-----------------------+ +----------------------------+
| thread accept(80 443) | | asio coroutine thread | | thread pool(business code) |
+-----------------------+ +-----------------------+ +----------------------------+
框架使用 ASIO 的线程池做 IO 处理(网络收发),内置业务线程池运行业务代码。HTTP/HTTPS 监听连接到来,协程函数直接运行,普通函数丢到业务线程池。静态文件直接发送,不走业务线程。 ASIO thread pool handles IO (network send/receive), while built-in business thread pool runs application code. HTTP/HTTPS listeners accept connections; coroutine functions run directly, regular functions go to business thread pool. Static files are served directly without business thread involvement.
C++ 协程具有传染性,在协程注册函数中需使用 ORM 协程方法。普通函数中无法发起协程函数,只能使用 ORM 普通函数。建议一个连接一个线程的经典模式。 C++ coroutines are contagious — coroutine handler functions must use async ORM methods, while regular handlers use sync ORM methods. The classic one-connection-per-thread pattern is recommended.
📂 项目结构 📂 Project Structure
框架未分离命令行工具独立安装,全部包含在一个项目内 Framework and CLI are bundled in a single project
.
├── asio asio 库文件ASIO library files
├── bin 编译后的执行文件Compiled executables
├── cache 缓存压缩文件Cache compressed files
├── conf 配置文件 (server.conf, orm.conf)Config files (server.conf, orm.conf)
├── controller 路由器代码入口Router code entry
├── libs 业务代码库Business code library
├── log 日志目录Log directory
├── models ORM 业务代码ORM business code
├── module 可插拔 SO 存放Pluggable SO storage
├── orm ORM 实体映射类ORM entity mapping classes
├── startup 框架 main 入口Framework main entry
├── temp 临时文件Temporary files
├── vendor 主程序与第三方包Main program and third-party packages
├── view HTML 模板HTML templates
├── viewsrc 编译好的视图Compiled views
├── websockets WebSocket 程序WebSocket programs
└── www 静态文件目录Static file directory
🎯 核心特性 🎯 Core Features
强大的内置功能,助你快速构建高性能 Web 应用 Powerful built-in features to help you build high-performance web apps
📊 SVG 图表模块 📊 SVG Charts Module
Paozhu 内置强大的 SVG 图表生成库 pzcharts,支持 17 种图表类型,纯 C++ 实现,无需任何前端依赖
Paozhu includes the powerful pzcharts SVG chart library with 17 chart types, pure C++ implementation with no frontend dependencies
-DENABLE_CHART=ON 即可启用图表模块
💡 Add -DENABLE_CHART=ON during compilation to enable the chart module
📖 入门完整简介 📖 Complete Introduction
从零开始,系统学习 Paozhu 框架 Systematically learn Paozhu from scratch
项目概述
了解框架设计理念、核心特性和技术栈
Project Overview
Learn the design philosophy, core features and tech stack
核心架构
深入理解 MVC 分层、I/O 模型和组件协作
Core Architecture
Deep dive into MVC, I/O model and component collaboration
快速开始
30 分钟完成环境搭建并运行 Hello World
Quick Start
Set up environment and run Hello World in 30 minutes
控制器开发
学习注解路由、参数处理、Session 管理
Controller Development
Learn annotation routing, parameter handling, session
ORM 数据访问
使用内置 ORM 操作数据库,支持事务和连接池
ORM Data Access
Built-in ORM with transactions and connection pooling
视图系统
模板渲染、变量传递、JSON 响应
View System
Template rendering, variable passing, JSON responses
WebSocket 教程
实时通信、协程 WebSocket、客户端与服务端
WebSocket Guide
Real-time communication, coroutine WebSocket
API 参考
完整的 API 文档,涵盖 httppeer、ORM、PDF 等
API Reference
Complete API docs: httppeer, ORM, PDF, Excel, etc.
高级模块
PDF 生成、Excel 读写、短信、邮件、支付等内置模块
Advanced Modules
PDF generation, Excel, SMS, email, payment integration
性能与部署
性能优化、生产部署、故障排查
Performance & Deployment
Performance tuning, production deployment, troubleshooting
💻 平台安装指南 💻 Platform Installation
选择你的平台,查看详细的安装步骤 Choose your platform and view detailed installation steps