backend Stack3 Harmonized RulesMulti-Platform Compatible

Rust Axum + Tokio + Cloud-Native Systems

Production behavioral rules for Rust backend engineering. Guards against blocking the Tokio executor, enforces Send + Sync state, and mandates zero unwrap() in production paths.

CLI One-Linernpx agentrules
npx agentrules init

Auto-detects this stack and writes verified client instructions into your project root.

42 lines • ~777 tokens
# Combined .cursorrules generated by AgentRules.org (https://agentrules.org)
# Specification Version: 2026.10-Industrial | Licensed under CC BY 4.0
# Stack: Rust Axum & Tokio Production Concurrency Standard, Docker Multi-Stage & Non-Root Hardening Standard, Zero Secret Hardcoding & Environment Hygiene Standard
# Free for in-repo use. Attribution to agentrules.org required if cited or republished.

# ==============================================================================
# SECTION 1: RUST AXUM & TOKIO PRODUCTION CONCURRENCY STANDARD
# ==============================================================================
## Directive
You are a principal Rust backend engineer building services with Axum and Tokio. Never block Tokio threads with synchronous operations; use tokio::task::spawn_blocking or tokio::fs. Axum handler state must be thread-safe (Arc<AppState>). Use thiserror for domain errors.

## Strict Guidelines
1. Never use std::thread::sleep in async fn; use tokio::time::sleep.
2. Offload heavy CPU-bound or blocking operations to tokio::task::spawn_blocking.
3. Prefer bounded channels (tokio::sync::mpsc::channel(capacity)) to prevent unbounded memory growth under load.
4. Implement IntoResponse for custom application Error enum using thiserror.


# ==============================================================================
# SECTION 2: DOCKER MULTI-STAGE & NON-ROOT HARDENING STANDARD
# ==============================================================================
## Directive
You are a container security specialist. Docker containers must never run as root. Always create and switch to an unprivileged user (USER appuser). Use multi-stage builds to discard build tools, compilers, and source artifacts from the final image. Include explicit HEALTHCHECK instructions.

## Strict Guidelines
1. Never run as root. Add `RUN addgroup -S app && adduser -S app -G app` and `USER app`.
2. Separate build dependencies from runtime using multi-stage builds.
3. Use specific immutable image digest tags (node:22-alpine3.20) rather than `:latest`.
4. Define HEALTHCHECK to allow orchestrators to detect deadlocked processes.


# ==============================================================================
# SECTION 3: ZERO SECRET HARDCODING & ENVIRONMENT HYGIENE STANDARD
# ==============================================================================
## Directive
You are a cloud security compliance officer. Never hardcode API keys, passwords, private keys, or tokens in source code, tests, or documentation. Validate all environment variables at application startup using a strict schema (e.g., @t3-oss/env-nextjs or Zod).

## Strict Guidelines
1. Never commit secrets to Git; add .env, .env.local, and *.pem to .gitignore.
2. Validate presence and format of required environment variables during bootstrap.
3. Reference dummy mock tokens (e.g., 'TEST_MOCK_TOKEN') strictly in unit tests with no production resemblances.
Target File:.cursorrules
AgentRules.org RFC-2119 Matrix Standard

Architectural Rationale & Failure Mode Analysis

Why modern AI assistants repeatedly fail on this specific technology combination without behavioral constraints.

Async Rust requires careful respect for thread executors. When AI models generate Rust code, they frequently attempt to call std::thread::sleep or sync file I/O inside Tokio futures, completely freezing worker threads.

Prevented Production Hazards & AI Hallucination Vectors

AI Hallucination HazardProduction ImpactVerifiable Guardrail Mitigation
Calling std::thread::sleep or sync I/O in async fnTokio worker thread starvation; catastrophic throughput collapse.Enforces tokio::time::sleep and tokio::task::spawn_blocking.
Using .unwrap() on Result or Option in request handlersProcess panics under malicious or unexpected payloads.Mandates Result<T, AppError> with custom IntoResponse error mapper.

Constituent Rules in this Stack (3)

Each rule provides AST-level positive and negative enforcement
backendcritical

Rust Axum & Tokio Production Concurrency Standard

Guardrails for Rust web services: manage Send + Sync bounds, avoid blocking Tokio worker threads, use bounded mpsc channels, and handle database connection pooling.

#rust#axum#tokio
View Spec
devopscritical

Docker Multi-Stage & Non-Root Hardening Standard

Production Dockerfile hardening: multi-stage builds, non-root user execution, minimal base images (distroless/alpine), and HEALTHCHECK directives.

#docker#containers#security
View Spec
securitycritical

Zero Secret Hardcoding & Environment Hygiene Standard

Guardrails against leaked API keys, tokens, and database passwords: zero plaintext secrets in code, Git pre-commit secret scanning, and automated runtime env validation.

#security#secrets#env
View Spec

AI Agent Golden Iron Triangle Integrations

Combine behavioral rules with verifiable execution skills and live tool servers for complete Agent autonomy.

Recommended Agent Skillsaskills.dev

Equip your AI agent with specialized command functions to execute verification tests and lints directly.

Recommended MCP Tool Serversmcp-serverlist.com

Connect standard Model Context Protocol servers to grant your agent authenticated filesystem and database access.