axum-impl-tower-stack

Configure Axum middleware stacks with correct tower layer ordering and feature flags.

Updated May 20, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-tower-stack
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: axum-impl-tower-stack
Source: https://github.com/Impertio-Studio/Axum-Claude-Skill-Package/tree/main/skills/source/axum-impl/axum-impl-tower-stack
Command: npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-tower-stack

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It prevents subtle, production-breaking bugs when adding Axum middleware through tower and tower-http, especially layer ordering mistakes, missing Cargo features, and incorrect CORS or rate-limiting assumptions.

Core Features & Use Cases

  • Correct tower middleware composition: clarifies how tower::Service/Layer wrapping works in Axum and how ServiceBuilder order differs from stacked Router::layer() order.
  • tower-http layer correctness: ensures the right constructor usage and enables the required tower-http Cargo feature flags so layers actually compile.
  • Production-safe CORS and rate limiting: provides guardrails for using CorsLayer::new() allowlists instead of permissive presets, and distinguishes coarse global throttling (tower::limit) from per-client token buckets (tower_governor), including the Clone/Buffer requirement.

Quick Start

Use the skill when you need to add tracing, compression, timeouts, CORS, request body limits, or rate limiting to an Axum app via a ServiceBuilder middleware stack and want deterministic, version-aware ordering and feature-safe configuration.

Frequently Asked Questions about axum-impl-tower-stack

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I order Axum middleware correctly with ServiceBuilder and Router::layer?▼

Axum middleware ordering depends on whether you use ServiceBuilder or stacked Router::layer() calls, as ServiceBuilder applies layers in reverse declaration order while Router::layer() applies them outermost-first. Matching the two prevents unexpected request processing behavior.

Why does my tower-http CorsLayer or CompressionLayer fail to compile in Axum?▼

tower-http layers often fail to compile because specific Cargo feature flags must be explicitly enabled for components like CorsLayer, CompressionLayer, and TraceLayer. Enabling the correct tower-http features resolves the missing trait implementation errors.

What is the difference between tower::limit and tower_governor for Axum rate limiting?▼

tower::limit provides coarse global throughput throttling, whereas tower_governor implements per-client token bucket rate limiting. tower_governor requires its service to be Clone or wrapped in a BufferLayer to satisfy backpressure contracts.

How do I configure production-safe CORS in Axum using tower-http?▼

Production-safe CORS in Axum requires configuring CorsLayer with explicit origin allowlists rather than using permissive presets. Defining specific allowed origins prevents unauthorized cross-origin requests from reaching your application.

Does RateLimitLayer in Axum require a BufferLayer for non-Clone services?▼

Yes, RateLimitLayer requires non-Clone services to be wrapped in a BufferLayer to properly handle the poll_ready backpressure contract. Wrapping the service ensures correct rate limiting behavior without panicking under load.

What are common limitations when composing global middleware stacks in Axum?▼

Common limitations include violating the poll_ready backpressure contract, misordering ServiceBuilder versus Router::layer() outermost layers, and missing required tower-http Cargo features. Adhering to layer ordering and feature enablement rules avoids these middleware stack failures.