| Crates.io | densha |
| lib.rs | densha |
| version | 0.1.5 |
| created_at | 2025-04-12 16:20:48.608703+00 |
| updated_at | 2025-09-17 16:05:45.741348+00 |
| description | Next.js-like web application framework built with Kotoba |
| homepage | https://github.com/jun784/densha |
| repository | https://github.com/jun784/densha |
| max_upload_size | |
| id | 1631062 |
| size | 393,025 |
A Next.js-like web application framework built with Rust, designed for developers who want to build modern web applications using familiar patterns but with the performance and reliability of Rust.
โจ File-based Routing - Create pages and API routes with simple file structure ๐จ Component-based Architecture - Write components in Kotoba syntax โก Fast Development - Hot reload and instant feedback ๐ง Full-stack Ready - Handle both frontend and backend in one place ๐ฆ Zero Configuration - Get started immediately with sensible defaults ๐ฅ๏ธ Tauri Integration - Build desktop applications with the same codebase
# Install Densha CLI
cargo install densha
# Create a new project
densha init my-app
# Start development server
cd my-app
densha dev --target service
# Or simply (service is default)
densha dev
# Install Tauri CLI
npm install -g @tauri-apps/cli
# Create a new project with Tauri integration
cargo install densha
densha init my-app
# Start desktop development
cd my-app
densha dev --target system
# Build for production
densha build --target system
cargo tauri build
my-app/
โโโ app/ # Page components (file-based routing)
โ โโโ page.kotoba # Home page (/)
โ โโโ layout.kotoba # Root layout component
โ โโโ globals.css # Global styles
โ โโโ about/
โ โโโ page.kotoba # About page (/about)
โโโ api/ # API routes (serverless functions)
โ โโโ hello/
โ โโโ route.kotoba # API endpoint (/api/hello)
โโโ public/ # Static files (served at /)
โ โโโ globals.css # Additional global styles
โโโ styles/ # Component-specific styles
โโโ densha.json # Project configuration
Create pages in the app/ directory using Kotoba DSL syntax:
// app/page.kotoba - Home page (DSL format)
{
"metadata": {
"title": "Home - My Densha App",
"description": "Welcome to my Densha application"
},
"template": {
"type": "div",
"className": "container mx-auto py-8",
"children": [
{
"type": "h1",
"className": "text-4xl font-bold mb-4",
"children": ["Welcome to Densha! ๐"]
},
{
"type": "p",
"className": "text-gray-600 mb-8",
"children": ["This is your first Densha application."]
}
]
},
"script": "console.log('Home page loaded!');"
}
Define serverless functions in the api/ directory using JavaScript export syntax:
// api/hello/route.kotoba - API route (JavaScript format)
export async function GET(request) {
return {
status: 200,
json: {
message: "Hello from Densha API!",
timestamp: new Date().toISOString()
}
};
}
export async function POST(request) {
const body = await request.json();
return {
status: 201,
json: {
message: "Data received!",
data: body
}
};
}
| File Path | Route | Example |
|---|---|---|
app/page.kotoba |
/ |
Home page |
app/about/page.kotoba |
/about |
About page |
app/blog/[slug]/page.kotoba |
/blog/:slug |
Dynamic route |
api/users/route.kotoba |
/api/users |
API endpoint |
Densha validates your .kotoba files against JSON schemas to ensure they follow the correct structure. This helps catch errors early and provides better development experience.
Densha automatically detects file type and applies appropriate validation:
app/ directory)kotoba-dsl.schema.jsonmetadata, template, script propertieskotoba-kotobas for JSON configuration parsingapi/ directory)kotoba-api.schema.jsonexport async function METHOD(request) syntaxSchema validation runs automatically during:
densha validateUse densha validate --strict in CI/CD pipelines to fail builds on validation errors.
Densha uses different parsers for different file types:
When the dsl-parser feature is enabled (default), page templates use advanced parsing:
kotoba-kotobaskotoba-dsl.schema.jsonAPI routes use JavaScript syntax validation:
export async function METHOD(request) formatstatus propertykotoba-api.schema.jsonDSL syntax example for templates:
metadata {
title "My Page"
layout "default"
}
template {
div class="container" {
h1 { "Welcome" }
p class="text" { "Hello World" }
}
}
To disable DSL parsers (fallback to basic validation):
cargo build --no-default-features --features web-server
.kotoba Jsonnet filesdensha validate command for manual validationdensha dev - Start development server (service target, default)densha dev --target service - Start web development serverdensha dev --target system - Start desktop development with Tauridensha build - Build for production (service target, default)densha build --target service - Build web applicationdensha build --target system - Build desktop applicationdensha start - Start production serverdensha export - Export to static files (service target, default)densha export --target service - Export web applicationdensha export --target system - Export desktop applicationdensha validate - Validate all .kotoba files against schemasdensha validate <path> - Validate specific files or directoriesdensha validate --strict - Exit with error code on validation failuresdensha init - Create a new projectDensha comes with several project templates:
default - Basic setup to get you startedblog - Blog functionality with dynamic routingapi - API-focused project with documentationfullstack - Complete application with pages and API routestauri - Desktop application template with Tauri integration# Create a blog project
densha init --template blog my-blog
# Create an API project
densha init --template api my-api
# Create a desktop application
densha init --template tauri my-desktop-app
Densha supports two main target platforms:
my-tauri-app/
โโโ src-tauri/ # Rust backend (Tauri application)
โ โโโ src/
โ โ โโโ main.rs # Tauri main application
โ โโโ tauri.conf.json # Tauri configuration
โโโ src/ # Frontend (HTML/CSS/JS)
โ โโโ index.html
โ โโโ styles.css
โ โโโ app.js
โโโ app/ # Densha pages
โโโ api/ # Densha API routes
โโโ public/ # Static assets
When using the system target, Tauri provides IPC (Inter-Process Communication) to connect your web frontend with the Rust backend:
// Frontend (JavaScript) - System Target
const { invoke } = window.__TAURI__.tauri;
const users = await invoke('get_users');
// Backend (Rust) - System Target
#[tauri::command]
async fn get_users() -> Result<Vec<User>, String> {
// Your implementation
Ok(users)
}
For service target, standard HTTP communication is used:
// Frontend (JavaScript) - Service Target
const response = await fetch('/api/users');
const users = await response.json();
// Backend (Rust) - Service Target
async fn handle_users_request() -> Result<Response, Error> {
// Standard HTTP handling
Ok(Json(users))
}
See the complete Tauri integration example in examples/tauri-integration/ for a working implementation including:
# Development mode with hot reload (recommended)
densha dev --target system
# Alternative: Direct Tauri commands
cargo tauri dev
# Build for production
densha build --target system
cargo tauri build
# Export for Tauri development
densha export --target system
# Build for specific platforms
cargo tauri build --target x86_64-apple-darwin # macOS
cargo tauri build --target x86_64-pc-windows-msvc # Windows
cargo tauri build --target x86_64-unknown-linux-gnu # Linux
# Development mode
densha dev --target service
# or simply
densha dev
# Production mode
densha build --target service
densha start
# Export to static files
densha export --target service
Densha is built on top of:
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Browser โโโโโบโ Hyper Server โโโโโบโ Densha Core โ
โ (HTTP/HTTPS) โ โ (HTTP/1.1) โ โ (Kotoba) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ WebView โโโโโบโ Tauri Runtime โโโโโบโ Densha Core โ
โ (HTML/CSS/JS) โ โ (IPC/Rust) โ โ (Kotoba) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
Check out the examples/ directory for comprehensive examples:
We welcome contributions! Please see our Contributing Guide for details.
Licensed under the MIT License (LICENSE).
Built with โค๏ธ using Rust