1 unstable release
new 0.1.0 | Apr 12, 2025 |
---|
#238 in WebAssembly
99 downloads per month
320KB
6.5K
SLoC
Densha
Next.js inspired Rust fullstack framework with file-based routing
Densha (電車, Japanese for "train") is a fullstack web framework for Rust that brings the developer experience of Next.js to the Rust ecosystem. It provides file-based routing, multiple rendering strategies (SSG, SSR, CSR), and a flexible adapter system for choosing your preferred tech stack.
Features
1. File-based Routing
Routes are automatically created based on your file structure:
// /pages/users/[id].rs gets mapped to /users/:id
#[page]
pub async fn user_page(Path(id): Path<String>) -> impl IntoResponse {
// Page component
}
// /api/users.rs gets mapped to /api/users
#[api]
pub async fn list_users() -> Json<Vec<User>> {
// API endpoint
}
2. Flexible Rendering
Choose your rendering strategy per page:
#[page(render = "static")] // SSG
pub fn about_page() -> impl IntoResponse {
// Static page generated at build time
}
#[page(render = "server")] // SSR
pub async fn dashboard_page(State(db): State<Database>) -> impl IntoResponse {
// Server-rendered page at request time
}
#[page(render = "client")] // CSR
pub fn client_page() -> impl IntoResponse {
// Client-side rendered page
}
3. Rust-optimized Developer Experience
// Start your app with a simple builder pattern
fn main() {
Densha::new()
.with_database() // Automatic database setup
.with_hot_reload() // Hot reloading during development
.with_api_docs() // Automatic API documentation
.start()
}
4. Tech Stack Flexibility
Mix and match your preferred technologies:
Densha::new()
.with_web_framework(WebFramework::Actix) // Or Axum, Rocket
.with_database(Database::SeaOrm) // Or Diesel, SQLx
.with_frontend(Frontend::Sycamore) // Or Yew, Dioxus
Installation
# Install the CLI tool
cargo install densha-cli
# Create a new project
densha new my-app
cd my-app
# Start development server
densha dev
Project Structure
my-app/
├── Cargo.toml
├── src/
│ ├── main.rs # App entry point
│ ├── pages/ # Page components
│ │ ├── index.rs # Home page (/)
│ │ ├── about.rs # About page (/about)
│ │ └── users/
│ │ ├── index.rs # Users list page (/users)
│ │ └── [id].rs # User detail page (/users/:id)
│ └── api/ # API endpoints
│ └── users.rs # Users API (/api/users)
└── public/ # Static assets
Documentation
For full documentation, visit docs.densha.rs.
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Dependencies
~29–46MB
~828K SLoC