webapp.rs: a single Rust crate that serves a Leptos frontend, Axum backend and Postgres login flow
A web application completely written in Rust. 🌍
At a glance
- What is it?
- webapp.rs by Sascha Grunert is a reference web application with registration, login and JWT sessions, all in one Rust crate. This piece covers how the pieces connect, the defaults that must change before deployment, and what the sample does not attempt.
- Who is it for?
- Use webapp.rs as a worked example of Leptos server functions, Axum and SQLx in one crate, or as a starting skeleton for a login-protected app. Do not ship it unchanged: JWT_SECRET defaults to change-me-in-production and the only features are registration, login and a health check.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 7 days ago.
- What is it written in?
- Mainly Rust, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- saschagrunert/webapp.rs2,254 ★ · +5
| Repository | 2026-10-08 | 2026-11-25 |
|---|---|---|
| saschagrunert/webapp.rs | 2.2k | 2.3k |
5 Stars in the last 48 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Leptos server functions replace the REST layer
webapp.rs sets out to write a complete web application, backend and frontend, within Rust. The README draws the flow as a Leptos frontend running as WebAssembly in the browser, talking by SSR and RPC to an Axum HTTP server, which reaches PostgreSQL through SQLx.
The design choice that defines the project is the lack of a separate API. Leptos server functions carry calls between frontend and backend, so there is no hand-written REST layer to keep in sync. Server and client are compiled from a single Rust crate. Cargo.toml reflects this: the package is named webapp, the library crate type is ["cdylib", "rlib"], and dependencies are marked optional and switched on by two features, ssr and hydrate.
The consequence is that a change to one function signature breaks both sides at compile time, which is the point of the exercise. The price is that you must learn the Leptos model before you can read any of the code.
Two feature flags split one crate into a server and a browser build
The hydrate feature pulls in leptos/hydrate, console_error_panic_hook, wasm-bindgen and web-sys. The ssr feature pulls in axum, tokio, leptos_axum, sqlx and the rest of the server stack. The Cargo.toml in the repository is cut off after the jsonwebtoken entry in ssr, so the full list is in the file.
The development commands show where the flag matters:
cargo fmt --check # Check formatting
cargo clippy --features ssr -- -D warnings # Lint server code
cargo test --features ssr # Run tests
cargo leptos build # Build for development
cargo leptos build --release # Build for productionNote that clippy and the tests run with --features ssr only. Nothing in the README lints or tests the hydrate build, so a break that exists only in the WebAssembly half would be caught by cargo leptos build, not by those first three commands.
The Cargo.toml declares edition = "2024" and the package version is 2.0.0.
Getting it running needs five tools before cargo leptos watch
The prerequisites are Rust stable, cargo-leptos, PostgreSQL, the wasm32-unknown-unknown target and wasm-bindgen-cli. The install lines are:
cargo install cargo-leptos
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cliThe database comes from a throwaway container:
docker run -d --name postgres \
-e POSTGRES_USER=webapp \
-e POSTGRES_PASSWORD=webapp \
-e POSTGRES_DB=webapp \
-p 5432:5432 \
postgres:17Then set the connection string and start the watcher:
export DATABASE_URL=postgres://webapp:webapp@localhost/webapp
cargo leptos watchThe app listens on http://127.0.0.1:3000. You register through the Register link on the login page and then log in. The repository has a migrations directory, and sqlx is built with the migrate feature, so the schema setup is part of the Rust side.
If you skip wasm-bindgen-cli or the wasm target, the browser half cannot build, and cargo leptos watch will fail before you see a page.
The default JWT secret is a placeholder you must replace
Three environment variables configure the server:
| Variable | Default | |---|---| | DATABASE_URL | postgres://localhost/webapp | | JWT_SECRET | change-me-in-production | | LEPTOS_SITE_ADDR | 127.0.0.1:3000 |
The JWT_SECRET default is the one that hurts. Anyone who knows it can sign tokens, and the container example in the README sets only DATABASE_URL, so a container started exactly as shown runs with change-me-in-production. Pass your own value with an extra -e JWT_SECRET=... flag.
The default DATABASE_URL has no user, password or port, which works against a local Postgres that accepts the current OS user. The Getting Started URL carries webapp as both user and password, matching the docker run command, so it is a development setup only.
LEPTOS_SITE_ADDR defaults to the loopback address. Bind to 0.0.0.0:3000 for anything reachable from outside, which the Dockerfile does with ENV LEPTOS_SITE_ADDR=0.0.0.0:3000.
Auth is Argon2 passwords, JWT sessions and an origin check
The feature list is short and specific: registration with Argon2 password hashing, login with username and password, JWT-based session management with automatic renewal, PostgreSQL session and user storage, and CSRF protection via origin validation. Dependencies match: argon2 0.6.0, jsonwebtoken 11.0.0 with the rust_crypto feature, and sqlx 0.8.6 with the postgres feature.
What the README does not describe matters for anyone planning a real product. There is no email verification, no password reset, no roles or permissions, and no rate limiting listed. Login is by username and password only. The list also does not say how long a token lives or how renewal is triggered, so read the source before you trust it.
The CSRF protection works by validating the request origin, not by issuing per-form tokens. That is a design statement from the README, and it means the check depends on the browser sending an origin header you can rely on.
The Dockerfile builds twice and ships a Debian slim image with curl
The container build is a four-stage Dockerfile. The chef stage starts from rust:latest, adds the wasm32-unknown-unknown target and installs cargo-chef and cargo-leptos. A planner stage runs cargo chef prepare to write recipe.json. The builder stage cooks dependencies twice, once with --features ssr and once with --target wasm32-unknown-unknown --features hydrate, then runs cargo leptos build --release.
The final stage is debian:bookworm-slim with ca-certificates and curl installed. It copies the webapp binary to /usr/local/bin/webapp and the target/site directory to /app/site, sets LEPTOS_SITE_ROOT=site, and exposes port 3000. The curl package exists for the health check:
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/healthz || exit 1Because the base is rust:latest rather than a pinned version, a rebuild months apart can pick up a different compiler. The cargo-chef layering keeps dependency compilation cached when only source changes. The run example uses host.docker.internal to reach a Postgres on the host.
Releases jump from v1.0.0 in 2019 to a rewrite at v2.0.0 in 2026
Two tags exist. v1.0.0 is dated 2019-07-05 and v2.0.0 is dated 2026-03-24. The current stack in the README (Leptos 0.8, Axum 0.8, Rust edition 2024) belongs to v2.0.0 and later, and the README links two blog posts from the earlier era, one titled A Web Application completely in Rust and a follow-up on lessons learned.
Because the project was rewritten across a gap of nearly seven years, advice in those posts may not match the current code. Treat the blog posts as background on the motivation and check the repository for the present architecture.
The last push was on 2026-10-22 and the repository is not archived. The contribution policy is one sentence: fork it and send a pull request. There is no contributing guide, no issue template mentioned and no roadmap. This is a personal example repository, and you should plan to own whatever you copy out of it.
Editorial conclusion
Use webapp.rs as a worked example of Leptos server functions, Axum and SQLx in one crate, or as a starting skeleton for a login-protected app. Do not ship it unchanged: JWT_SECRET defaults to change-me-in-production and the only features are registration, login and a health check. Before you build on it, run the Getting Started steps against a local Postgres and read the Dockerfile to see how much of the toolchain you inherit.
Frequently asked questions
What is the meaning of webapp in webapp.rs?
Here webapp is the Cargo package name and the project is described as a web application completely written in Rust. It covers backend and frontend in one crate.
How does a webapp like webapp.rs work?
A Leptos frontend compiled to WebAssembly talks to an Axum HTTP server through Leptos server functions, and the server reads and writes PostgreSQL through SQLx. Pages use server-side rendering with client-side hydration.
What are examples of webapps, and what does webapp.rs implement?
webapp.rs is one example: it offers user registration, login with username and password, JWT sessions with automatic renewal and a /healthz endpoint. It is a single binary deployment.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/saschagrunert-webapp-rs)Star history chart for your README
[](https://hysenlabs.com/projects/saschagrunert-webapp-rs)Was this useful?