Sefism is free for learners. We are here to help you grow, one step at a time.Join for free
Sefism.

Project structure · Backend

Rust with Axum project structure

Opens with credits

A REST API for an orders app in Rust, built on Axum, Tokio and SQLx with tower middleware. A thin main.rs starts a library crate split into routes, extractors, domain types, repositories and services, and SQL is checked against PostgreSQL at compile time. For students who know basic Rust and want to see how a real service is laid out, from cargo new to a workspace a team can maintain for years.

Curated by Tauseef FayyazAdvanced143 files and foldersRust 1.99 (edition 2024), Axum 0.8, Tokio 1.53Checked October 2026
Explore the filesPick any file to see what it is, why it exists and when you add it.

How it grows

Each stage opens the explorer there

  1. 1Day 1What the scaffold and your first hour give you9 files and folders
  2. 2GrowingWhat a real app with features and tests adds+68 files and folders
  3. ProductionWhat running it for real users adds+33 files and foldersOpens with credits
  4. ExpertWhat a team needs to keep it healthy for years+33 files and foldersOpens with credits

How it is organised

  • A thin binary over a library: `main.rs` only loads config and starts the server, everything else is in `lib.rs` modules, because integration tests can only import a library crate.
  • Handlers stay thin: extractors pull typed data out of the request, a service does the work, `AppError` turns failures into responses. Business rules never live in a handler.
  • Parse, do not validate: newtypes such as `Email` and `Money` can only be built through a checking constructor, so the rest of the code trusts its inputs.
  • Plain SQL, checked at compile time: SQLx macros verify every query against the real schema, and `.sqlx/` lets CI and Docker build without a database.
  • One error type per layer, joined with `?`: domain errors and `sqlx::Error` convert into `AppError`, which logs details and shows clients a safe message.
  • Shared state is cheap to clone and created once: the pool, config and HTTP client live in `AppState`; nothing per request is stored in memory that a second replica would not see.
  • Use tower middleware before writing your own: tracing, timeouts, request ids, CORS and compression already exist in tower-http.
  • Tests grow in layers: unit tests next to the code, `#[sqlx::test]` integration tests with a fresh database each, Hurl journeys against the built image, then snapshots, benchmarks and mutation tests for a team.
  • Boundaries become crates when they start to drift: the domain moves into its own workspace crate so the compiler, not code review, keeps web and database code out.

At the top of the project

Open one in the explorer for the full story

Learn more on Sefism

Roadmaps, cheat sheets and projects that go with Rust with Axum.

See 8 more
Checked against 19 official sources, October 2026. If something has changed, the docs win.Show sources

Picked from the other libraries by shared topics.

Work with me

Stuck on something specific?

Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.

  • 1:1 Mentorship
  • Fresh Graduate Mentorship
  • Career Guidance

Brand deals, promos and partnerships: tauseeffayyaz@gmail.com