| Crates.io | kotoba-server |
| lib.rs | kotoba-server |
| version | 0.1.21 |
| created_at | 2025-09-14 17:45:18.405508+00 |
| updated_at | 2025-09-19 16:25:47.329358+00 |
| description | Complete HTTP server and frontend integration system for Kotoba graph database |
| homepage | https://github.com/com-junkawasaki/kotoba |
| repository | https://github.com/com-junkawasaki/kotoba |
| max_upload_size | |
| id | 1839010 |
| size | 208,074 |
Complete HTTP server and frontend integration system for the Kotoba graph database. Provides RESTful APIs, GraphQL endpoints, real-time WebSocket connections, and automated React/TypeScript component generation.
Kotoba Server serves as the complete web interface for the Kotoba ecosystem, providing:
HTTP Request โ Middleware โ Routing โ Handler โ Response
โ โ โ โ โ
Security Logging Params GraphQL JSON
CORS Metrics Types REST HTML
Rate Tracing Guards Static Binary
Limit Auditing AuthZ
// Main server orchestrator
pub struct Server {
http_server: HttpServer,
websocket_server: Option<WebSocketServer>,
graphql_handler: GraphQLHandler,
static_file_server: StaticFileServer,
middleware_pipeline: MiddlewarePipeline,
}
http/graphql.rs)// Full GraphQL implementation with introspection
pub struct GraphQLHandler {
schema: GraphQLSchema,
execution_engine: QueryExecutor,
introspection_enabled: bool,
}
impl GraphQLHandler {
pub async fn execute_query(&self, query: &str, variables: &Value) -> Result<GraphQLResponse>;
pub fn build_schema(&self, graph: &GraphRef) -> GraphQLSchema;
}
Kotoba Config โ Parser โ IR โ Generator โ React Components
โ โ โ โ โ
.kotoba AST Build TSX JSX + Hooks
Jsonnet Types Tree Props State Mgmt
Schema Routes CSS Events Lifecycle
frontend/)// Intermediate representation for frontend components
pub enum FrontendIR {
Component(ComponentIR),
Route(RouteIR),
ApiCall(ApiIR),
Style(StyleIR),
Build(BuildIR),
}
| Metric | Status |
|---|---|
| Compilation | โ Clean (with HTTP dependencies) |
| Tests | โ Comprehensive server test suite |
| Documentation | โ Complete API docs |
| Performance | โ Async/await optimized |
| Security | โ Full middleware pipeline |
| Web Standards | โ HTTP/1.1, WebSocket, GraphQL |
use kotoba_server::{Server, ServerConfig};
use kotoba_graph::graph::GraphRef;
use kotoba_security::SecurityService;
// Configure server components
let server_config = ServerConfig {
http: HttpConfig {
port: 8080,
host: "127.0.0.1".to_string(),
tls_enabled: false,
..Default::default()
},
graphql: GraphQLConfig {
enabled: true,
introspection: true,
playground: true,
},
websocket: WebSocketConfig {
enabled: true,
heartbeat_interval: Duration::from_secs(30),
},
frontend: FrontendConfig {
enabled: true,
hot_reload: true,
build_optimization: true,
},
..Default::default()
};
// Initialize core services
let graph = GraphRef::new(Graph::empty());
let security = SecurityService::new(security_config).await?;
let execution = QueryExecutor::new();
// Create and start server
let server = Server::new(server_config, graph, security, execution).await?;
server.start().await?;
use kotoba_server::http::graphql::GraphQLHandler;
// Create GraphQL handler
let graphql = GraphQLHandler::new(execution_engine, graph_ref);
// Execute GraphQL query
let query = r#"
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
}
}
"#;
let variables = serde_json::json!({"id": "user123"});
let response = graphql.execute_query(query, &variables).await?;
println!("{}", response.data);
use kotoba_server::http::handlers::*;
// RESTful graph operations
#[post("/api/graph/vertices")]
async fn create_vertex(
req: HttpRequest,
vertex_data: Json<VertexData>,
graph: Data<GraphRef>,
) -> HttpResponse {
// Create vertex in graph
let vertex_id = graph.write().add_vertex(vertex_data.into_inner());
HttpResponse::Created()
.json(json!({ "vertex_id": vertex_id }))
}
use kotoba_server::http::websocket::WebSocketHandler;
// Handle real-time graph updates
let ws_handler = WebSocketHandler::new(graph_ref.clone());
ws_handler.on("graph.update", |socket, payload| async move {
// Broadcast graph changes to all connected clients
socket.broadcast("graph.updated", payload).await?;
Ok(())
});
use kotoba_server::frontend::{ComponentGenerator, KotobaParser};
// Parse Kotoba configuration
let parser = KotobaParser::new();
let config = parser.parse_file("app.kotoba").await?;
// Generate React components
let generator = ComponentGenerator::new();
let components = generator.generate_components(&config).await?;
// Generated components include:
// - React functional components
// - TypeScript interfaces
// - API client hooks
// - CSS-in-JS styles
Kotoba Server is the web interface for the complete ecosystem:
| Crate | Purpose | Integration |
|---|---|---|
kotoba-graph |
Required | Graph data backend and operations |
kotoba-execution |
Required | Query processing and execution |
kotoba-security |
Required | Authentication and authorization middleware |
kotoba-jsonnet |
Required | Configuration file processing |
kotoba2tsx |
Required | React component generation |
kotoba-storage |
Required | Data persistence layer |
cargo test -p kotoba-server
Test Coverage:
Server] - Main HTTP server orchestratorServerConfig] - Complete server configurationHttpServer] - HTTP/HTTPS request handlerWebSocketServer] - Real-time communication serverGraphQLHandler] - GraphQL query processorhandlers] - REST API endpoint implementationsmiddleware] - Request/response processing pipelinerouting] - URL routing and parameter extractionstatic_files] - Asset serving and optimizationComponentGenerator] - React component generationKotobaParser] - Configuration file parsingBuildSystem] - Development build pipelineHotReload] - Live development serverHttpConfig] - HTTP server settingsGraphQLConfig] - GraphQL endpoint configurationWebSocketConfig] - WebSocket connection settingsFrontendConfig] - Component generation optionsSee the main Kotoba repository for contribution guidelines.
Licensed under MIT OR Apache-2.0. See LICENSE for details.