Back to guide/AI Tool Configs

CLAUDE.md — Rust + Axum + SQLx

CLAUDE.md template for Rust web APIs using Axum, compile-time checked SQLx queries, and proper error handling.

claude-mdrustaxumsqlxai-config
Edit View
Prompt
# 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

{{project_name}}{{one-line description}}{{auth_approach}}

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.