CLAUDE.md — Rust + Axum + SQLx
CLAUDE.md template for Rust web APIs using Axum, compile-time checked SQLx queries, and proper error handling.
# CLAUDE.md ## Project Overview {{project_name}} — {{one-line description}} ## Tech Stack - Language: Rust (latest stable) - Web framework: Axum 0.7+ - Database: PostgreSQL via SQLx (compile-time checked queries) - Serialization: serde + serde_json - Error handling: thiserror + anyhow - Auth: {{auth_approach}} - Tracing: tracing + tracing-subscriber ## Commands ```bash cargo run # Dev server cargo test # Run tests cargo clippy -- -D warnings # Lint sqlx migrate run # Apply migrations sqlx prepare # Prepare offline query cache ``` ## Directory Structure ``` src/ ├── main.rs # Server setup + routing ├── routes/ # Axum handler functions ├── models/ # Database models (FromRow) ├── services/ # Business logic ├── extractors/ # Custom Axum extractors ├── error.rs # App error type + IntoResponse └── config.rs # Environment config migrations/ # SQLx migrations ``` ## Conventions - Use typed extractors (Json<T>, Path<T>, Query<T>) - Custom AppError type that implements IntoResponse - All DB queries via sqlx::query_as! (compile-time checked) - Use Arc<AppState> for shared state - Prefer &str over String in function parameters - No unwrap() in production code — use ? operator - Run `sqlx prepare` before committing if queries changed
Variables to customize
Why this prompt works
Rust has strict idioms. 'No unwrap() in production' and 'compile-time checked queries' are constraints Claude can enforce consistently, producing code that compiles cleanly.
Save this prompt to your library
Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.
Related prompts
Production CLAUDE.md template for Next.js App Router projects with TypeScript strict mode and Tailwind CSS.
CLAUDE.md — Python + FastAPI + SQLAlchemyCLAUDE.md template for async FastAPI projects with SQLAlchemy 2.0, Alembic migrations, and pytest.
CLAUDE.md — Go + Chi Router + PostgreSQLCLAUDE.md template for Go APIs using Chi, pgx, and idiomatic Go project structure.
CLAUDE.md — React Native + ExpoCLAUDE.md template for React Native Expo projects with file-based routing, NativeWind, and Zustand.