Documentation
Cookbook & Templates

Real-world Templates

Copy production-ready solutions and design architectures built using the Kitwork sovereign engine.

01

E-commerce Store Checkout

Create a dynamic checkout route that records transaction rows in the database and generates custom VietQR vectors dynamically.

checkout.js
router.post("/order/checkout").handle((req, res) => {
    const body = req.body().json();

    // 1. Write order details to the database
    const order = db.table("orders").create({
        amount: body.amount,
        status: "pending"
    });

    // 2. Build VietQR payload
    const payment = napas
        .bank("970415", "1234567890")
        .amount(order.amount)
        .info("PAY ORDER " + order.id);

    const qrSvg = qrcode.napas(payment).svg();
    return res.json({
        orderId: order.id,
        qrcode: qrSvg
    });
});
02

Auto-reporting Worker

Combine isolated Goroutines with headless browser captures to fetch stats, snapshot visual charts, and record backups periodically.

cron-worker.js
// Spawn background worker scope
go(() => {
    while (true) {
        log.Print("Initiating dashboard capture...");
        try {
            const png = chromedp.capture("http://127.0.0.1:8080/dashboard", {
                width: 1920,
                height: 1080,
                waitSelector: "#charts-loaded"
            });
            // Save to local backup, send to webhook, etc.
            log.Print("Dashboard snapshot recorded successfully.");
        } catch (err) {
            log.Print("Capture failed: " + err);
        }
        // Wait for 24 hours
        sys.sleep("24h");
    }
});