svelte-axum-template

Starting project template for Rust, Axum, Sqlite backend and Svelte frontend. Simple Single-Page-App (SPA) example. Does not use SvelteKit.

Work in progress (new features coming), but should be usable as a starting point.

Cloning the template

Using Cargo

  • Must have cargo generate installed: cargo install cargo-generate
  • Then use cargo generate AndreiBozantan/svelte-axum-project -n <your-project-name>

Using git template

  • you can also just hit the "use this template" button in green on top of the repo
  • if you have gh cli installed check out --template option

Running the project

  • Install the following:

  • Change current directory in the project folder:

    • cd <your-project-name> - to go to the project root folder.
  • Run in dev mode with

    • npm run dev.

This will start the backend and frontend in dev mode with hot reloading and will also open the browser. By default, the backend will be available at http://localhost:3000 and the frontend at http://localhost:5173.

In dev mode, the vite config is set to proxy the backend requests to the backend server.

Build the release version

Execute npm run build in the project root folder, to build the frontend and backend in release mode.

The npm script will build the frontend before the backend, as the static files are embedded in the backend binary.

Back end - Rust Axum

  • located in ./back_end
  • serves front end directory
  • middleware for checking authorization header
  • middleware for checking session that user exists
  • store example that holds token secret for authorization
  • /api route example using authorization header
  • /secure route example using sessions for authorization

Run cargo run from inside the ./back_end folder to start the backend server.

Front end - Svelte

  • Located in ./front_end
  • navbar with login and logout
  • secure page that shows session information once logged in
  • api fetch example, log in not required

Run npm run dev from inside the ./front_end directory to start serving the frontend.

Version History

Version 0.7.2

  • update frontend to use Svelte 5
  • use npm scripts for the build process
  • add support for running the app in dev mode, with hot reloading

Version 0.7.1

  • load config from toml files and env variables, see pr#6
  • some cleanup of the backend code

Version 0.7

  • update to use Rust edition 2024, see pr#3

Version 0.6

  • add sqlite database example with sqlx, see pr#2

Version 0.5

  • embedding static files into the binary using cargo-embed-file see pr#1
  • updated to axum 0.8.4

Top categories

svelte logo

Need a Svelte website built?

Hire a professional Svelte developer today.
Loading Svelte Themes