Rust backend
Skill muxammadmamajonov/dot-claude/.claude/skills/rust-backend
Use for Rust backend services — Axum/Actix-web, Tokio async, thiserror/anyhow, SQLx/SeaORM, testing, hardening. Triggers — Cargo.toml, .rs handlers, 'axum', 'actix', 'tokio', 'sqlx'.From its SKILL.md
npx -y skills add muxammadmamajonov/dot-claude --skill rust-backendAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
6.1 KB, ~1.5k tokens by cl100k_base, as published. Nobody here has run it
Rust Backend Development
When to use
- Writing HTTP APIs or gRPC services with Axum, Actix-web, or Warp
- Designing ownership-safe data models and async service layers
- Implementing error types with
thiserrorand propagation withanyhow/? - Integrating databases via
sqlx(async, compile-time checked) or SeaORM - Writing unit, integration, and property-based tests
- Profiling CPU/allocation with
perf,flamegraph, orcriterion
Workflow
- Confirm Rust edition and MSRV — check
Cargo.toml(edition = "2021",rust-version). Use stable toolchain unless a nightly feature is justified and documented. - Establish crate/module layout:
src/ main.rs # binary entrypoint: init tracing, DB pool, router, server lib.rs # re-exports for integration tests api/ # Axum handlers, extractors, middleware services/ # business logic (pure functions over domain types) db/ # sqlx queries, repository impls domain/ # types, enums, value objects (no I/O) errors.rs # AppError enum + IntoResponse impl config.rs # typed config from env vars - Define domain types and the
AppErrorenum first — they drive everything else.#[derive(Debug, thiserror::Error)] pub enum AppError { #[error("not found")] NotFound, #[error("db: {0}")] Db(#[from] sqlx::Error), } - Set up the
AppState—#[derive(Clone)]struct holdingPgPool, config, and shared clients. Pass viaaxum::Extensionor state extractor. - Write handlers — thin: extract → call service → return
impl IntoResponse. Validation viavalidatorcrate + custom extractor. - Async runtime —
#[tokio::main]withtokio::runtime::Builderfor production (configure worker threads). Neverblock_oninside async code. - Database queries with
sqlx:- Use
sqlx::query_as!macros — compile-time checked against a live DB (DATABASE_URLin.env). - All multi-step writes in explicit
pool.begin()transactions. - Set
connect_options.statement_cache_capacityand pool max connections.
- Use
- Write tests:
- Unit: pure functions, no I/O, in
#[cfg(test)]modules within the same file. - Integration:
tokio::test, real DB viasqlx::testattribute (creates an isolated DB per test). - Use
axum::body::to_bytes+serde_jsonto assert handler responses.
- Unit: pure functions, no I/O, in
- Benchmark hot paths with
criterion; runcargo flamegraphto visualise. - Audit against .claude/checklists/security.md and .claude/checklists/performance.md.
Standards
Ownership and types
- Prefer
&stroverStringin function parameters where the callee doesn't need ownership. - Use
Arc<T>for shared state across async tasks;Mutex<T>only inside synchronous critical sections — prefertokio::sync::Mutexin async contexts. - Newtype pattern for domain IDs:
struct UserId(Uuid)prevents accidental ID mixups. - Derive
Debug,Clone,PartialEqfor domain types; deriveSerialize/Deserializeonly at API boundary structs.
Error handling
- Define one
AppErrorenum per crate/service withthiserror. - Use
?for propagation; never.unwrap()or.expect()in production code paths. - Implement
axum::response::IntoResponseforAppErrorto map to HTTP status + JSON body. - Log errors at the point of origin; propagate the type, not a string.
Async / Tokio
- CPU-bound work:
tokio::task::spawn_blockingorrayonthreadpool — never block in an async context. - Set timeouts with
tokio::time::timeouton every external call. - Structured concurrency:
tokio::select!,JoinSet, orFuturesUnorderedover baretokio::spawnwhen you need to collect results.
Security
- Validate all input with the
validatorcrate and reject early with 422. - Hash passwords with
argon2(useargon2crate, not rawbcrypt). - Use
secrecy::Secret<String>for tokens and passwords to prevent accidentalDebugleakage. - Set
Content-Security-Policy,X-Frame-Options, and security headers viatower-http::set-header.
Do not
- Do not use
unsafewithout aSAFETY:comment block explaining the invariants upheld. - Do not panic in library code (
panic!,unwrap,expect) — return aResultinstead. - Do not use
.clone()reflexively to satisfy the borrow checker — restructure first. - Do not place
#[allow(unused_*)]globally; fix the warnings instead.
Common mistakes to avoid
| Mistake | Fix |
|---|---|
async fn that holds a non-Send type across .await | Restructure to drop the non-Send value before the await point. |
sqlx::query! failing at runtime due to missing DATABASE_URL at compile time | Set DATABASE_URL in .env and run cargo sqlx prepare to embed offline metadata. |
Cloning PgPool repeatedly into handlers | PgPool is already Clone + Send + Sync cheaply (Arc-backed); clone freely. |
Shadowing outer error types with anyhow::Error | Use thiserror for typed errors in libraries; anyhow only in binaries/tests. |
Mutex<Vec<T>> contention under load | Use DashMap or channel-based message passing for concurrent collections. |
Missing tower::ServiceBuilder middleware order | Middleware applies inside-out; put logging outermost, auth innermost. |
Output format
- New handler:
async fnwith typed extractors, service call, andAppErrorpropagation. - Error enum:
thiserrorenum with#[from]conversions andIntoResponseimpl. Cargo.tomladditions: feature-flagged dependencies with version pinning.- Test:
#[sqlx::test]annotated async function with setup, action, and assertion.
Related checklists
- .claude/checklists/security.md
- .claude/checklists/performance.md
- .claude/checklists/qa.md
Related agents
- .claude/agents/core/orchestrator.md
- .claude/agents/engineering/devops-engineer.md
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.