axum-base
v0.0.1Basic Axum starter file archiecture recipe
xnex install axum-base GitHub repo ๐ฆ Axum Base Recipe
A pluggable, highly modular starter architecture for building decoupled and scalable APIs with Rust and Axum.
This recipe establishes a clear feature-driven isolation pattern, allowing developers to drop in or remove standalone modules effortlessly without breaking the application core.
๐ Architecture Overview
Every feature (e.g., health, auth, users) lives inside its own isolated folder under src/modules/. Modules expose only their unified router to the central router system.
src/
โโโ main.rs # Application entry point (Server boot & listener)
โโโ lib.rs # Crate root exporting core routing and modules
โโโ routes.rs # Central router hub (Where modules are mounted via .nest())
โโโ modules/
โโโ mod.rs # Module registry (Enables/disables standalone modules)
โโโ health/ # Example of an isolated feature module
โโโ mod.rs # Entry point exposing the feature's router
โโโ routes.rs # Feature-specific handlers and endpoints
๐ Key Design Philosophies
- Strict Isolation: Modules do not cross-contaminate. Code inside
modules/health/knows nothing about external modules. - Plug & Play (
Router::nest): To attach or detach a feature, you only add or remove a single line insrc/routes.rs. - Crate-Ready: The architecture separates binary logic (
main.rs) from library logic (lib.rs), making it trivial to extract features into standalone open-source crates later.
๐ ๏ธ Quick Start
1. Installation & Recipe Setup
The setup lifecycle automatically handles configuration and pulls the essential asynchronous and serialization primitives:
cargo add axum
cargo add tokio --features full
cargo add serde --features derive
2. Booting the Server
Run the application locally:
cargo run
Once booted, the application mounts your decoupled modules under the specified path prefixes:
- Health Check Endpoint:
GET [http://127.0.0.1:3000/api/health](http://127.0.0.1:3000/api/health)
๐ How to Add a New Feature Module
To expand your API with a new module (e.g., a users module) without causing architectural drift, follow these three steps:
- Create the Folder Structure:
Create
src/modules/users/mod.rsand write your handlers/routes inside it, exposing a singlepub fn router() -> Routerfunction. - Register the Module:
Open
src/modules/mod.rsand register your new folder:
pub mod health;
pub mod users; // <-- Add this
- Mount the Route Hub:
Inject the standalone router into the gateway tree in
src/routes.rs:
pub fn create_router() -> Router {
Router::new()
.nest("/api/health", modules::health::router())
.nest("/api/users", modules::users::router()) // <-- Mount here
}
Versions
Release links are tracked by Nex; source code lives in the developer's GitHub repo.
setup.files
Files that will be integrated into your project
- recipes
- axum-base
- README.md โ recipes/axum-base
-
-
- src
- modules
- health
- mod.rs โ src/modules/health
- routes.rs โ src/modules/health
-
- mod.rs โ src/modules
-
- lib.rs โ src
- main.rs โ src
- routes.rs โ src
-
- Cargo.toml โ .
setup.scripts
Commands executed during recipe integration
These commands run automatically during integration โ after your explicit approval via the Nex CLI.
- 1 Auto-run script
cargo add axum tokio -F tokio/full serde -F serde/derive - 2 Auto-run script
cargo build
nexconfig
Full recipe configuration
{
"name": "axum-base",
"version": "0.0.1",
"description": "Basic Axum starter file archiecture recipe",
"keywords": [
"rust",
"axum",
"nex",
"recipe",
"backend",
"api"
],
"files": [
"src",
"Cargo.toml",
"recipes/axum-base/README.md"
],
"setup": {
"scripts": [
"cargo add axum tokio -F tokio/full serde -F serde/derive",
"cargo build"
],
"files": {
"src": {
"lib.rs": "src",
"main.rs": "src",
"modules": {
"health": {
"mod.rs": "src/modules/health",
"routes.rs": "src/modules/health"
},
"mod.rs": "src/modules"
},
"routes.rs": "src"
},
"Cargo.toml": ".",
"recipes/axum-base/README.md": "recipes/axum-base"
}
}
}
You might also be interested in these
axum-log
Basic log middleware for axum api application.
nestjs
NESTJS EMPTY TEMPLATE
spring-logger
Basic logger middleware recipe
nestjs-basic-auth
NESTJS BASIC AUTH RECIPE
nestjs-logging
NESTJS REQUEST LOGGING MIDDLEWARE RECIPE