| Crates.io | kotoba-kotobas |
| lib.rs | kotoba-kotobas |
| version | 0.1.22 |
| created_at | 2025-09-17 13:45:39.703106+00 |
| updated_at | 2025-09-19 18:57:47.877371+00 |
| description | KotobaScript - Declarative programming language for frontend applications, extending Jsonnet with React component definitions |
| homepage | |
| repository | https://github.com/com-junkawasaki/kotoba |
| max_upload_size | |
| id | 1843338 |
| size | 393,079 |
KotobaScript - Declarative programming language for frontend applications, extending Jsonnet with React component definitions.
KotobaScript is a declarative programming language that extends Jsonnet to enable frontend application development without writing Rust code. It provides a unified approach to defining React components, pages, state management, and API integrations using familiar Jsonnet syntax.
KotobaScript (.kotobas) โ kotoba-jsonnet โ kotoba-kotobas โ React Components
โ โ โ โ
Declarative Syntax AST Evaluation Component Parsing TSX Generation
& React Extensions & Validation & Validation & TypeScript
http_parser.rs)// Declarative HTTP API definitions
pub struct HttpParser;
impl HttpParser {
pub fn parse_request(&self, jsonnet: &str) -> Result<HttpRequest>;
pub fn parse_response(&self, jsonnet: &str) -> Result<HttpResponse>;
pub fn parse_route(&self, jsonnet: &str) -> Result<RouteConfig>;
}
frontend.rs)// Component-based UI definitions
pub struct FrontendParser;
impl FrontendParser {
pub fn parse_component(&self, jsonnet: &str) -> Result<ComponentDefinition>;
pub fn parse_page(&self, jsonnet: &str) -> Result<PageDefinition>;
pub fn parse_layout(&self, jsonnet: &str) -> Result<LayoutDefinition>;
}
deploy.rs)// Infrastructure-as-Code definitions
pub struct DeployParser;
impl DeployParser {
pub fn parse_service(&self, jsonnet: &str) -> Result<ServiceDefinition>;
pub fn parse_topology(&self, jsonnet: &str) -> Result<TopologyDefinition>;
pub fn parse_policy(&self, jsonnet: &str) -> Result<PolicyDefinition>;
}
config.rs)// Application configuration definitions
pub struct ConfigParser;
impl ConfigParser {
pub fn parse_app_config(&self, jsonnet: &str) -> Result<ApplicationConfig>;
pub fn parse_env_config(&self, jsonnet: &str) -> Result<EnvironmentConfig>;
pub fn parse_feature_flags(&self, jsonnet: &str) -> Result<FeatureFlags>;
}
| Metric | Status |
|---|---|
| Compilation | โ Clean (with Jsonnet dependencies) |
| Tests | โ Comprehensive Jsonnet extension tests (874 tests) |
| Documentation | โ Complete API docs |
| Performance | โ Fast Jsonnet evaluation |
| Extensibility | โ Domain-specific Jsonnet extensions |
| Integration | โ Full ecosystem compatibility |
use kotoba_kotobanet::http_parser::HttpParser;
// Define HTTP APIs declaratively
let http_config = r#"
{
routes: [
{
path: "/api/users",
method: "GET",
handler: "getUsers",
middleware: ["auth", "rate_limit"],
authRequired: true,
parameters: {
page: { type: "integer", default: 1 },
limit: { type: "integer", default: 10, max: 100 }
}
},
{
path: "/api/users",
method: "POST",
handler: "createUser",
middleware: ["auth", "validation"],
requestBody: {
type: "object",
properties: {
name: { type: "string", minLength: 1 },
email: { type: "string", format: "email" }
}
}
}
],
middleware: {
auth: {
type: "jwt",
secret: "your-jwt-secret"
},
rate_limit: {
type: "token_bucket",
capacity: 100,
refill_rate: 10
}
}
}
"#;
let parser = HttpParser::new();
let routes = parser.parse_routes(http_config)?;
use kotoba_kotobanet::frontend::FrontendParser;
// Define React components in Jsonnet
let component_config = r#"
{
name: "UserDashboard",
props: {
userId: { type: "string", required: true },
theme: { type: "string", default: "light" }
},
state: {
user: null,
loading: false,
error: null
},
lifecycle: {
componentDidMount: "fetchUserData()",
componentDidUpdate: "handlePropsChange()"
},
render: {
type: "div",
className: "dashboard",
children: [
{
condition: "!state.loading",
type: "UserProfile",
props: { user: state.user, theme: props.theme }
},
{
condition: "state.loading",
type: "Spinner",
props: { size: "large" }
}
]
},
handlers: {
onRefresh: "fetchUserData()",
onThemeChange: "updateTheme(newTheme)"
}
}
"#;
let parser = FrontendParser::new();
let component = parser.parse_component(component_config)?;
use kotoba_kotobanet::deploy::DeployParser;
// Define infrastructure as code
let deploy_config = r#"
{
name: "user-service",
version: "1.2.0",
environment: "production",
services: {
api: {
image: "myregistry.com/user-api:v1.2.0",
ports: [8080, 8443],
environment: {
DATABASE_URL: std.base64Decode(std.extVar("db_secret")),
REDIS_URL: "redis://redis-cluster:6379",
JWT_SECRET: std.extVar("jwt_secret")
},
resources: {
cpu: "1000m",
memory: "2Gi",
storage: "10Gi"
},
healthCheck: {
path: "/health",
interval: "30s",
timeout: "5s"
},
scaling: {
minReplicas: 3,
maxReplicas: 20,
targetCPUUtilization: 70
}
},
worker: {
image: "myregistry.com/user-worker:v1.2.0",
command: ["./worker", "--queue", "user-events"],
environment: {
QUEUE_URL: "amqp://rabbitmq:5672",
DATABASE_URL: std.base64Decode(std.extVar("db_secret"))
},
depends_on: ["rabbitmq", "postgres"]
}
},
networks: {
frontend: {
services: ["api", "web", "cdn"],
ingress: {
domain: "api.myapp.com",
tls: true,
certificate: "letsencrypt"
}
},
backend: {
services: ["api", "worker", "postgres", "redis", "rabbitmq"],
internal: true
}
},
policies: {
security: {
networkPolicy: "deny-all",
allowIngress: [
{ from: "web", to: "api", ports: [8080] },
{ from: "api", to: "worker", ports: [5672] }
]
},
backup: {
schedule: "0 2 * * *",
retention: "30d",
databases: ["postgres"]
}
}
}
"#;
let parser = DeployParser::new();
let topology = parser.parse_deployment(deploy_config)?;
use kotoba_kotobanet::config::ConfigParser;
// Centralized configuration management
let app_config = r#"
{
app: {
name: "UserManagementSystem",
version: "1.2.0",
environment: std.extVar("ENVIRONMENT"),
features: {
userRegistration: true,
emailVerification: true,
socialLogin: std.extVar("ENABLE_SOCIAL_LOGIN"),
analytics: false
}
},
database: {
primary: {
host: "postgres-primary",
port: 5432,
database: "usermgmt",
username: std.extVar("DB_USER"),
password: std.base64Decode(std.extVar("DB_PASSWORD")),
ssl: {
enabled: true,
mode: "require",
ca_cert: std.extVar("DB_CA_CERT")
},
pool: {
min_connections: 5,
max_connections: 50,
acquire_timeout: "30s",
idle_timeout: "10m"
}
},
replica: {
host: "postgres-replica",
port: 5432,
read_only: true
}
},
cache: {
redis: {
cluster: [
"redis-01:6379",
"redis-02:6379",
"redis-03:6379"
],
password: std.extVar("REDIS_PASSWORD"),
tls: true,
pool: {
max_connections: 20,
retry_on_failure: true
}
}
},
messaging: {
rabbitmq: {
url: std.format("amqp://%s:%s@rabbitmq:5672/",
std.extVar("RABBITMQ_USER"),
std.extVar("RABBITMQ_PASSWORD")),
vhost: "/usermgmt",
exchanges: {
user_events: {
type: "topic",
durable: true
}
},
queues: {
email_notifications: {
exchange: "user_events",
routing_key: "user.created",
durable: true
}
}
}
},
external_apis: {
email_service: {
base_url: "https://api.emailservice.com/v1",
api_key: std.extVar("EMAIL_API_KEY"),
timeout: "10s",
retry: {
attempts: 3,
backoff: "exponential"
}
},
payment_processor: {
base_url: "https://api.payment.com/v2",
api_key: std.extVar("PAYMENT_API_KEY"),
webhook_secret: std.extVar("PAYMENT_WEBHOOK_SECRET")
}
},
monitoring: {
metrics: {
enabled: true,
exporter: "prometheus",
endpoint: "/metrics"
},
tracing: {
enabled: true,
jaeger_endpoint: "http://jaeger:14268/api/traces",
sampling_rate: 0.1
},
logging: {
level: "info",
format: "json",
outputs: ["stdout", "file:/var/log/app.log"]
}
},
security: {
jwt: {
algorithm: "RS256",
public_key: std.extVar("JWT_PUBLIC_KEY"),
private_key: std.extVar("JWT_PRIVATE_KEY"),
expiration: "1h",
refresh_expiration: "24h"
},
cors: {
allowed_origins: [
"https://app.mycompany.com",
"https://admin.mycompany.com"
],
allowed_methods: ["GET", "POST", "PUT", "DELETE"],
allowed_headers: ["Authorization", "Content-Type"],
credentials: true
},
rate_limiting: {
enabled: true,
global_limit: "1000/minute",
endpoint_limits: {
"/api/auth/login": "5/minute",
"/api/users": "100/minute"
}
}
}
}
"#;
let parser = ConfigParser::new();
let config = parser.parse_application_config(app_config)?;
Kotoba Kotobanet serves as the configuration layer for:
| Crate | Purpose | Integration |
|---|---|---|
kotoba-jsonnet |
Required | Jsonnet evaluation engine |
kotoba-server |
Required | HTTP server configuration |
kotoba2tsx |
Required | Frontend component generation |
kotoba-core |
Required | Type system and validation |
kotoba-execution |
Optional | Query execution configuration |
kotoba-security |
Optional | Security policy configuration |
cargo test -p kotoba-kotobas
Test Coverage:
evaluate_kotoba()] - Evaluate Jsonnet with Kotoba extensionsevaluate_kotoba_to_json()] - Evaluate to JSON with extensionsHttpParser] - HTTP request/response parsingFrontendParser] - UI component definitionsDeployParser] - Infrastructure configurationConfigParser] - Application settingsHttpConfig] - HTTP API definitionsFrontendConfig] - UI component configurationsDeployConfig] - Infrastructure definitionsAppConfig] - Application settingsSee the main Kotoba repository for contribution guidelines.
Licensed under MIT OR Apache-2.0. See LICENSE for details.