axum

A set of coding guidelines for Axum, a Rust framework for building web servers and APIs. It covers application structure, setup, dependencies, and API documentation.

In plain words
What is it for?
Use it when creating or reviewing Rust web applications with Axum 0.8 or newer, database access, configuration, and OpenAPI or Swagger documentation.
Why use it?
It gives the agent consistent patterns for organising Axum applications, including shared application state, request handling, middleware, and documented API responses.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/tyrchen/cursor-rust-rules/axum
Clone the repo
git clone --depth 1 https://github.com/tyrchen/cursor-rust-rules

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 9,871 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.09871
Opus 5 $0.00000 $0.04935
Sonnet 5 $0.00000 $0.01974
Haiku 4.5 $0.00000 $0.00987

Measured 2d ago against content hash 2ab0863fe858, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

axum scanned grade A with 0 findings against 26 rules in 11 categories โ€” prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency โ€” measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/rust/features/axum.mdc ยท 1,434 lines

How it starts

The opening of the file, as written. The whole thing โ€” 1,434 lines โ€” stays where its author put it; the contents beside it link to each section on GitHub.

๐ŸŒ AXUM WEB FRAMEWORK STANDARDS

TL;DR: Comprehensive guidelines for building production-ready web applications with Axum, including AppConfig/AppState patterns, OpenAPI integration with utoipa, and scalable server architecture.

๐Ÿ—๏ธ AXUM APPLICATION ARCHITECTURE

graph TD
    HTTP["HTTP Requests"] --> Router["Axum Router"]
    Router --> Middleware["Middleware Stack"]
    Middleware --> Handlers["Route Handlers"]

    Handlers --> State["Application State"]
    State --> Config["AppConfig<br>(via arc-swap)"]
    State --> Database["Database Pool"]
    State --> Services["Service Layer"]

    Config --> Settings["Configuration Settings"]
    Database --> Repositories["Repository Layer"]
    Services --> BusinessLogic["Business Logic"]

    Handlers --> Response["HTTP Response"]
    Response --> OpenAPI["OpenAPI Docs<br>(utoipa)"]
    Response --> Swagger["Swagger UI"]

    style HTTP fill:#4da6ff,stroke:#0066cc,color:white
    style Router fill:#4dbb5f,stroke:#36873f,color:white
    style State fill:#ffa64d,stroke:#cc7a30,color:white
    style Config fill:#d94dbb,stroke:#a3378a,color:white
    style OpenAPI fill:#4dbbbb,stroke:#368787,color:white

๐ŸŽฏ AXUM VERSION AND SETUP

Axum 0.8+ Requirements

  • Use Axum 0.8 or later - leverages latest async patterns
  • Path parameters with {param} syntax - more intuitive than :param
  • Structured router organization - group related endpoints
  • OpenAPI integration with utoipa for documentation
  • AppState pattern with arc-swap for hot-reloadable configuration

๐Ÿ“ฆ AXUM DEPENDENCIES

# Cargo.toml - Required dependencies for Axum applications
[dependencies]
# Core Axum
axum = { version = "0.8", features = ["macros", "multipart"] }
tokio = { version = "1.45", features = ["macros", "rt-multi-thread", "net", "fs", "time", "sync", "signal"] }
tower = { version = "0.5", features = ["full"] }
tower-http = { version = "0.6", features = ["cors", "trace", "compression", "auth", "limit"] }
http = "1.0"

# Configuration management with hot-reload
arc-swap = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

# OpenAPI and documentation
utoipa = { version = "5.0", features = ["axum_extras", "chrono", "uuid"] }
utoipa-axum = "0.2"
utoipa-swagger-ui = { version = "9.0", features = ["axum"] }

# Error handling and validation
anyhow = "1.0"
thiserror = "2.0"
validator = { version = "0.18", features = ["derive"] }

# Utilities
uuid = { version = "1.17", features = ["v4", "v7", "serde"] }
chrono = { version = "0.4", features = ["serde"] }

# Logging and tracing
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json", "chrono"] }

# Database (if needed)
sqlx = { version = "0.8", features = ["runtime-tokio-rustls", "postgres", "uuid", "chrono", "time", "json"] }

# HTTP client
reqwest = { version = "0.12", features = ["rustls-tls", "json", "stream", "multipart"] }

[dev-dependencies]
axum-test = "15.0"
tower-test = "0.4"
tempfile = "3.0"
wiremock = "0.6"

Read the full file on GitHub ยท 1,434 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen ยท 1,434 lines ยท 0 tokens per session scan A 2ab0863fe858

Subscribe to this mod's changes

axum is a cursor rule published in the GitHub repository tyrchen/cursor-rust-rules (27 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 9,871 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.