| Crates.io | kotoba-main |
| lib.rs | kotoba-main |
| version | 0.1.22 |
| created_at | 2025-09-19 15:05:58.968492+00 |
| updated_at | 2025-09-19 15:05:58.968492+00 |
| description | GP2-based Graph Rewriting Language - ISO GQL-compliant queries, MVCC+Merkle persistence, and distributed execution |
| homepage | https://github.com/com-junkawasaki/kotoba |
| repository | https://github.com/com-junkawasaki/kotoba |
| max_upload_size | |
| id | 1846593 |
| size | 18,075,912 |
GP2-based Graph Rewriting + Event Sourcing + ISO GQL - A comprehensive graph processing platform featuring complete Event Sourcing, ISO GQL-compliant queries, MVCC+Merkle persistence, and distributed execution using hexagonal architecture.
๐ Core Graph Processing System
๐ GP2-based Graph Rewriting Engine
๐ Event Sourcing + Materialized Views
๐ ISO GQL-compliant Graph Queries
โก MVCC + Merkle DAG Persistence
๐๏ธ Hexagonal Architecture (Port/Adapter Pattern)
๐ง Pluggable Storage Adapters (RocksDB, Redis, In-Memory)
Kotoba is a Core Graph Processing System featuring GP2-based graph rewriting with complete Event Sourcing capabilities, ISO GQL-compliant queries, MVCC+Merkle persistence, and distributed execution using hexagonal architecture.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐๏ธ PRESENTATION LAYER โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ๐ HTTP/GraphQL API โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ ๐ฑ CLI & Web Clients โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ฏ APPLICATION LAYER โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ๐ CORE GRAPH PROCESSING โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ๏ธ GRAPH REWRITING ENGINE (GP2) โ โ โ
โ โ โ ๐ EVENT SOURCING ENGINE โ โ โ
โ โ โ ๐ PROJECTION ENGINE โ โ โ
โ โ โ ๐ GQL QUERY ENGINE โ โ โ
โ โ โ ๐ฃ๏ธ ROUTING ENGINE โ โ โ
โ โ โ ๐ญ STATE GRAPH ENGINE โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ง INFRASTRUCTURE LAYER โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ๐พ STORAGE ADAPTERS โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ ๐๏ธ RocksDB Adapter โ โ โ
โ โ โ ๐ด Redis Adapter โ โ โ
โ โ โ ๐ง In-Memory Adapter โ โ โ
โ โ โ โ๏ธ Distributed Storage โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Kotoba supports multiple storage backends through its Port/Adapter architecture:
# Install system dependencies (Ubuntu/Debian)
sudo apt-get install clang llvm-dev libclang-dev
# Install system dependencies (macOS)
brew install llvm
# RocksDB will be automatically downloaded and built
# Install Redis
# Ubuntu/Debian:
sudo apt-get install redis-server
# macOS:
brew install redis
# Start Redis server
redis-server
# No additional setup required - default option
# Clone the repository
git clone https://github.com/com-junkawasaki/kotoba.git
cd kotoba
# Build the project (includes all crates)
cargo build --release
# Run the CLI
./target/release/kotoba --help
# Or run with cargo
cargo run -- --help
# Create a simple graph and query it
echo 'CREATE GRAPH test;
INSERT (:Person {name: "Alice"})-[:KNOWS]->(:Person {name: "Bob"});
MATCH (p:Person) RETURN p.name;' > query.gql
cargo run -- query --file query.gql
# Start event sourcing with in-memory storage
cargo run -- event-stream --create example_stream
# Add events
cargo run -- event-stream --stream example_stream --add "UserCreated" '{"id": 1, "name": "Alice"}'
# Create projection
cargo run -- projection --create user_count --query "MATCH (u:User) RETURN count(u) as total"
# Define a graph rewriting rule
echo 'rule: {
left: (:A)-[:edge]->(:B)
right: (:A)-[:edge]->(:C)-[:edge]->(:B)
conditions: []
}' > rewrite_rule.jsonnet
cargo run -- rewrite --rule rewrite_rule.jsonnet --apply
# Build Docker image
docker build -t kotoba .
# Run with RocksDB storage
docker run -v $(pwd)/data:/data kotoba --storage rocksdb --path /data
# Run with Redis storage
docker run -p 6379:6379 -d redis
docker run --network host kotoba --storage redis --url redis://localhost:6379
The Nix environment provides:
- โ
Exact Rust version (1.82.0)
- โ
All required dependencies
- โ
Development tools (docker, kind, kubectl, helm)
- โ
Reproducible builds
- โ
Cross-platform support
### Installation
```bash
# Clone the repository
git clone https://github.com/com-junkawasaki/kotoba.git
cd kotoba
# Install dependencies and build
cargo build
# Run comprehensive test suite (38/38 tests passing)
cargo test --workspace
# Build release version
cargo build --release
Kotoba includes a complete Jsonnet implementation supporting arrays, objects, functions, and string interpolation:
example.jsonnet
// Local variables and functions
local version = "1.0.0";
local add = function(x, y) x + y;
// Object with computed values
{
app: {
name: "Kotoba Demo",
version: version,
features: ["jsonnet", "graph", "gql"],
},
// Array operations
numbers: [1, 2, 3, 4, 5],
doubled: [x * 2 for x in self.numbers],
// String interpolation
greeting: "Hello, %(name)s!" % { name: "World" },
// Function calls
sum: add(10, 20),
// Conditional logic
status: if self.sum > 25 then "high" else "low",
}
Run with Kotoba:
# Evaluate Jsonnet file
cargo run --bin kotoba-jsonnet evaluate example.jsonnet
# Convert to JSON
cargo run --bin kotoba-jsonnet to-json example.jsonnet
Users create .kotoba files in Jsonnet format for graph processing:
graph.kotoba
{
// Graph data
graph: {
vertices: [
{ id: "alice", labels: ["Person"], properties: { name: "Alice", age: 30 } },
{ id: "bob", labels: ["Person"], properties: { name: "Bob", age: 25 } },
],
edges: [
{ id: "follows_1", src: "alice", dst: "bob", label: "FOLLOWS" },
],
},
// GQL queries
queries: [
{
name: "find_people",
gql: "MATCH (p:Person) RETURN p.name, p.age",
},
],
// ๅฎ่กใญใธใใฏ
handlers: [
{
name: "main",
function: "execute_queries",
metadata: { description: "Execute all defined queries" },
},
],
}
ๅฎ่กๆนๆณ
# .kotobaใใกใคใซใๅฎ่ก
kotoba run app.kotoba
# ใพใใฏใตใผใใผใขใผใใง่ตทๅ
kotoba server --config app.kotoba
Kotoba adopts a modular multi-crate architecture for maximum flexibility:
โโโ kotoba-core/ # Core types and IR definitions
โโโ kotoba-jsonnet/ # Complete Jsonnet implementation (38/38 tests passing)
โโโ kotoba-graph/ # Graph data structures and operations
โโโ kotoba-storage/ # High-performance RocksDB + Redis hybrid storage
โโโ kotoba-execution/ # Query execution and planner
โโโ kotoba-rewrite/ # Graph rewriting engine
โโโ kotoba-server/ # HTTP server and handlers
โโโ kotoba-kotobas/ # KotobaScript - Declarative programming language
โโโ kotoba2tsx/ # TypeScript/React code generation
# ๐ Advanced Deployment Extensions
โโโ kotoba-deploy-core/ # Core deployment types and configurations
โโโ kotoba-deploy-cli/ # Advanced deployment CLI with progress bars
โโโ kotoba-deploy-controller/ # Advanced deployment strategies (rollback, blue-green, canary)
โโโ kotoba-deploy-network/ # CDN integration, security, and edge optimization
โโโ kotoba-deploy-scaling/ # AI-powered scaling and performance monitoring
โโโ kotoba-deploy-git/ # Git integration and webhook handling
โโโ kotoba-deploy-hosting/ # Application hosting and runtime management
โโโ kotoba/ # Main integration crate
Each crate can be used independently, allowing you to pick only the features you need.
kotoba-jsonnet - Complete Jsonnet Implementation"%(name)s" % { name: "World" }local x = 42; x + 1kotoba-graph - Graph Processing Corecargo test --workspace passesCLI Extension (kotoba-deploy-cli):
Controller Extension (kotoba-deploy-controller):
Network Extension (kotoba-deploy-network):
Scaling Extension (kotoba-deploy-scaling) - Planned:
# .kotobaใใกใคใซใงๅ
จใฆๅฎ็พฉ
kotoba run myapp.kotoba
# ้็บๆใฏใฆใฉใใใขใผใ
kotoba run myapp.kotoba --watch
Rust API๏ผๅ ้จไฝฟ็จ๏ผ
// Rust APIใฏไธปใซๅ
้จๅฎ่ฃ
ใงไฝฟ็จ
use kotoba_core::types::*;
use kotoba_graph::prelude::*;
ๅcrateใฏๆกไปถไปใใณใณใใคใซใซใใWASMใฟใผใฒใใใซใๅฏพๅฟใใฆใใพใ๏ผ
# WASMใใซใ
cargo build --target wasm32-unknown-unknown --features wasm
Kotoba is based on a Process Network Graph Model, where all components are centrally managed through dag.jsonnet.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ lib.rs โ
โ (Main Library) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ execution/ โ rewrite/ โ
โ (Query Executor) โ (DPO Rewriter) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ planner/ โ storage/ โ
โ (Query Planner) โ (MVCC+Merkle) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ graph/ โ ir/ โ
โ (Data Structures) โ (Core IR) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ types.rs โ
โ (Common Types) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// Get build order from dag.jsonnet
$ jsonnet eval dag.jsonnet | jq .topological_order
[
"types",
"ir_catalog",
"ir_rule",
"ir_query",
"ir_patch",
"graph_vertex",
"graph_edge",
"ir_strategy",
"graph_core",
"storage_mvcc",
"storage_merkle",
"storage_lsm", // RocksDB-based high-performance storage
"planner_logical",
"planner_physical",
"execution_parser",
"rewrite_matcher",
"rewrite_applier",
"planner_optimizer",
"rewrite_engine",
"execution_engine",
"lib"
]
queries.kotoba
{
config: {
type: "config",
name: "QueryExample",
},
// ใฐใฉใใใผใฟ
graph: {
vertices: [
{ id: "alice", labels: ["Person"], properties: { name: "Alice", age: 30 } },
{ id: "bob", labels: ["Person"], properties: { name: "Bob", age: 25 } },
{ id: "charlie", labels: ["Person"], properties: { name: "Charlie", age: 35 } },
],
edges: [
{ id: "f1", src: "alice", dst: "bob", label: "FOLLOWS" },
{ id: "f2", src: "bob", dst: "charlie", label: "FOLLOWS" },
],
},
// GQLใฏใจใชๅฎ็พฉ
queries: [
{
name: "follow_network",
gql: "MATCH (p:Person)-[:FOLLOWS]->(f:Person) WHERE p.age > 25 RETURN p.name, f.name",
description: "25ๆญณไปฅไธใฎไบบใใใฉใญใผใใฆใใไบบใๅๅพ",
},
],
handlers: [
{
name: "execute_query",
function: "run_gql_query",
parameters: { query_name: "follow_network" },
},
],
}
kotoba run queries.kotoba
rewrite.kotoba
{
config: {
type: "config",
name: "RewriteExample",
},
// ใฐใฉใๆธๆใใซใผใซ
rules: [
{
name: "triangle_collapse",
description: "ไธ่งๅฝขใๆใใใใ",
lhs: {
nodes: [
{ id: "u", type: "Person" },
{ id: "v", type: "Person" },
{ id: "w", type: "Person" },
],
edges: [
{ id: "e1", src: "u", dst: "v", type: "FOLLOWS" },
{ id: "e2", src: "v", dst: "w", type: "FOLLOWS" },
],
},
rhs: {
nodes: [
{ id: "u", type: "Person" },
{ id: "w", type: "Person" },
],
edges: [
{ id: "e3", src: "u", dst: "w", type: "FOLLOWS" },
],
},
},
],
// ๅฎ่กๆฆ็ฅ
strategies: [
{
name: "exhaust_triangle_collapse",
rule: "triangle_collapse",
strategy: "exhaust",
order: "topdown",
},
],
handlers: [
{
name: "apply_rewrite",
function: "execute_rewrite",
parameters: { strategy_name: "exhaust_triangle_collapse" },
},
],
}
server.kotoba
{
config: {
type: "config",
name: "GraphServer",
server: { host: "127.0.0.1", port: 3000 },
},
// ใซใผใๅฎ็พฉ
routes: [
{
method: "GET",
pattern: "/api/users",
handler: "list_users",
description: "ใฆใผใถใผไธ่ฆงใๅๅพ",
},
{
method: "POST",
pattern: "/api/users",
handler: "create_user",
description: "ใฆใผใถใผใไฝๆ",
},
],
// ใฐใฉใในใญใผใ
schema: {
node_types: ["User", "Post"],
edge_types: ["FOLLOWS", "LIKES"],
},
handlers: [
{
name: "list_users",
function: "execute_gql",
parameters: {
query: "MATCH (u:User) RETURN u.name, u.email",
format: "json",
},
},
{
name: "create_user",
function: "create_graph_node",
parameters: {
type: "User",
properties: ["name", "email", "age"],
},
},
],
}
Kotobaใใญใธใงใฏใใงใฏใ่จญๅฎใใกใคใซใUIๅฎ็พฉใชใฉใซ.kotobaใใกใคใซๅฝขๅผใไฝฟ็จใใพใใใใใฏJsonnetๅฝขๅผใใใผในใจใใๆง้ ๅใใใ่จญๅฎใใฉใผใใใใงใใ
.kotobaใใกใคใซใฏไปฅไธใฎ็นๅพดใๆใกใพใ๏ผ
// ่จญๅฎใใกใคใซใฎๅบๆฌๆง้
{
// ่จญๅฎใปใฏใทใงใณ
config: {
type: "config",
name: "MyApp",
version: "1.0.0",
metadata: {
description: "ใขใใชใฑใผใทใงใณ่จญๅฎ",
},
},
// ใณใณใใผใใณใๅฎ็พฉ
components: [
// ใณใณใใผใใณใใชใใธใงใฏใ
],
// ใฆใผใใฃใชใใฃ้ขๆฐ
makeComponent: function(name, type, props={}) {
// ใณใณใใผใใณใ็ๆ้ขๆฐ
},
}
type (ๅฟ
้ ): ใชใใธใงใฏใใฎ็จฎ้กใๆๅฎname (ๆจๅฅจ): ใชใใธใงใฏใใฎไธๆใช่ญๅฅๅญmetadata (ใชใใทใงใณ): ่ฟฝๅ ๆ
ๅ ฑ๏ผ่ชฌๆใใใผใธใงใณใชใฉ๏ผlocalๅคๆฐ: Jsonnetใฎใญใผใซใซๅคๆฐใซใใ่จญๅฎใฎๅ
ฑ้ๅ้ขๆฐ: ่จญๅฎ็ๆใฎใใใฎๅๅฉ็จๅฏ่ฝใช้ขๆฐ::ๆผ็ฎๅญ: ่จ็ฎใใญใใใฃใซใใๅ็่จญๅฎ็ๆconfig - ่จญๅฎใชใใธใงใฏใใขใใชใฑใผใทใงใณๅ จไฝใฎ่จญๅฎใๅฎ็พฉใใพใใ
local appVersion = "1.0.0";
config: {
type: "config",
name: "MyApp",
version: appVersion,
host: "127.0.0.1",
port: 8080,
theme: "light",
metadata: {
description: "ใขใใชใฑใผใทใงใณ่จญๅฎ",
environment: "development",
},
}
routes / middlewares - HTTP่จญๅฎHTTPใตใผใใผใฎใซใผใใจใใใซใฆใงใขใๆง้ ๅใใฆๅฎ็พฉใใพใใ
// ใฆใผใใฃใชใใฃ้ขๆฐ
local makeRoute = function(method, pattern, handler, desc) {
type: "route",
method: method,
pattern: pattern,
handler: handler,
metadata: { description: desc },
};
routes: [
makeRoute("GET", "/api/" + appVersion + "/users", "list_users", "List users"),
makeRoute("POST", "/api/" + appVersion + "/users", "create_user", "Create user"),
],
middlewares: [
{
type: "middleware",
name: "cors",
order: 10,
function: "cors_middleware",
metadata: {
description: "CORS handling middleware",
allowed_origins: ["*"],
},
},
],
components - UIใณใณใใผใใณใๅฎ็พฉReactใณใณใใผใใณใใๆง้ ๅใใฆๅฎ็พฉใใพใใ
local styles = {
button: { primary: "button primary", secondary: "button secondary" },
layout: { header: "header", sidebar: "sidebar" },
};
local makeButton = function(name, text, style, onClick) {
type: "component",
name: name,
component_type: "button",
props: {
text: text,
className: style,
onClick: onClick,
},
metadata: { description: name + " button" },
};
components: [
makeButton("SaveButton", "Save", styles.button.primary, "handleSave"),
makeButton("CancelButton", "Cancel", styles.button.secondary, "handleCancel"),
],
handlers / states - ใคใใณใใจ็ถๆ
็ฎก็ใคใใณใใใณใใฉใผใจ็ถๆ ใๅฎ็พฉใใพใใ
handlers: [
{
type: "handler",
name: "handleSave",
function: "handleSave",
metadata: { description: "Save form data" },
},
],
states: [
{
type: "state",
name: "user",
initial: null,
metadata: { description: "Current user state" },
},
{
type: "state",
name: "loading",
initial: false,
metadata: { description: "Loading state" },
},
],
Jsonnetใฎๆฉ่ฝใๆดป็จใใๅ็่จญๅฎใจใใชใใผใทใงใณใ
// ่จ็ฎใใญใใใฃ
allRoutes:: [r.pattern for r in self.routes],
routeCount:: std.length(self.routes),
// ใใชใใผใทใงใณ้ขๆฐ
validateRoutes:: function() {
local duplicates = [
pattern
for pattern in std.set([r.pattern for r in self.routes])
if std.count([r.pattern for r in self.routes], pattern) > 1
];
if std.length(duplicates) > 0 then
error "Duplicate route patterns: " + std.join(", ", duplicates)
else
"Routes validation passed";
},
// config.kotoba - HTTPใตใผใใผ่จญๅฎ
local apiVersion = "v1";
local defaultTimeout = 30000;
{
// ใตใผใใผ่จญๅฎ
config: {
type: "config",
host: "127.0.0.1",
port: 8080,
max_connections: 1000,
timeout_ms: defaultTimeout,
metadata: {
description: "HTTP server configuration",
environment: "development",
},
},
// ใฆใผใใฃใชใใฃ้ขๆฐ
makeRoute: function(method, pattern, handler, desc) {
type: "route",
method: method,
pattern: pattern,
handler: handler,
metadata: { description: desc },
},
makeMiddleware: function(name, order, func, desc) {
type: "middleware",
name: name,
order: order,
function: func,
metadata: { description: desc },
},
// ใซใผใๅฎ็พฉ
routes: [
$.makeRoute("GET", "/ping", "ping_handler", "Simple ping endpoint"),
$.makeRoute("GET", "/health", "health_check", "Health check endpoint"),
$.makeRoute("GET", "/api/" + apiVersion + "/users", "list_users", "List users"),
$.makeRoute("POST", "/api/" + apiVersion + "/users", "create_user", "Create user"),
],
// ใใใซใฆใงใขๅฎ็พฉ
middlewares: [
$.makeMiddleware("cors", 10, "cors_middleware", "CORS handling"),
$.makeMiddleware("auth", 20, "auth_middleware", "Authentication"),
$.makeMiddleware("logger", 100, "request_logger", "Request logging"),
],
// ่จ็ฎใใญใใใฃ
serverInfo:: {
host: $.config.host,
port: $.config.port,
routes_count: std.length($.routes),
middlewares_count: std.length($.middlewares),
},
}
// app.kotoba - React UI่จญๅฎ
local appName = "MyApp";
local appVersion = "1.0.0";
{
// ใขใใชใฑใผใทใงใณ่จญๅฎ
config: {
type: "config",
name: appName,
version: appVersion,
theme: "light",
title: "My App",
metadata: {
framework: "React",
description: "Sample React application",
},
},
// ในใฟใคใซๅฎๆฐ
styles: {
button: {
primary: "button primary",
secondary: "button secondary",
},
layout: {
header: "header",
main: "main-content",
},
},
// ใฆใผใใฃใชใใฃ้ขๆฐ
makeComponent: function(name, componentType, props={}, children=[], desc="") {
type: "component",
name: name,
component_type: componentType,
props: props,
children: children,
metadata: { description: desc },
},
makeButton: function(name, text, style, onClick, desc) {
$.makeComponent(name, "button", {
text: text,
className: style,
onClick: onClick,
}, [], desc),
},
// ใณใณใใผใใณใๅฎ็พฉ
components: [
$.makeComponent("App", "div", {}, ["Header", "Main"], "Root application component"),
$.makeComponent("Header", "header", {
title: $.config.title,
className: $.styles.layout.header,
}, ["Nav"], "Application header"),
$.makeButton("SaveBtn", "Save", $.styles.button.primary, "handleSave", "Save button"),
$.makeButton("CancelBtn", "Cancel", $.styles.button.secondary, "handleCancel", "Cancel button"),
],
// ใคใใณใใใณใใฉใผ
handlers: [
{
type: "handler",
name: "handleSave",
function: "handleSave",
metadata: { description: "Handle save action" },
},
{
type: "handler",
name: "handleCancel",
function: "handleCancel",
metadata: { description: "Handle cancel action" },
},
],
// ็ถๆ
็ฎก็
states: [
{
type: "state",
name: "user",
initial: null,
metadata: { description: "Current user state" },
},
{
type: "state",
name: "theme",
initial: $.config.theme,
metadata: { description: "Current theme state" },
},
],
}
Jsonnetใใกใคใซใฏjsonnetใณใใณใใพใใฏใใญใฐใฉใ ใซใใ่ฉไพกใๅฟ
่ฆใงใ๏ผ
# Jsonnetใใกใคใซใ่ฉไพกใใฆJSONใซๅคๆ
jsonnet eval config.kotoba
# ใพใใฏใใญใฐใฉใ ใง็ดๆฅไฝฟ็จ
jsonnet eval config.kotoba | jq .routes
// Rustใงใฎไฝฟ็จไพ
use std::process::Command;
// Jsonnetใใกใคใซใ่ฉไพก
let output = Command::new("jsonnet")
.arg("eval")
.arg("config.kotoba")
.output()?;
let config_json: serde_json::Value = serde_json::from_slice(&output.stdout)?;
// ่จญๅฎใไฝฟ็จ
if let Some(routes) = config_json.get("routes") {
println!("Found {} routes", routes.as_array().unwrap().len());
}
local appVersion = "v1";
local defaultPort = 8080;
{
config: {
version: appVersion,
port: defaultPort,
},
routes: [
{ pattern: "/api/" + appVersion + "/users" },
],
}
local makeApiRoute = function(method, resource, action) {
type: "route",
method: method,
pattern: "/api/v1/" + resource + "/" + action,
handler: resource + "_" + action,
};
routes: [
makeApiRoute("GET", "users", "list"),
makeApiRoute("POST", "users", "create"),
],
{
components: [/* ... */],
// ใณใณใใผใใณใๆฐใฎ่จ็ฎ
componentCount:: std.length(self.components),
// ใณใณใใผใใณใใฟใคใๅฅใฎ้่จ
componentTypes:: std.set([c.component_type for c in self.components]),
}
local environment = "production";
{
config: {
debug: if environment == "development" then true else false,
port: if environment == "production" then 80 else 3000,
},
// ใใชใใผใทใงใณ
validate:: function() {
if std.length(self.config.name) == 0 then
error "Application name is required"
else
"Configuration is valid";
},
}
localๅคๆฐใงๅฎ็พฉใใฆDRYๅๅใๅฎใ::ๆผ็ฎๅญใงๅ็ใช่จญๅฎๅคใ็ๆ//ใณใกใณใใๆดป็จใใฆ่จญๅฎใฎๆๅณใๆ็ขบใซ.kotobaๅฝขๅผ๏ผJsonnet๏ผใฏ้ๅธธใซๆกๅผตๆงใ้ซใใJsonnetใฎๅ
จๆฉ่ฝใๆดป็จใงใใพใ๏ผ
// utils.libsonnet
{
// ๆฑ็จใฆใผใใฃใชใใฃ้ขๆฐ
makeCrudRoutes(resource):: [
{
type: "route",
method: "GET",
pattern: "/api/v1/" + resource,
handler: resource + "_list",
},
{
type: "route",
method: "POST",
pattern: "/api/v1/" + resource,
handler: resource + "_create",
},
],
// ในใฟใคใซๅฎๆฐ
themes: {
light: { bg: "#ffffff", fg: "#000000" },
dark: { bg: "#000000", fg: "#ffffff" },
},
}
// ่คๆฐใฎ่จญๅฎใใกใคใซใๅๆ
local base = import "base.libsonnet";
local api = import "api.libsonnet";
base + api + {
// ่ฟฝๅ ่จญๅฎ
customRoutes: [
{ pattern: "/health", handler: "health_check" },
],
}
// ็ฐๅขใซๅฟใใ่จญๅฎๅใๆฟใ
local environment = std.extVar("ENVIRONMENT");
{
config: {
debug: environment != "production",
port: if environment == "production" then 80 else 3000,
database: {
host: if environment == "production"
then "prod-db.example.com"
else "localhost",
},
},
}
# ่จญๅฎใใกใคใซใฎๆค่จผ
jsonnet eval config.kotoba
# ็นๅฎใฎใปใฏใทใงใณใฎใฟๅๅพ
jsonnet eval -e "(import 'config.kotoba').routes"
# ใใชใใผใทใงใณๅฎ่ก
jsonnet eval -e "(import 'config.kotoba').validate()"
# ่จญๅฎใJSONใจใใฆไฟๅญ
jsonnet eval config.kotoba > config.json
# Check dependencies of specific component
jsonnet eval -e "local dag = import 'dag.jsonnet'; dag.get_dependencies('execution_engine')"
# Check components that depend on this component
jsonnet eval -e "local dag = import 'dag.jsonnet'; dag.get_dependents('types')"
# Get overall build order
jsonnet eval dag.jsonnet | jq .topological_order[]
# Check build order for specific node
jsonnet eval -e "local dag = import 'dag.jsonnet'; dag.get_build_order('graph_core')"
# Get investigation order when problems occur
jsonnet eval dag.jsonnet | jq .reverse_topological_order[]
# Get configuration for specific target
jsonnet eval -e "local lib = import 'lib.jsonnet'; lib.get_target_config('x86_64-apple-darwin')"
# Resolve component dependencies
jsonnet eval -e "local lib = import 'lib.jsonnet'; lib.resolve_dependencies('kotoba-core', ['full'])"
# Get Docker image configuration
jsonnet eval lib.jsonnet | jq .packaging.docker
# Get Debian package configuration
jsonnet eval lib.jsonnet | jq .packaging.debian
# 1. Make code changes
vim src/some_component.rs
# 2. Check dependencies
jsonnet eval -e "local dag = import 'dag.jsonnet'; dag.get_dependencies('some_component')"
# 3. Run tests
cargo test --package some_component
# 4. Check overall consistency
cargo check
# 5. Validate DAG
jsonnet eval -e "local dag = import 'dag.jsonnet'; dag.validate_dag()"
# 6. Commit
git add .
git commit -m "Update some_component"
Kotoba maintains high test coverage across all components, with particular emphasis on the storage layer achieving 95% coverage.
# Run all tests
cargo test
# Run storage tests (95% coverage)
cargo test -p kotoba-storage
# Run specific test
cargo test test_graph_operations
# Run documentation tests
cargo test --doc
# Generate coverage report (requires cargo-tarpaulin)
cargo tarpaulin -p kotoba-storage --out Html
# Run integration tests
cargo test --test integration
# Run benchmarks
cargo bench
# Run benchmark with LDBC-SNB dataset
cargo run --bin kotoba-bench -- --dataset ldbc-snb
# Build Docker image
docker build -t kotoba:latest .
# Run the image
docker run -p 8080:8080 kotoba:latest
# Create Debian package
cargo deb
# Install the package
sudo dpkg -i target/debian/kotoba_0.1.0_amd64.deb
# Install Homebrew Formula
brew install kotoba
Kotobaใฏ2ใคใฎไธป่ฆใชCLIใๆไพใใพใ๏ผ
Deno CLIใๅ่ใซใใไฝฟใใใใใณใใณใใฉใคใณใคใณใฟใผใใงใผในใๆไพใใพใใใฐใฉใๅฆ็ใใฏใจใชๅฎ่กใใใกใคใซๆไฝใชใฉใใตใใผใใใฆใใพใใ
ๅฎๅ จใชใใใญใคใกใณใ็ฎก็ๆฉ่ฝใๆไพใใ้ซๅบฆใชCLIใใใญใฐใฌในใใผใ่จญๅฎใใกใคใซๅฆ็ใ่ฉณ็ดฐใชใใทใงใณใๅใใฆใใพใใ
# ใใซใใใฆใคใณในใใผใซ
cargo build --release --features binary
cp target/release/kotoba ~/.local/bin/ # ใพใใฏPATHใฎ้ใฃใๅ ดๆใซ
# ใใซใ่กจ็คบ
kotoba --help
# ใใญใธใงใฏใๆ
ๅ ฑ่กจ็คบ
kotoba info
kotoba info --detailed --json
# GQLใฏใจใชๅฎ่ก
kotoba query "MATCH (n) RETURN n" --format json
# ใใกใคใซๅฎ่ก
kotoba run myfile.kotoba
# ใใกใคใซๆค่จผ
kotoba check src/
kotoba check --all
# ใใกใคใซใใฉใผใใใ
kotoba fmt src/
kotoba fmt --all --check
# ใตใผใใผ่ตทๅ
kotoba server --port 3000 --host 127.0.0.1
# ๆฐ่ฆใใญใธใงใฏใๅๆๅ
kotoba init my-project --template web
# ใใญใฅใกใณใ็ๆ
kotoba doc --output ./docs --format html
# ใใผใธใงใณ่กจ็คบ
kotoba version
# Deploy CLIใใใซใ
cargo build --release -p kotoba-deploy-cli
cp target/release/kotoba-deploy-cli ~/.local/bin/kotoba-deploy
# ใพใใฏCargo็ต็ฑใงใคใณในใใผใซ
cargo install --path crates/kotoba-deploy-cli
# ใใซใ่กจ็คบ
kotoba-deploy --help
# ใใใญใคใกใณใๅฎ่ก
kotoba-deploy deploy --name my-app --entry-point app.js --runtime nodejs --port 3000
# ่จญๅฎใใกใคใซใไฝฟ็จใใใใใญใค
kotoba-deploy deploy --config deploy.json
# ใใใญใคใกใณใไธ่ฆง่กจ็คบ
kotoba-deploy list --detailed
# ใใใญใคใกใณใในใใผใฟใน็ขบ่ช
kotoba-deploy status my-deployment-id
# ใใใญใคใกใณใๅๆญข
kotoba-deploy stop my-deployment-id --force
# ในใฑใผใซ่ชฟๆด
kotoba-deploy scale my-deployment-id 5
# ใญใฐ่กจ็คบ
kotoba-deploy logs my-deployment-id --follow --lines 100
# ่จญๅฎ็ฎก็
kotoba-deploy config --show
kotoba-deploy config --set log_level=debug
| ใณใใณใ | ่ชฌๆ | ไพ |
|---|---|---|
deploy |
ใขใใชใฑใผใทใงใณใใใใญใค | deploy --name app --runtime nodejs |
list |
ใใใญใคใกใณใไธ่ฆง่กจ็คบ | list --detailed |
status |
ใใใญใคใกใณใในใใผใฟใน็ขบ่ช | status deployment-123 |
stop |
ใใใญใคใกใณใๅๆญข | stop deployment-123 --force |
scale |
ใคใณในใฟใณในๆฐใ่ชฟๆด | scale deployment-123 3 |
logs |
ใใใญใคใกใณใใญใฐ่กจ็คบ | logs deployment-123 --follow |
config |
่จญๅฎ็ฎก็ | config --show |
# ่ฉณ็ดฐใชใใใญใคใน่จญๅฎ
kotoba-deploy deploy \
--name production-app \
--entry-point dist/server.js \
--runtime nodejs \
--port 8080 \
--env NODE_ENV=production \
--env DATABASE_URL=postgres://... \
--build-cmd "npm run build" \
--start-cmd "npm start" \
--min-instances 2 \
--max-instances 10 \
--cpu-threshold 0.8 \
--memory-threshold 0.8 \
--domain api.example.com \
--dry-run
# CDN็ตฑๅ
kotoba-deploy deploy \
--cdn-provider cloudflare \
--cdn-zone-id ZONE_ID \
--cdn-api-key API_KEY
# ใใซใผใฐใชใผใณใใใญใค
kotoba-deploy deploy \
--strategy blue-green \
--traffic-split 10 \
--health-check-endpoint /health
deploy.json
{
"metadata": {
"name": "my-production-app",
"version": "1.2.0"
},
"application": {
"entry_point": "dist/app.js",
"runtime": "nodejs",
"environment": {
"NODE_ENV": "production",
"PORT": "8080"
},
"build_command": "npm run build",
"start_command": "npm start"
},
"scaling": {
"min_instances": 2,
"max_instances": 10,
"cpu_threshold": 0.8,
"memory_threshold": 0.8,
"auto_scaling_enabled": true
},
"network": {
"domains": ["api.example.com"],
"ssl_enabled": true,
"cdn_enabled": true
},
"deployment": {
"strategy": "canary",
"traffic_percentage": 20,
"rollback_on_failure": true
}
}
# 1. ใขใใชใฑใผใทใงใณ้็บ
kotoba run app.kotoba --watch
# 2. ใใใญใคใกใณใๆบๅ
kotoba check deploy.kotoba
# 3. ใใใญใคใกใณใๅฎ่ก
kotoba-deploy deploy --config deploy.json --dry-run
kotoba-deploy deploy --config deploy.json --wait
# 4. ใใใญใคใกใณใ็ฎก็
kotoba-deploy list
kotoba-deploy status production-app
kotoba-deploy scale production-app 5
# 5. ใญใฐ็ฃ่ฆ
kotoba-deploy logs production-app --follow
# Generate documentation
cargo doc --open
# Generate documentation including private items
cargo doc --document-private-items --open
feature/your-feature-name# Install development dependencies
cargo install cargo-edit cargo-watch cargo-deb
# Set up pre-commit hooks
cp pre-commit.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
rustfmt and clippyThis project is licensed under the Apache License 2.0. See the LICENSE file for details.
๐ง CLI Extension (kotoba-deploy-cli)
๐๏ธ Controller Extension (kotoba-deploy-controller)
๐ Network Extension (kotoba-deploy-network)
๐ Scaling Extension (kotoba-deploy-scaling)
Kotoba implements a Process Network Graph Model where all components are centrally managed through dag.jsonnet. This ensures topological consistency and proper dependency resolution.
# Check build dependencies
jsonnet eval -e "local dag = import 'dag.jsonnet'; dag.get_dependencies('execution_engine')"
# Validate DAG structure
jsonnet eval -e "local dag = import 'dag.jsonnet'; dag.validate_dag()"
# Get deployment extension status
jsonnet eval -e "local dag = import 'dag.jsonnet'; dag.get_nodes_by_type('deploy_cli')"
Kotoba - Exploring the world of graphs through words, now with advanced deployment capabilities