Rust with Axum project structure

Rust with Axum project structure

Explorer

  • .git…
  • .gitignore
  • Cargo.toml
  • Cargo.lock
  • target…, not committed
  • README.md
  • rust-toolchain.toml
  • src
  • main.rs
  • lib.rsnew
  • app.rsnew
  • config.rsnew
  • state.rsnew
  • error.rsnew
  • telemetry.rsnew
  • migrationsnew
  • 20261007100000_create_users.sqlnew
  • 20261007100500_create_orders.sqlnew
  • .sqlx…new
  • confignew
  • base.tomlnew
  • local.tomlnew
  • .envnew, not committed
  • .env.examplenew
  • compose.yamlnew
  • rustfmt.tomlnew
  • clippy.tomlnew
  • .vscodenew
  • settings.jsonnew
  • extensions.jsonnew
  • .cargonew
  • config.tomlnew
  • justfilenew
  • testsnew
  1. # Create the binary crate (also runs git init)

    cargo new orders-api && cd orders-api
  2. # Add the web stack

    cargo add axum tokio --features tokio/full && cargo add tower tower-http --features tower-http/trace,tower-http/timeout,tower-http/request-id,tower-http/cors
  3. # Add the database layer and the SQLx CLI

    cargo add sqlx --features runtime-tokio,tls-rustls,postgres,macros,migrate,uuid,chrono && cargo install sqlx-cli --no-default-features --features postgres,rustls
  4. # Add serde, errors, config and logging

    cargo add serde --features derive && cargo add serde_json thiserror anyhow config secrecy tracing && cargo add tracing-subscriber --features env-filter,json
  5. # Add test tools

    cargo add --dev axum-test && cargo install cargo-nextest
  6. # Start PostgreSQL, create the database and run migrations

    docker compose up -d db && sqlx database create && sqlx migrate run
  7. # Run the server

    cargo run