Rust + htmx + tailwind + nix + redb + twind demo web app

Overview

htmx sorta

A demo project where I learn and play with my "Rust web stack":

  • Rust
  • Nix flakes for building and dev shell
  • redb Rust local key-value store database
  • astra Rust web server library
  • maud Rust html templating library
  • htmx for dynamic html frontend
  • tailwind via twind for CSS styling

In essence it's a TODO app, and looks like this (click for a video):

Video Preview

Note: server response slowness is simulated to help improve the UX. The imgur "optimized" the video and now it's slow and laggy, but I have no energy to fight with it right now. In reality things are working just fine.

Some of the features: persistent ordered list, with drag'n'drop UX, responsive html, graceful offline handling, rate limiting.

I think it might be source of inspiration and example for people that would like to use a similar set of tools for their own projects.

Running

If you're a Nix flake user you can run nix run github:dpc/htmx-sorta. Otherwise, proceed like with any other Rust project.

About the stack

I like things simple, small and to the point. Also - it's a bit of a research project, so I'm not afraid to try out things that are not most popular and trendy.

I'd like to avoid using async Rust, because it's immature and PITA to use, while blocking IO is perfectly sufficient. That's why I use astra, which is very promising blocking IO Rust web framework/library.

I don't want any C-binding based dependencies, and that's why I'm using redb, which is very promising and lean key value store, in a similar category as e.g. RocksDB.

I don't like DSL, especially looking like combination of Python and HTML, so maud is my favourite HTML framework. Again - fast, lean, to the point.

I'm tired of all the SPAs that are slow heavy and barely work. I'm more of a backend developer than a frontend developer. I think HTMX is the direction that Web should have taken long time ago, instead of betting everything on Javascript. I'm not afraid of adding JS to the code, but it shouldn't be for UX niceness and not the tail wagging the dog.

I'm not much of a designer or a web developer, but I've did some web projects over last two decades, and I wholeheartly agree with Tailwind philosophy. Unfortunately it doesn't have a great Rust/maud integration, so I use twind as a client-side Tailwind JIT instead.

Points of Interest

Check maud templates in fragment.rs, acting like web-components for both htmx and tailwind.

Route handlers are in routes.rs. They are a bit low level and manual but hopefully astra will get some more convenient approach (e.g. like Axum extractors) in the near future. The developer is working on it. Go say hello if you're interested.

The Nix dev shell I'm using sets up automatically some cool git hooks. I keep using it in many projects. It includes semgrep, typos (checking typos), convco (conventional commits), linters, and some Rust specific checks.

mold is used to speed up linking, with symbol compression enabled to make the binary smaller (6.3 MiB ATM).

I've "invented" a variable-length sorting key approach, that simplifies item sorting. It makes generating a key between two other keys a simple and infaliable operation.

I had an idea for compact and fast, but imprecise pre-rate-limiter that I think would be very fast. It uses a multi-hash approach with buckets of atomic counters, kind of like bloom/cuckoo filters, to effective take one atomic (relaxed) write on the happy path, and gracefully degrade under heavy load. Did not have time to benchmark it, so 🤷. Maybe it's stupid.

The rest is somewhat typical. As of the time of writing this there are some known missing things. It's just an demo/research, don't expect too much.

License

MIT. Feel free to copy, paste and use, no attribution expected.

You might also like...
Sincere is a micro web framework for Rust(stable) based on hyper and multithreading

The project is no longer maintained! Sincere Sincere is a micro web framework for Rust(stable) based on hyper and multithreading. Style like koa. The

Source Code for 'Practical Rust Web Projects' by Shing Lyu

Apress Source Code This repository accompanies Practical Rust Web Projects by Shing Lyu (Apress, 2021). Download the files as a zip using the green bu

A web application completely written in Rust. 🌍
A web application completely written in Rust. 🌍

WebApp.rs A web application completely written in Rust Target of this project is to write a complete web application including backend and frontend wi

Web Server made with Rust - for learning purposes

Web Server made with Rust - for learning purposes

Archibald is my attempt at learning Rust and writing a HTTP 1.1 web server.
Archibald is my attempt at learning Rust and writing a HTTP 1.1 web server.

Archibald To be a butler, is to be able to maintain an even-temper, at all times. One must have exceptional personal hygiene and look sharp and profes

Salvo is a powerful and simplest web server framework in Rust world
Salvo is a powerful and simplest web server framework in Rust world

Salvo is an extremely simple and powerful Rust web backend framework. Only basic Rust knowledge is required to develop backend services.

VRS is a simple, minimal, free and open source static web server written in Rust
VRS is a simple, minimal, free and open source static web server written in Rust

VRS is a simple, minimal, free and open source static web server written in Rust which uses absolutely no dependencies and revolves around Rust's std::net built-in utility.

Actix-web wrapper for garde, a Rust validation library.

Garde-actix-web   Actix-web wrapper for garde, a Rust validation library. Installation Usage example Feature flags About us Installation [dependencies

The light web framework for Rust.
The light web framework for Rust.

Rusty Web Rusty web is a simple to use, fully customizable lightweight web framework for rust developers. Learn rusty web Installation [dependencies]

Owner
Rustshop
Rustshop
Static Web Server - a very small and fast production-ready web server suitable to serve static web files or assets

Static Web Server (or SWS abbreviated) is a very small and fast production-ready web server suitable to serve static web files or assets.

Jose Quintana 496 Jan 2, 2023
A demo blog post engine in Rust, using Rocket and MongoDB

A demo blog post engine written in Rust, using Rocket and MongoDB Quick Start Setup a new MongoDB cluster https://cloud.mongodb.com/ create a new data

Nabil Hachicha 5 Oct 19, 2022
Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.

Actix Web Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust Features Supports HTTP/1.x and HTTP/2 Streaming and pipelining

Actix 16.3k Jan 8, 2023
JSON Web Token implementation in Rust.

Frank JWT Implementation of JSON Web Tokens in Rust. Algorithms and features supported HS256 HS384 HS512 RS256 RS384 RS512 ES256 ES384 ES512 Sign Veri

Alex Maslakov 246 Dec 27, 2022
An Extensible, Concurrent Web Framework for Rust

Iron Extensible, Concurrency Focused Web Development in Rust. Response Timer Example Note: This example works with the current iron code in this repos

null 6.1k Dec 27, 2022
An expressjs inspired web framework for Rust

nickel.rs nickel.rs is a simple and lightweight foundation for web applications written in Rust. Its API is inspired by the popular express framework

null 3k Jan 3, 2023
A web framework for Rust.

Rocket Rocket is an async web framework for Rust with a focus on usability, security, extensibility, and speed. #[macro_use] extern crate rocket; #[g

Sergio Benitez 19.5k Jan 8, 2023
A lightweight web framework built on hyper, implemented in Rust language.

Sapper Sapper, a lightweight web framework, written in Rust. Sapper focuses on ergonomic usage and rapid development. It can work with stable Rust. Sa

Daogang Tang 622 Oct 27, 2022
Web framework in Rust

Rouille, a Rust web micro-framework Rouille is a micro-web-framework library. It creates a listening socket and parses incoming HTTP requests from cli

Pierre Krieger 840 Jan 1, 2023
A fast, boilerplate free, web framework for Rust

Tower Web A web framework for Rust with a focus on removing boilerplate. API Documentation Tower Web is: Fast: Fully asynchronous, built on Tokio and

Carl Lerche 969 Dec 22, 2022