Project Structure - Axum - Complete Documentation by ntxm.org

Thin main.rs

Learn why and how to keep your Axum main.rs entry point small and focused on server startup only.

lib.rs module in Axum projects

Learn what lib.rs is, why Axum projects use it, and how to move your application code from main.rs into a library module so main.rs becomes a thin startup file.

The pub fn app Function in Axum

Learn how to define the public app function that builds and returns your Axum Router from lib.rs, keeping your entry point clean and testable.

Router Return Type in Axum

Learn what the Router return type means in an Axum app function, how to annotate it correctly, and common mistakes to avoid.

main calls app

Learn how the Rust main function starts an Axum server by calling the app function and passing the Router to axum::serve.

Unchanged Behavior After Splitting the Entry Point

How to verify that splitting the entry point does not change application behavior.

cargo run regression

How to run and verify your Axum application after splitting the entry point, ensuring no behavior changed from the original single-file version.

Organizing Routes in Axum with the routes/ Directory

Learn how to structure and organize your Axum route definitions using a dedicated routes/ directory, including module splitting, merging routers, nesting prefixes, and common pitfalls.

The handlers/ Directory in Axum

Learn how to organize Axum handler functions into a dedicated handlers/ directory, including setup steps, multiple organization patterns, common mistakes, and sharing logic between handlers.

Models Directory in Axum Project Structure

Learn how to organize data structures in a dedicated models directory within an Axum project, including serde serialization, request and response models, and common pitfalls.

Creating the state.rs Placeholder in Axum Project Structure

Learn what application state is in Axum, why it needs its own file, and how to set up a state.rs placeholder as part of a conventional project layout.

error.rs placeholder

Learn why and how to create a placeholder error.rs file in a conventional Axum project structure, with multiple examples and beginner-friendly explanations.

Module Declarations in a Conventional Project Layout

How to connect your Axum project's source files using Rust mod declarations so the compiler can find and build every module

pub use re-exports

This page explains what pub use re-exports are in Rust, why you need them in an Axum project structure, and how to use them to create a clean public API for your crate.

Layer-based split in Axum

Learn how to organize a growing Axum application by separating code into layers such as routing, handlers, models, state, and errors, with complete examples and step-by-step guidance for beginners.

Feature-based split in Axum projects

Learn how to organize a growing Rust backend by feature modules, understand why grouping related code together reduces complexity, and build practical feature folders with complete examples.

Domain Folders in Axum Projects

Learn how to organize an Axum application by business domain using domain folders, a scaling convention that groups related features into dedicated modules for maintainable project structure.

Cargo Workspaces for Axum Projects

Learn how to organize an Axum application into multiple Rust crates using Cargo workspaces, and when this structure makes sense for larger projects.

When to Split an Axum App into Services

A beginner-friendly guide to deciding when a single Axum application should become multiple services, and how to structure that split.