An opinionated full-stack web app template with a Rust/Axum backend and a SvelteKit frontend
- Rust 68.9%
- TypeScript 13.2%
- Nix 9.1%
- HTML 3.3%
- Svelte 3.1%
- Other 2.4%
Rust + Svelte Template
An opinionated full-stack web application template with a Rust/Axum backend and a SvelteKit frontend, which compiles to a single binary.
Stack
- Backend: Rust, Axum, Tokio, Tracing
- Frontend: SvelteKit, Svelte 5 (SPA)
- Type definitions generation: ts-rs
- Assets embedding: rust-embed
Development
# Enter the nix devShell
nix develop
# Or with direnv
direnv allow
# (Re-)generate the TypeScript bindings
cargo test export_bindings
# Start the backend (http://localhost:3000)
cargo run
# Start the frontend dev server (http://localhost:5173)
pnpm dev
The frontend dev server proxies /api requests to the Rust backend, so both servers must be running during development.
Build
# (Re-)generate the TypeScript bindings
cargo test export_bindings
# Build the release binary
cargo build -r
The SvelteKit project is automatically built when compiling the rust binary, so it's not necessary to run pnpm build
manually.
Project structure
.
├── src/
│ ├── main.rs # Axum router setup, AppJson extractor
│ ├── error.rs # AppError type, IntoResponse impl, logging middleware
│ ├── types.rs # Shared types (exported to TypeScript)
│ └── handlers/
│ ├── health.rs # GET /api/health
│ └── assets.rs # Static asset fallback handler
├── src-app/
│ ├── routes/ # SvelteKit pages
│ └── lib/
│ └── bindings/ # Auto-generated TypeScript types (do not edit)
├── build.rs # Builds the frontend as part of cargo build
├── package.json
└── Cargo.toml