anantbhandarkar/make-it-right/mir-backend-rust-axum
Claude Code and agent skill by anantbhandarkar/make-it-right
- community
Checking that the SKILL.md file is still in the repository.
Make It Right (Axum module). Axum 0.8 + Tower + async Rust specific reliability augmentation. Use alongside mir-backend and mir-backend-rust when the target stack is Axum — it carries the mechanical footguns that the framework-agnostic tiers deliberately omit: the 0.8 route syntax change (/:id now panics, use /{id}), extractor ordering (body-consuming extractors must be last), custom extractors after the #[async_trait] removal in axum-core 0.5, typed State<T> vs Extension<T> and the FromRef sub-state pattern, implementing IntoResponse for error types without leaking internals, DefaultBodyLimit, and Tower middleware layer ordering (outermost wraps first). TRIGGER only when the Rust backend framework is Axum — building, reviewing, or debugging an Axum handler, router, extractor, or Tower middleware. Always loads TOGETHER WITH mir-backend (the gates) and mir-backend-rust (Tokio runtime concerns: blocking, guard-across-await, cancellation safety, async traits, Arc/'static, backpressure, timeouts); this module only adds Axum/Tower library mechanics. SKIP for Actix-web — the App-factory worker trap, web::Data, web::block and ResponseError belong to mir-backend-rust-actix, not here. SKIP for Warp, Poem, or any non-Axum Rust stack, and for non-Rust runtimes.
Install
npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-rust-axumSKILL.md
The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-rust-axum.
/mir-backend-rust-axum · Make It Right (Axum)
Bottom tier of the chain: mir-backend (generic gates) → mir-backend-rust (Tokio runtime model) → this (Axum/Tower library mechanics). Run the gates first; load the Rust runtime tier for blocking/cancellation/Arc concerns; reach for this at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. Runtime-level concerns (blocking the Tokio runtime, guard-across-await, cancellation safety, bounded channels, timeouts) live in `mir-backend-rust` — not here.
Stack assumed: Axum · Tower middleware · async Rust on Tokio.
Versions verified 13 Aug 2026:
| Crate | Current | Note | |
|---|---|---|---|
axum | 0.8.9 (2026-04-14) | MSRV 1.80. 0.8.0 shipped 2025-01-01 | |
axum-core | 0.5.6 | where the #[async_trait] removal landed | |
tower | 0.5.3 | ||
tower-http | 0.7.0 (2026-06-15) | breaking changes from 0.6 — see §5 |
Axum 0.9 is not released. Work is on main with breaking changes queued, and the maintainers have stated there is no timeline. Target 0.8.x. If you are reading a tutorial that shows Router::new().route("/users/:id", ...), it predates 0.8 and will panic — see §1.
The Axum footguns AI walks into most
1. Route syntax changed in 0.8 — /:id panics, write /{id}
The single most common failure when AI writes Axum today. Axum 0.8 upgraded matchit to 0.8, which changed path parameter syntax. The old form was deliberately made a panic rather than silently changing behaviour, so this fails at startup — usually inside a test or on first boot, not at compile time.
| Axum 0.7 and earlier | Axum 0.8+ | |
|---|---|---|
/users/:id | /users/{id} | |
/assets/*path | /assets/{*path} |
The syntax now matches OpenAPI and format!(). Migration is a mechanical find-and-replace across every .route(...) and .nest(...) call. To escape a literal brace, double it: {{.
Because it panics rather than misroutes, the failure is loud — but a route registered only under a feature flag or in a rarely-built module will panic in production instead of in CI. Grep the whole tree for "/: and * route patterns when upgrading.
2. Extractor order — body-consuming extractors MUST be last
This is the #1 Axum compile/runtime trap. HTTP request bodies are streams: reading the body consumes it. Axum extractors that consume the body (Json<T>, String, Bytes, Form<T>, Multipart) must be the last parameter in the handler signature. Only one body-consuming extractor per handler is allowed — the request has one body.
Extractors that do NOT consume the body (they read headers, URI, path, query, or app state) can appear in any position: Path<T>, Query<T>, State<T>, Extension<T>, TypedHeader<T>, ConnectInfo<T>.
The rule is enforced by the type system, not at runtime: body-consuming extractors implement FromRequest, the rest implement FromRequestParts, and a handler may have at most one FromRequest in the final position. Getting it wrong is a compile error, but a famously unhelpful one — it surfaces as "the trait bound fn(...): Handler<_, _> is not satisfied", pointing at .route() rather than at the handler. Axum 0.8 improved these diagnostics; when they are still opaque, put #[debug_handler] on the handler and the error names the offending argument directly.
AI routinely puts State last (habit from other frameworks) and bumps Json to first or second — flag any handler where a body extractor is not the final argument.
Two 0.8 changes that break extractor code written for 0.7:
#[async_trait] was removed from FromRequest and FromRequestParts in axum-core 0.5 — Rust's native async fn in traits made it unnecessary. Custom extractors carrying the attribute no longer compile. Delete the attribute and the use axum::async_trait; import; leave the async fn signature alone.
Option<T> as an extractor changed meaning. In 0.7 any rejection from T was swallowed into None — including a malformed token or an unparseable body, which is how "optional auth" quietly became "no auth". In 0.8, Option<T> requires T: OptionalFromRequestParts (or OptionalFromRequest), so the extractor decides whether a failure means "absent" or "reject". If Option<T> stops compiling on upgrade, that is the point — the old code was discarding an error. Note Query does not have an OptionalFromRequestParts impl; use Query<SomeStructWithOptionFields> instead of Option<Query<T>>.
3. State<T> vs Extension<T> — prefer State, use FromRef for sub-states
Axum provides two mechanisms for injecting app-wide data into handlers:
- `State<T>` (via
.with_state(value)on the router): type-checked at compile time, zero-cost extraction, the idiomatic modern approach. Use this. - `Extension<T>` (via
.layer(Extension(value))): stored as a type-erased map in the request extensions and looked up at runtime. A missing extension does not panic and is not a compile error — it produces anExtensionRejection::MissingExtension, which is a plain 500 with the body "Missing request extension". That is quiet: it looks like an ordinary server error in your dashboards, so a layer you removed or reordered can break a route without anything naming the cause. UseExtensiononly for middleware-injected per-request data, never for app-wide state.
For large apps with multiple shared resources (DB pool, config, cache), define a single AppState struct and implement FromRef<AppState> for each sub-state so individual handlers can extract only what they need:
AppState must implement Clone (cheaply — wrap expensive resources in Arc or use pool handles that are already Clone).
4. Error handling — implement IntoResponse, never unwrap in handlers
Handlers return Result<impl IntoResponse, E> where E: IntoResponse. Do not `.unwrap()` or `.expect()` inside a handler — a panic aborts the request task and, without CatchPanicLayer, the connection is dropped with no HTTP response at all, not a 500. The client sees a transport error and your 5xx dashboard sees nothing. Implement IntoResponse for your error type to produce consistent, controlled HTTP responses:
Note the shape of the DbError arm: the sqlx::Error is logged server-side and the client gets a fixed string. A blanket impl IntoResponse for anyhow::Error that writes any anyhow formatting into the body does the opposite. {} / to_string() emits whatever the last .context(...) said, {:#} emits the full cause chain including the database's own error text, and {:?} adds the backtrace. If you use anyhow for speed, make the IntoResponse impl log the error and return a correlation ID, never the message.
5. Tower middleware layer order — outermost wraps first, responses last
Tower middleware is composed as a stack: the layer added outermost (last in the builder chain or added first to ServiceBuilder) sees the request first and the response last. This is the reverse of what many frameworks call "middleware order."
Take the TimeoutLayer import seriously: `tower::timeout::TimeoutLayer` will not compile here. Its error type is BoxError, and a Router layer must be infallible — you would need HandleErrorLayer to convert it. tower_http's version returns the status directly. Note also that TimeoutLayer::new has been deprecated since tower-http 0.6.7 in favour of with_status_code.
Practical ordering rules:
- Tracing/logging — outermost so it captures the full round trip including all other middleware latency.
- Timeout — before auth/business logic so runaway requests are cut regardless of what's inside.
- Auth/authorization — inner, after trace so requests are logged even if they fail auth (useful for security auditing), before business handlers.
- Compression — innermost (wraps the response body), since it should apply to the final handler output.
AI frequently reverses the intuition ("last added = outermost") because it matches neither Express nor Django middleware mental models. When reviewing a .layer() chain, trace through request and response direction explicitly.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/mir-backend-rust-axum/SKILL.md
Popularity
- Repository stars
- 15
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-rust-axum)