Kotoba : "ใใจใฐ" - Core Graph Processing System
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.
)
)
๐ Overview
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.
๐ฏ Core Features
- ๐ GP2-based Graph Rewriting: Theoretical foundation for graph transformations
- ๐ Complete Event Sourcing: Immutable events, projections, materialized views
- ๐ ISO GQL-compliant Queries: Standardized graph query language
- โก MVCC + Merkle DAG Persistence: Consistent distributed data management
- ๐๏ธ Hexagonal Architecture: Clean separation of business logic and infrastructure
- ๐ง Pluggable Storage: Choose from RocksDB, Redis, or In-Memory implementations
- ๐ Distributed Execution: Multi-node coordination and consensus
- ๐ Type Safety: Full Rust type system with compile-time guarantees
๐๏ธ Architecture Overview
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐๏ธ 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 โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฏ Key Features
๐ Core Graph Processing Engine
- GP2-based Graph Rewriting: Theoretical foundation for graph transformations
- Graph Pattern Matching: Complex graph traversal and pattern recognition
- Rule-based Transformations: Declarative graph rewriting rules
- Graph Isomorphism: Advanced graph matching algorithms
- Concurrent Processing: Parallel graph operations and transformations
๐ช Complete Event Sourcing System
- Event Store: Immutable event storage with versioning
- Projection Engine: Real-time materialized views and read models
- Command Processing: CQRS pattern with command validation
- Event Streaming: Real-time event processing and subscriptions
๐ Advanced Graph Query Language
- ISO GQL Compliance: Industry-standard graph query language
- Path Queries: Variable-length path queries with constraints
- Aggregation Functions: Statistical and analytical operations
- Graph Analytics: Built-in graph algorithms and metrics
๐๏ธ Hexagonal Architecture (Port/Adapter Pattern)
- Clean Architecture: Business logic independent of infrastructure
- Dependency Inversion: Interfaces define contracts, implementations are pluggable
- Testability: Easy unit testing with mock adapters
- Technology Agnostic: Database/storage technology can be changed without affecting business logic
โก High-Performance Storage Options
- RocksDB: LSM-Tree based persistent storage with high write throughput
- Redis: In-memory caching with persistence options
- In-Memory: Fast development and testing storage
- Distributed: Multi-node storage with consensus
๐ Distributed & Scalable
- Multi-Node Coordination: Raft consensus for distributed operations
- Horizontal Scaling: Automatic partitioning and load balancing
- High Availability: Fault-tolerant design with automatic failover
- Global Distribution: Edge computing with CDN integration
๐ Advanced Deployment Extensions
- CLI Extension: Complete deployment management CLI with progress bars, configuration files, and detailed options
- Controller Extension: Advanced deployment strategies including rollback, blue-green, and canary deployments
- Network Extension: CDN integration (Cloudflare, AWS CloudFront), security features, and edge optimization
- Security Features: Rate limiting, WAF, DDoS protection, SSL/TLS certificate management
- Scalability: Intelligent scaling with performance monitoring and cost optimization
๐ Quick Start
Prerequisites
- Rust 1.70.0 or later
- Cargo package manager
- Optional: RocksDB or Redis for persistent storage
๐๏ธ Choose Your Storage Backend
Kotoba supports multiple storage backends through its Port/Adapter architecture:
Option 1: RocksDB (Persistent, High-Performance)
# Install system dependencies (Ubuntu/Debian)
# Install system dependencies (macOS)
# RocksDB will be automatically downloaded and built
Option 2: Redis (In-Memory with Persistence)
# Install Redis
# Ubuntu/Debian:
# macOS:
# Start Redis server
Option 3: In-Memory (Development/Testing)
# No additional setup required - default option
๐ฆ Installation & Basic Usage
# Clone the repository
# Build the project (includes all crates)
# Run the CLI
# Or run with cargo
๐ฏ Basic Examples
1. Execute a GQL Query
# Create a simple graph and query it
2. Event Sourcing Example
# Start event sourcing with in-memory storage
# Add events
# Create projection
3. Graph Rewriting Example
# Define a graph rewriting rule
๐ณ Docker Development (Alternative)
# Build Docker image
# Run with RocksDB storage
# Run with Redis storage
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
Basic Usage Examples
Jsonnet Evaluation
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
# Convert to JSON
Graph Processing
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ใใกใคใซใๅฎ่ก
# ใพใใฏใตใผใใผใขใผใใง่ตทๅ
๐๏ธ Architecture
Multi-Crate Architecture
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.
Crate Highlights
kotoba-jsonnet - Complete Jsonnet Implementation
- โ 38/38 tests passing - Full test coverage
- โ Arrays, Objects, Functions - Complete Jsonnet language support
- โ
String Interpolation -
"%(name)s" % { name: "World" } - โ
Local Variables -
local x = 42; x + 1 - โ JSON/YAML Output - Multiple serialization formats
kotoba-graph - Graph Processing Core
- โ Vertex/Edge Management - Full graph operations
- โ GP2 Rewriting - Theoretical graph transformations
- โ ISO GQL Queries - Standardized graph query language
Integration Features
- โ
Workspace Testing -
cargo test --workspacepasses - โ Clean Codebase - Clippy warnings minimized
- โ Documentation - Comprehensive API docs
๐ Deployment Extension Highlights
-
CLI Extension (
kotoba-deploy-cli):- โ Complete Deployment CLI - Progress bars, configuration files, detailed options
- โ Multi-format Output - JSON, YAML, human-readable formats
- โ Deployment Management - List, status, stop, scale, logs commands
- โ Configuration Handling - Auto-generation and validation
- โ Interactive Progress - Real-time deployment progress tracking
-
Controller Extension (
kotoba-deploy-controller):- โ Advanced Deployment Strategies - Rollback, blue-green, canary deployments
- โ Deployment History - Comprehensive deployment tracking and rollback
- โ Health Checks - Integrated health monitoring and auto-rollback
- โ Traffic Management - Gradual traffic shifting and canary releases
- โ Multi-strategy Support - Flexible deployment strategy selection
-
Network Extension (
kotoba-deploy-network):- โ CDN Integration - Cloudflare, AWS CloudFront, Fastly, Akamai support
- โ Security Features - Rate limiting, WAF, DDoS protection
- โ SSL/TLS Management - Automatic certificate renewal and custom certs
- โ Edge Optimization - Image optimization, compression, caching
- โ Geographic Routing - Nearest edge location selection
- โ Performance Monitoring - Real-time metrics and analytics
-
Scaling Extension (
kotoba-deploy-scaling) - Planned:- ๐ AI-Powered Scaling - Machine learning based traffic prediction
- ๐ Cost Optimization - Intelligent resource allocation
- ๐ Performance Monitoring - Advanced metrics collection
- ๐ Auto-scaling - Dynamic scaling based on multiple factors
- ๐ Load Balancing - Intelligent load distribution
ไฝฟ็จไพ
# .kotobaใใกใคใซใงๅ
จใฆๅฎ็พฉ
# ้็บๆใฏใฆใฉใใใขใผใ
Rust API๏ผๅ ้จไฝฟ็จ๏ผ
// Rust APIใฏไธปใซๅ
้จๅฎ่ฃ
ใงไฝฟ็จ
use *;
use *;
WASMๅฏพๅฟ
ๅcrateใฏๆกไปถไปใใณใณใใคใซใซใใWASMใฟใผใฒใใใซใๅฏพๅฟใใฆใใพใ๏ผ
# WASMใใซใ
Process Network Graph Model
Kotoba is based on a Process Network Graph Model, where all components are centrally managed through dag.jsonnet.
Main Components
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 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) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Build Order (Topological Sort)
// 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"
]
๐ Usage
1. Basic GQL Queries
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" },
},
],
}
2. Graph Rewriting
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" },
},
],
}
3. HTTP Server with Graph Operations
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 File Format
Kotobaใใญใธใงใฏใใงใฏใ่จญๅฎใใกใคใซใUIๅฎ็พฉใชใฉใซ.kotobaใใกใคใซๅฝขๅผใไฝฟ็จใใพใใใใใฏJsonnetๅฝขๅผใใใผในใจใใๆง้ ๅใใใ่จญๅฎใใฉใผใใใใงใใ
ๆฆ่ฆ
.kotobaใใกใคใซใฏไปฅไธใฎ็นๅพดใๆใกใพใ๏ผ
- Jsonnetๅฝขๅผ: JSONใฎในใผใใผใปใใใงใๅคๆฐใ้ขๆฐใๆกไปถๅๅฒใชใฉใฎๆฉ่ฝใๆดป็จ
- ๆง้ ๅ่จญๅฎ: ใชใใธใงใฏใใจ้ ๅใซใใ้ๅฑค็ใช่จญๅฎๆง้
- ใฆใผใใฃใชใใฃ้ขๆฐ: ่จญๅฎ็ๆใฎใใใฎๅๅฉ็จๅฏ่ฝใช้ขๆฐๅฎ็พฉ
- ่จ็ฎใใญใใใฃ: ๅ็ใช่จญๅฎ็ๆใจใใชใใผใทใงใณ
- ๅๅฎๅ จ: Jsonnetใฎๅใทในใใ ใซใใ่จญๅฎใฎๆดๅๆง็ขบไฟ
ใใกใคใซๅฝขๅผไปๆง
ๅบๆฌๆง้
// ่จญๅฎใใกใคใซใฎๅบๆฌๆง้
{
// ่จญๅฎใปใฏใทใงใณ
config: {
type: "config",
name: "MyApp",
version: "1.0.0",
metadata: {
description: "ใขใใชใฑใผใทใงใณ่จญๅฎ",
},
},
// ใณใณใใผใใณใๅฎ็พฉ
components: [
// ใณใณใใผใใณใใชใใธใงใฏใ
],
// ใฆใผใใฃใชใใฃ้ขๆฐ
makeComponent: function(name, type, props={}) {
// ใณใณใใผใใณใ็ๆ้ขๆฐ
},
}
ไธป่ฆใชใใญใใใฃ
type(ๅฟ ้ ): ใชใใธใงใฏใใฎ็จฎ้กใๆๅฎname(ๆจๅฅจ): ใชใใธใงใฏใใฎไธๆใช่ญๅฅๅญmetadata(ใชใใทใงใณ): ่ฟฝๅ ๆ ๅ ฑ๏ผ่ชฌๆใใใผใธใงใณใชใฉ๏ผlocalๅคๆฐ: Jsonnetใฎใญใผใซใซๅคๆฐใซใใ่จญๅฎใฎๅ ฑ้ๅ้ขๆฐ: ่จญๅฎ็ๆใฎใใใฎๅๅฉ็จๅฏ่ฝใช้ขๆฐ::ๆผ็ฎๅญ: ่จ็ฎใใญใใใฃใซใใๅ็่จญๅฎ็ๆ
ไธป่ฆใชใปใฏใทใงใณ
1. 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",
},
}
2. 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: ["*"],
},
},
],
3. 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"),
],
4. 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" },
},
],
5. ่จ็ฎใใญใใใฃใจใใชใใผใทใงใณ
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";
},
ไฝฟ็จไพ
HTTPใตใผใใผ่จญๅฎไพ
// 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),
},
}
React UI่จญๅฎไพ
// 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ใซๅคๆ
# ใพใใฏใใญใฐใฉใ ใง็ดๆฅไฝฟ็จ
|
// Rustใงใฎไฝฟ็จไพ
use Command;
// Jsonnetใใกใคใซใ่ฉไพก
let output = new
.arg
.arg
.output?;
let config_json: Value = from_slice?;
// ่จญๅฎใไฝฟ็จ
if let Some = config_json.get
Jsonnetๅบๆใฎๆฉ่ฝๆดป็จ
1. ๅคๆฐใจๅฎๆฐใฎไฝฟ็จ
local appVersion = "v1";
local defaultPort = 8080;
{
config: {
version: appVersion,
port: defaultPort,
},
routes: [
{ pattern: "/api/" + appVersion + "/users" },
],
}
2. ้ขๆฐใซใใ่จญๅฎ็ๆ
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"),
],
3. ่จ็ฎใใญใใใฃใซใใๅ็่จญๅฎ
{
components: [/* ... */],
// ใณใณใใผใใณใๆฐใฎ่จ็ฎ
componentCount:: std.length(self.components),
// ใณใณใใผใใณใใฟใคใๅฅใฎ้่จ
componentTypes:: std.set([c.component_type for c in self.components]),
}
4. ๆกไปถๅๅฒใจใใชใใผใทใงใณ
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ๅๅใๅฎใ - ้ขๆฐใซใใๆฝ่ฑกๅ: ่จญๅฎ็ๆใใฟใผใณใ้ขๆฐๅใใฆๅๅฉ็จๆงใ้ซใใ
- ่จ็ฎใใญใใใฃใฎไฝฟ็จ:
::ๆผ็ฎๅญใงๅ็ใช่จญๅฎๅคใ็ๆ - ๆง้ ๅ: ่จญๅฎใ่ซ็็ใชใปใฏใทใงใณ๏ผconfig, routes, components็ญ๏ผใซๅใใ
- ใใชใใผใทใงใณ: ่จญๅฎใฎๅฆฅๅฝๆงใๆค่จผใใ้ขๆฐใๅฎ็พฉ
- ใณใกใณใ: Jsonnetใฎ
//ใณใกใณใใๆดป็จใใฆ่จญๅฎใฎๆๅณใๆ็ขบใซ - ๅๅฉ็จ: ๅ ฑ้ใฎ้ขๆฐใในใฟใคใซใๅฅใใกใคใซใซๅ้ขใใฆimport
ๆกๅผตๆง
.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",
},
},
}
้็บใฏใผใฏใใญใผ
# ่จญๅฎใใกใคใซใฎๆค่จผ
# ็นๅฎใฎใปใฏใทใงใณใฎใฟๅๅพ
# ใใชใใผใทใงใณๅฎ่ก
# ่จญๅฎใJSONใจใใฆไฟๅญ
๐ ๏ธ Development
Using dag.jsonnet
1. Dependency Analysis
# Check dependencies of specific component
# Check components that depend on this component
2. Build Order Verification
# Get overall build order
|
# Check build order for specific node
3. Causality Identification During Troubleshooting
# Get investigation order when problems occur
|
Using lib.jsonnet
1. Build Configuration Verification
# Get configuration for specific target
# Resolve component dependencies
2. Packaging Configuration
# Get Docker image configuration
|
# Get Debian package configuration
|
Development Workflow
# 1. Make code changes
# 2. Check dependencies
# 3. Run tests
# 4. Check overall consistency
# 5. Validate DAG
# 6. Commit
๐งช Testing
Test Coverage: 95%
Kotoba maintains high test coverage across all components, with particular emphasis on the storage layer achieving 95% coverage.
# Run all tests
# Run storage tests (95% coverage)
# Run specific test
# Run documentation tests
# Generate coverage report (requires cargo-tarpaulin)
Coverage Highlights
- Storage Layer: 95% coverage with comprehensive LSM tree testing
- Core Types: Full coverage of Value, GraphRef, and IR types
- Graph Operations: Extensive testing of rewriting and query operations
- HTTP Server: Integration tests for API endpoints
Integration Tests
# Run integration tests
# Run benchmarks
LDBC-SNB Benchmark
# Run benchmark with LDBC-SNB dataset
๐ฆ Packaging
Docker Image
# Build Docker image
# Run the image
Debian Package
# Create Debian package
# Install the package
Homebrew
# Install Homebrew Formula
๐ง CLI Tools
Kotoba CLI Extensions
Kotobaใฏ2ใคใฎไธป่ฆใชCLIใๆไพใใพใ๏ผ
1. Core Kotoba CLI - Graph Processing & Development
Deno CLIใๅ่ใซใใไฝฟใใใใใณใใณใใฉใคใณใคใณใฟใผใใงใผในใๆไพใใพใใใฐใฉใๅฆ็ใใฏใจใชๅฎ่กใใใกใคใซๆไฝใชใฉใใตใใผใใใฆใใพใใ
2. Advanced Deploy CLI - Deployment Management
ๅฎๅ จใชใใใญใคใกใณใ็ฎก็ๆฉ่ฝใๆไพใใ้ซๅบฆใชCLIใใใญใฐใฌในใใผใ่จญๅฎใใกใคใซๅฆ็ใ่ฉณ็ดฐใชใใทใงใณใๅใใฆใใพใใ
๐๏ธ Core Kotoba CLI
ใคใณในใใผใซ
# ใใซใใใฆใคใณในใใผใซ
ๅบๆฌ็ใชไฝฟ็จๆนๆณ
# ใใซใ่กจ็คบ
# ใใญใธใงใฏใๆ
ๅ ฑ่กจ็คบ
# GQLใฏใจใชๅฎ่ก
# ใใกใคใซๅฎ่ก
# ใใกใคใซๆค่จผ
# ใใกใคใซใใฉใผใใใ
# ใตใผใใผ่ตทๅ
# ๆฐ่ฆใใญใธใงใฏใๅๆๅ
# ใใญใฅใกใณใ็ๆ
# ใใผใธใงใณ่กจ็คบ
๐ Advanced Deploy CLI
ใคใณในใใผใซ
# Deploy CLIใใใซใ
# ใพใใฏCargo็ต็ฑใงใคใณในใใผใซ
้ซๅบฆใชใใใญใคใกใณใๆฉ่ฝ
# ใใซใ่กจ็คบ
# ใใใญใคใกใณใๅฎ่ก
# ่จญๅฎใใกใคใซใไฝฟ็จใใใใใญใค
# ใใใญใคใกใณใไธ่ฆง่กจ็คบ
# ใใใญใคใกใณใในใใผใฟใน็ขบ่ช
# ใใใญใคใกใณใๅๆญข
# ในใฑใผใซ่ชฟๆด
# ใญใฐ่กจ็คบ
# ่จญๅฎ็ฎก็
Deploy CLIใฎไธปใชใณใใณใ
| ใณใใณใ | ่ชฌๆ | ไพ |
|---|---|---|
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 |
Deploy CLIใฎ้ซๅบฆใชใชใใทใงใณ
# ่ฉณ็ดฐใชใใใญใคใน่จญๅฎ
# CDN็ตฑๅ
# ใใซใผใฐใชใผใณใใใญใค
่จญๅฎใใกใคใซไพ
deploy.json
๐ ็ตฑๅใฏใผใฏใใญใผ
# 1. ใขใใชใฑใผใทใงใณ้็บ
# 2. ใใใญใคใกใณใๆบๅ
# 3. ใใใญใคใกใณใๅฎ่ก
# 4. ใใใญใคใกใณใ็ฎก็
# 5. ใญใฐ็ฃ่ฆ
๐ API Documentation
# Generate documentation
# Generate documentation including private items
๐ค Contributing
Contribution Guidelines
- Create Issue: Bug reports or feature requests
- Create Branch:
feature/your-feature-name - Implement Changes:
- Add tests
- Update documentation
- Verify dag.jsonnet consistency
- Create Pull Request
Development Environment Setup
# Install development dependencies
# Set up pre-commit hooks
Coding Standards
- Rust: Use
rustfmtandclippy - Commit Messages: Conventional Commits
- Testing: Add tests for all changes
- Documentation: Add documentation for all public APIs
๐ License
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
๐ Acknowledgments
- GP2 Team: Theoretical foundation for graph rewriting systems
- ISO/IEC: GQL standard specification
- Rust Community: Excellent programming language
๐ Support
- Documentation: https://kotoba.jun784.dev
- Issues: GitHub Issues
- Discussions: GitHub Discussions
๐ What's New - Advanced Deployment Extensions
v0.1.0 - Deployment Extensions Release
โ Completed Extensions
๐ง CLI Extension (kotoba-deploy-cli)
- Complete deployment CLI with progress bars and configuration management
- Multi-format output (JSON, YAML, human-readable)
- Advanced deployment options with environment variables, scaling, and networking
- Deployment lifecycle management (list, status, stop, scale, logs)
- Interactive progress tracking with real-time updates
๐๏ธ Controller Extension (kotoba-deploy-controller)
- Advanced deployment strategies: Rollback, Blue-Green, Canary
- Comprehensive deployment history and rollback capabilities
- Integrated health checks with auto-rollback on failure
- Traffic management with gradual shifting and canary releases
- Multi-strategy deployment orchestration
๐ Network Extension (kotoba-deploy-network)
- CDN Integration: Cloudflare, AWS CloudFront, Fastly, Akamai
- Security Features: Rate limiting, WAF, DDoS protection
- SSL/TLS Management: Auto-renewal and custom certificate support
- Edge Optimization: Image optimization, compression, caching
- Geographic Routing: Intelligent edge location selection
- Performance Monitoring: Real-time metrics and analytics
๐ Upcoming Extensions
๐ Scaling Extension (kotoba-deploy-scaling)
- AI-powered traffic prediction using machine learning
- Cost optimization with intelligent resource allocation
- Advanced performance monitoring and metrics collection
- Dynamic auto-scaling based on multiple factors
- Intelligent load balancing and distribution
๐ Architecture Overview
Process Network Graph Model
Kotoba implements a Process Network Graph Model where all components are centrally managed through dag.jsonnet. This ensures topological consistency and proper dependency resolution.
Key Benefits:
- Topological Sort: Build order verification
- Reverse Topological Sort: Problem resolution order
- Dependency Analysis: Automatic impact assessment
- Consistency Validation: DAG structure verification
Usage Examples:
# Check build dependencies
# Validate DAG structure
# Get deployment extension status
Kotoba - Exploring the world of graphs through words, now with advanced deployment capabilities