Rust + Axum + htmx + Askama (Server-Rendered Web App)
Server-rendered Rust web app rules: Axum 0.8, compile-time Askama templates, htmx partials, sqlx 0.9 + PostgreSQL, and a cargo check loop for AI agents.
- Formats
- 4 files
- AGENTS.md
- 57 lines
- CLAUDE.md
- 18 lines
- Languages
- Rust
- Updated
- Oct 2026
- Used by
- 4 projects
Writes .claude/skills/rust-axum-htmx-askama/SKILL.md
$ curl -s --create-dirs -o .claude/skills/rust-axum-htmx-askama/SKILL.md https://stackitfast.com/rules/rust-axum-htmx-askama/SKILL.mdRule files
Works with Claude Code · Cursor · Windsurf · AGY
Architecture notes
Architecture Overview
A server-rendered Rust web app: Axum handlers render Askama templates, htmx swaps HTML fragments for interactivity, and sqlx talks to PostgreSQL with queries checked at compile time. It is the Rust take on Rails + Hotwire or Laravel + Livewire, and of the four Rust web stacks on STACK IT FAST it has the fewest moving parts.
Why it suits AI coding agents
- Two compilers check the agent’s work. rustc checks the handlers, and Askama compiles templates into Rust, so a typo in
{{ user.emial }}failscargo checkinstead of a page view. - One rendering model. There is no client state, hydration or API contract to keep in sync, so agents change a handler and a template and are done.
- Matches what open source uses. Axum is the web framework in 13 of the 18 open-source Rust apps in the directory that use one. Kanidm renders its whole self-service UI with Axum, Askama (
askama_web) andaxum-htmx, and authentik pairs Axum with Askama in its Rust server.
When to pick something else
Choose Leptos full-stack when the UI needs rich client-side state, Loco when you want generators, mailers and workers out of the box, and Rust + Axum + PostgreSQL for a JSON API with a separate frontend. Background reading: Building web apps in Rust in 2026.
Frequently asked questions
Is Axum + htmx a good Rust alternative to Rails + Hotwire?
It is the closest match in spirit: the server renders HTML, htmx swaps fragments in place like Turbo Frames, and there is no client-side app to keep in sync. What you give up is Rails generators and conventions; this rule supplies the conventions (feature modules, template partials, one handler per page and fragment) so an AI agent applies them consistently.
Why Askama instead of Tera or MiniJinja?
Askama compiles templates into Rust at build time, so a missing field or a wrong type in a template is a compile error that cargo check reports, which is exactly the feedback loop coding agents need. Tera and MiniJinja load templates at runtime and only fail when the page is rendered.
How do I render only part of a page for htmx?
Use Askama block fragments: define the list inside a {% block list %} in the page template and add a second struct with #[template(path = "todos/index.html", block = "list")]. The handler checks the HX-Request header and renders the block for htmx requests and the full page otherwise.
Does this stack need Node.js?
No. Tailwind CSS ships a standalone CLI binary and htmx is a single script file you vendor into assets/. The whole app builds with cargo and deploys as one binary plus static assets.
Used in production
Explore all stacksRustFS
1RustFS splits a MinIO-style object store into dozens of single-purpose Rust crates behind one binary, keeps extra protocols behind cargo features, and moves inter-node traffic to gRPC, so storage, healing and IAM evolve separately.
Axum
Axum skips a custom middleware system and treats every route and layer as a Tower service, so it inherits timeouts, tracing, compression and auth from tower-http and shares middleware with Hyper and tonic code.
Leptos
Leptos separates its reactive graph, renderer and server-function RPC into independent crates and keeps the core server-agnostic, so the same components run as SSR HTML or WebAssembly, and Axum or Actix Web plug in through thin integration crates.
Dioxus
Dioxus keeps one virtual DOM and component model and swaps renderers per platform (WebAssembly, WebView, SSR, LiveView, native), while its own dx CLI handles hot-patching, asset bundling and packaging for every target.