densha 0.1.2

Next.js-like web application framework built with Kotoba
Documentation

Densha 🚀

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.

Features

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

Quick Start

# Install Densha CLI
cargo install densha

# Create a new project
densha init my-app

# Start development server
cd my-app
densha dev

Project Structure

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

Writing Pages

Create pages in the app/ directory using Kotoba syntax:

// app/page.kotoba - Home page
export default function Home() {
    return (
        <div className="container mx-auto py-8">
            <h1 className="text-4xl font-bold mb-4">
                Welcome to Densha! 🚀
            </h1>
            <p className="text-gray-600 mb-8">
                This is your first Densha application.
            </p>
        </div>
    );
}

Creating API Routes

Define serverless functions in the api/ directory:

// api/hello/route.kotoba
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-based Routing

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

Available Scripts

  • densha dev - Start development server with hot reload
  • densha build - Build application for production
  • densha start - Start production server
  • densha export - Export to static files
  • densha init - Create a new project

Templates

Densha comes with several project templates:

  • default - Basic setup to get you started
  • blog - Blog functionality with dynamic routing
  • api - API-focused project with documentation
  • fullstack - Complete application with pages and API routes
# Create a blog project
densha init --template blog my-blog

# Create an API project
densha init --template api my-api

Architecture

Densha is built on top of:

  • Hyper - Fast HTTP server
  • Tokio - Async runtime
  • Handlebars - Template rendering
  • Serde - Serialization
  • Tower - Middleware framework

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

Licensed under the MIT License (LICENSE).

Support


Built with ❤️ using Rust