engine

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

README

🚀 Kitwork Engine

"High-Performance Execution Engine for Complex Business Logic."

Go Version Architecture Efficiency License

Kitwork Engine is an industrial-grade logic infrastructure designed for high-concurrency systems. It provides a specialized runtime to execute complex workflows with nanosecond precision, bridging the gap between low-level Go performance and high-level developer productivity.

📚 Table of Contents

🚀 Quick Start

Get up and running in under 30 seconds:

git clone https://github.com/kitwork/engine
go run cmd/server/main.go
# Server online at http://localhost:8100

Define your first Logic Work (demo/api/hello.js):

work("Service")
  .get("/hello", () => {
    return { status: "Online", engine: "Kitwork 1.0" };
  });

🧠 Core Concepts

  • Nanosecond VM: A proprietary stack-based VM that executes bytecode instructions in ~70ns.
  • Logic as Infrastructure: Your business logic is decoupled from the server implementation.
  • Zero-GC Pressure: The engine pools task contexts and VM stacks, ensuring consistent performance without GC pauses.

🌐 Web Stack Primitives

Zero-Copy Routing

Kitwork uses a high-performance Trie-based router for maximum throughput.

work("App")
    .get("/users", listUsers)           // Static
    .get("/users/:id", getUser)         // Dynamic Parameter
    .post("/users", createUser)          // POST Payload
    .put("/users/:id/status", update)    // Method-based mapping
Request & Response Mapping
Function Description Example
params(key) Dynamic path parameters. const id = params("id")
query(key) URL query string data. const p = query("page")
body(key?) JSON request payload (Lazy-load). const email = body("email")
header(key) Request headers. const auth = header("Authorization")
status(code) Set HTTP status code. status(201)
redirect(url) Immediate redirect. redirect("/home")
Security & Cookies

Modern security defaults out-of-the-box.

cookie("session_id", "secret-token", {
    httpOnly: true, // XSS Prevention
    secure: true,   // HTTPS only
    maxAge: 3600    // 1-hour expiration
});

🗄️ Elite ORM (The Magic DB)

The most intuitive database SDK ever built for a scripting environment.

🌟 Magic Lambda Join (Double Inference)

Parameters in Kitwork aren't just variables; they are Schema References. The engine infers join logic directly from your parameter names.

// Variable 'orders' automatically maps to table "orders"
db().from("users")
    .join((orders, users) => orders.user_id == users.id)
    .take();
🧠 Smart Operator Inference

Stop typing .like() or .in(). Let the data speak for itself.

  • Auto-Pattern: u.name == "Apple%"WHERE name LIKE 'Apple%'
  • Auto-Set: u.id == [1, 2, 3]WHERE id IN (1, 2, 3)
🛠 Elite Terminal Methods
Method Description SQL Result
.take(n?) Execute the query and return Array. SELECT * LIMIT n
.one() Return a single Object or null. LIMIT 1
.last() Smart ordering to fetch latest record. ORDER BY id DESC LIMIT 1
.find(id/fn) Lookup by Primary Key or Lambda. WHERE id = $1 LIMIT 1

⚡ Industrial Concurrency

High-concurrency logic made simple and safe.

High-Performance Parallelism

Execute independent tasks concurrently to maximize I/O utilization.

const { user, profile } = parallel({
    user: () => db().from("users").find(1),
    profile: () => http().get("https://internal.service/profile/1")
});
Advanced Flow Control
  • go(() => ...): Dispatch heavy tasks to background workers.
  • defer(() => ...): Lifecycle management to run logic after the response is sent.

📦 Explicit Caching System

Explicit key management ensures your cache is as predictable as your code.

// Get-or-Set with human-readable TTL
const data = cache("top_sales", "1h30m", () => {
    return db().from("orders").where(o => o.amount > 1000).take();
});

🛠 Performance Markers

Kitwork is built for speed. Period.

Metric Result Context
Instruction Speed ~14,112,000 ops/s Raw VM Instruction Throughput
Logic Complex Ops ~605,000 ops/s Real-world data transformation
VM Overhead ~70ns Pure execution latency
GC Pause Impact Near-Zero Pooled resources architecture

⚙️ Modular Configuration

Enterprise-ready modular setup for scaling databases and services.

port: 8081
debug: true
source: ["./demo/api"]
# Modular Database Configuration
databases: 
  - "config/database/master.yaml"
# Modular SMTP Configuration
smtps: ["config/smtp/service.yaml"]

👨‍💻 Foundation & Architecture

"Performance is not an afterthought; it is the infrastructure."

👨‍💻 Logic Engine Architect

Huỳnh Nhân Quốc

  • ⚙️ Core Engine & Bytecode Development
  • ⚡ High-Performance Runtime (Golang)
  • 📜 Scripting Syntax & Logic Design
  • 🚀 kitwork.vn

Support DevelopmentSponsor KitWork / Huỳnh Nhân Quốc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(cfg *Config)

Run starts the Kitwork Engine using the provided Config. It will automatically discover modular configs and database settings within cfg.Sources.

func Test

func Test(source string, iterations ...int)

Test thực thi script với số vòng lặp tùy chọn (mặc định là 1) và báo cáo hiệu năng chi tiết (hỗ trợ đa luồng)

Types

type Config

type Config struct {
	Port      int      `yaml:"port"`
	Debug     bool     `yaml:"debug"`
	Sources   []string `yaml:"source"`
	Databases []string `yaml:"databases"`
	SMTPS     []string `yaml:"smtp"`
}

func LoadConfig

func LoadConfig(dir string) (*Config, error)

LoadConfig loads the root configuration file (config.yaml).

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result chứa kết quả thực thi và metadata

func Script

func Script(source string) *Result

Script thực thi một đoạn mã script và trả về kết quả chi tiết

func (*Result) Energy

func (r *Result) Energy() uint64

func (*Result) Error

func (r *Result) Error() error

func (*Result) Raw

func (r *Result) Raw() value.Value

func (*Result) Value

func (r *Result) Value() any

Directories

Path Synopsis
cmd
server command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL