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.
cargo install cargo-generate
cargo generate AndreiBozantan/svelte-axum-project -n <your-project-name>
--template
optionInstall the following:
Change current directory in the project folder:
cd <your-project-name>
- to go to the project root folder.Initialization - run once before starting in dev mode:
npm run dev:init
Run the project in dev mode, with hot reloading:
npm run dev
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.
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.
Optionally, you can execute npm run clean
before the build, to remove all previous build artifacts, including the node_modules folders, so that the build starts from a clean state.
After running the clean command, you have to run npm run dev:init
once, to reinitialize the project before running in dev mode.
./backend
Run cargo run
from inside the ./backend
folder to start the backend server.
The backend can be configured using TOML files in the ./backend/config
directory:
default.toml
- Default configurationdevelopment.toml
- Development-specific overridesproduction.toml
- Production configuration exampleBy default, the application automatically runs database migrations on startup. This can be controlled via the run_db_migrations_on_startup
setting:
[database]
url = "sqlite:db.sqlite"
max_connections = 5
run_db_migrations_on_startup = true # Set to false to disable automatic migrations
For Development: Keep run_db_migrations_on_startup = true
for convenience.
For Production: Set run_db_migrations_on_startup = false
and run migrations manually:
./your-app migrate run
This provides better control over database schema changes in production environments.
./frontend
Run npm run dev
from inside the ./frontend
directory to start serving the frontend.
sqlx
, see pr#2cargo-embed-file
see pr#1axum
0.8.4