Complete File Listing for a Minimal Axum Project
A full view of every file in a new Axum project after adding dependencies and writing the hello world server
By this point you have created a new Rust project, added the Axum web framework and its supporting crates, and written a small web server that responds with "Hello, World!" when you visit the root URL. Each step built on the last, and now it is time to look at the complete picture. This page shows the exact files that should exist in your project directory, what each file contains, and how they all fit together.
You do not need to re‑learn what each line does here. Instead, treat this page as a final check: a single place where you can see the entire project at once and confirm that everything you have built so far is correct and ready to run.
The Project Directory Structure
When you open your project folder in a file manager or run ls -la in the terminal, you should see a layout similar to this. The exact order and extra files like Cargo.lock and target/ may vary slightly depending on whether you have already built the project.
my-axum-app
├── Cargo.toml
├── Cargo.lock
├── .gitignore
└── src
└── main.rs
Each item has a clear purpose:
Cargo.toml- the manifest file that tells Cargo what your project is, what dependencies it needs, and which features of those dependencies to enable.Cargo.lock- an automatically generated file that records the exact versions of every crate your project uses. You should not edit this file by hand..gitignore- a file that tells Git which files and folders to ignore when you make commits. It usually includes thetarget/directory and sensitive environment files.src/main.rs- the main entry point of your Rust program. This is where the Axum server is created and started.
The target/ directory is not listed here because it is generated when you run cargo build or cargo run. It contains compiled artifacts and is not part of your source code.
Why the complete listing matters:
Seeing every file together helps you understand that a Rust project is more than just the code you write. The manifest, the lock file, and the source file each play a different role. When something goes wrong later, you will know which file to look at.
Complete File Contents
Below are the complete contents of the three source‑control‑relevant files. The Cargo.lock file is intentionally left out because it is machine‑generated and changes every time you add or update a dependency.
The code shown here is the complete project as built so far. Read the three files in order: the manifest first, then the server code, then the ignore file.
Cargo.toml
[package]
name = "my-axum-app"
version = "0.1.0"
edition = "2024"
[dependencies]
axum = { version = "0.8", features = ["macros", "multipart", "ws", "json", "query", "form"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tower = { version = "0.5", features = ["util"] }
This is the manifest: the project name, the edition, and every dependency with the features the project needs.
src/main.rs
use axum::{
routing::get,
Router,
};
#[tokio::main]
async fn main() {
// Build the application router with a single route
let app = Router::new()
.route("/", get(hello_world));
// Bind to localhost on port 3000
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await
.unwrap();
println!("Server running at http://127.0.0.1:3000");
// Start serving requests
axum::serve(listener, app).await.unwrap();
}
// Handler function for the root route
async fn hello_world() -> &'static str {
"Hello, World!"
}
This is the whole server: one route, one handler, one listener, and the serve call that runs it all.
.gitignore
/target
.env
This keeps the build output and any secret environment values out of version control.
This is the target state:
If your files look exactly like the ones above, your project is correctly assembled. You have all the pieces needed to run a minimal Axum web server.
Which exact versions will Cargo pick?:
The version requirements above are ranges, so Cargo resolves them to the latest compatible releases. At the time of writing those are axum 0.8.9 (released 14 April 2026), tokio 1.54.1 (released 21 October 2026), tower 0.5.3, serde 1.0.229, and serde_json 1.0.154. You can see the exact versions Cargo chose for your project in Cargo.lock after the first build.
How These Files Work Together
Understanding the relationships between the files is more useful than memorizing each line.
Cargo.toml is the project's shopping list. When you run cargo build or cargo run, Cargo reads this file, downloads the listed crates from crates.io, and makes them available to your code. Without the correct entries here, your main.rs cannot use Axum or Tokio.
src/main.rs is the brain of the operation. It imports the necessary parts of Axum and Tokio, builds a Router that knows which handler to call for the / path, creates a network listener, and starts the server. Everything you want your web server to do starts from this file.
.gitignore keeps your repository clean. The target/ folder can be huge and is regenerated every time you compile. Committing it to Git would waste space and cause noise in your version history. The .env file often holds secrets like database passwords, and ignoring it prevents those secrets from being accidentally shared.
One helpful mental model is to think of a Rust project like a recipe:
Cargo.tomlis the ingredient list.src/main.rsis the cooking instructions.Cargo.lockis a snapshot of exactly which brand and quantity of each ingredient you used, so the dish turns out the same every time..gitignoreis a note to your future self: "Don't photograph the dirty kitchen; only the final dish."
Two Common Ways to Arrive at This Listing
You may have created these files by hand or used cargo add to append dependencies to Cargo.toml. Both approaches end in the same final listing. Understanding both can help you read other people's projects.
Approach A: Manual Editing
- Run
cargo new my-axum-appandcd my-axum-app. - Open
Cargo.tomlin a text editor and add the[dependencies]section exactly as shown above. - Replace the contents of
src/main.rswith the Axum server code. - Check that
.gitignorecontains the lines shown -cargo newalready creates it with/target; add the.envline if it is not there.
This approach gives you full control and helps you learn what each line does, but it is easy to make a typo.
Approach B: Using cargo add
- Run
cargo new my-axum-appandcd my-axum-app. - Run the following commands one by one:
cargo add axum@0.8 --features macros,multipart,ws,json,query,form
cargo add tokio@1 --features full
cargo add serde@1 --features derive
cargo add serde_json@1
cargo add tower@0.5 --features util
- Replace the default
src/main.rswith the Axum code. - Check
.gitignoreas in step 4 of Approach A.
Using cargo add automatically updates Cargo.toml with the correct syntax and version numbers. It also updates Cargo.lock immediately.
Which approach is better?:
For learning, manual editing forces you to see the exact format of Cargo.toml. For everyday work, cargo add is faster and less error‑prone. Both produce the same final file listing.
Common Mistakes and How to Spot Them
Even with a complete listing in front of you, small errors can slip in. The following points highlight mistakes beginners often make at this stage.
Missing the tokio full feature
If you declare tokio without the full feature (and without the individual features your code needs), your code will not compile at all. The compiler reports the missing pieces directly: without the net feature, tokio::net::TcpListener does not exist (cannot find 'TcpListener' in 'net'), and without macros or rt-multi-thread, the #[tokio::main] macro cannot be used.
Critical issue:
Without features = ["full"], the tokio crate does not include the networking and runtime modules that Axum relies on. Always keep the full feature enabled for a typical Axum project. If you prefer a minimal feature list instead, you need at least macros, rt-multi-thread, and net for the code on this page - anything less is a compile error, not a runtime surprise.
Using an outdated Axum version
Axum 0.7 and earlier used :param for path parameters, while Axum 0.8 uses {param}. For this minimal hello world example there are no path parameters, but if you copy code from older tutorials you may see incompatible syntax.
Version mismatches cause confusion:
The axum = "0.8" requirement in this project means you must use Axum 0.8 APIs. If you see route("/:id", ...) in a tutorial, that is for Axum 0.7 or earlier. Always check the version of the crate you are using.
Forgetting to replace the default main.rs
When you run cargo new, Rust creates a src/main.rs that prints "Hello, world!" to the console. If you leave that file untouched and only modify Cargo.toml, your project will not start a web server. Always open src/main.rs and replace its entire content with the Axum code.
Incorrect file paths
The main source file must be located at src/main.rs. If you place it in the project root as main.rs, Cargo will not find it and will report an error like no targets specified in the manifest - either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present. Stick to the standard structure.
Standard layout is required:
Rust projects created with cargo new use a src folder for all source code. Do not move main.rs out of that folder.
Verifying Your Complete Listing
Now that you can see all the files, you should verify that your project is in a healthy state. The following steps are a logical order because each check builds on the previous one.
Step 1: Check Cargo.toml
Open Cargo.toml and confirm that the [dependencies] section contains axum, tokio, serde, serde_json, and tower with the exact features shown above. A missing features array or a typo in a crate name will cause cargo build to fail.
Step 2: Check src/main.rs
Open src/main.rs and make sure it starts with use axum::{ routing::get, Router };, includes the #[tokio::main] attribute, defines an async fn main, builds a Router, binds a listener, and calls axum::serve. The handler function hello_world must return &'static str.
Step 3: Check .gitignore
Confirm that .gitignore exists and contains at least /target and .env. If it is missing, Git will try to track the huge target/ folder and any future .env files, which is messy and potentially insecure.
Step 4: Run cargo check
In your terminal, inside the my-axum-app directory, run:
cargo check
This command compiles your project without running it and without producing a final executable. It is a fast way to catch syntax errors, missing dependencies, and type mismatches. If you see a Finished line mentioning the dev profile with no errors, your complete listing is valid.
All checks passed?:
If cargo check finishes without errors, your project is exactly where it should be. You are ready to move on to running the server and seeing the web page respond with "Hello, World!"
Annotated Complete Listing for Deeper Understanding
Sometimes seeing comments directly in the code helps connect the dots. The following annotated version of src/main.rs explains the purpose of each section in plain English, without re‑teaching Rust or Axum syntax. Compare it with the clean version above to solidify your mental model.
// Import the parts of Axum we need
use axum::{
routing::get, // the `get` function registers a GET route
Router, // the `Router` type groups routes together
};
// Tell the Rust compiler that the `main` function is async and
// that Tokio should provide the async runtime.
#[tokio::main]
async fn main() {
// Create a new Router. A Router is like a map that says:
// "When a request comes in for this path, call this handler."
let app = Router::new()
// Register the root path "/" with the HTTP GET method.
// The handler `hello_world` will be called.
.route("/", get(hello_world));
// Create a TCP listener. This is the socket that waits for
// incoming network connections on the given address.
// We use `127.0.0.1` to listen only on the local machine.
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await // wait for the bind to complete (it's async)
.unwrap(); // if binding fails, panic and stop the program
// Print a helpful message so we know the server is ready.
println!("Server running at http://127.0.0.1:3000");
// Start the server. `serve` takes the listener and the app,
// and runs forever, handling incoming requests.
axum::serve(listener, app).await.unwrap();
}
// This is the handler function. It runs when someone visits "/".
// It returns a static string, which Axum converts into an HTTP response.
async fn hello_world() -> &'static str {
"Hello, World!"
}
The comments above are not required to make the server work. They are here to help you read the code like a story: import tools, build the route map, open the door, wait for visitors, and say hello.
The Complete Listing as a Mental Checkpoint
By now you have looked at the entire project from top to bottom. You have seen the manifest that declares dependencies, the main source file that defines the server, and the ignore file that keeps your repository clean. You have also learned two ways to assemble these files and how to verify that everything is correct.
The most important insight from this page is that a runnable Axum project is not a single file or even a single concept. It is a small system of files that each play a distinct role. When you later add more routes, extractors, state, or middleware, you will continue to work within this same structure. The Cargo.toml will grow new dependencies, main.rs will get longer, and new modules may appear, but the fundamental layout you see here will remain the backbone of every Axum application you build.
If you have been following along and your files match the listing above, take a moment to appreciate that you have just assembled a complete, working web server in Rust. The next logical step is to run it and see the "Hello, World!" response in your browser or terminal.