KeiSeiKit-1.0/_blocks/stack-rust-axum.md
denis 0b901cf2f9 feat: KeiSeiKit v0.1.0 — initial public release
Generic Constructor-Pattern agent kit for Claude Code. Zero personal data,
fully English, MIT-licensed.

Contents:
- 34 reusable blocks (baseline, rules, stack/deploy/domain/api/scraper)
- 14 cross-project agent manifests (code/ml/infra/researcher/critic/...)
- 6 portable skills (/new-agent, /research, /test-gen, /debug-deep, /pr-review, /refactor)
- Rust assembler (single binary, ~500 KB)
- 3 hooks (auto-reassemble, pre-commit validate, no-hand-edit)
- install.sh (idempotent, cargo-builds on first run)
- MIT LICENSE

All 6 sanity greps pass: 0 Russian text, 0 specific project names,
0 incident numbers, 0 user paths, 0 hardcoded IPs, 0 API keys.

cargo check + assemble --validate: both pass on 14 manifests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 23:58:34 +08:00

1.3 KiB

STACK — Rust HTTP server (axum + tokio + sqlx)

Default web stack — no language justification needed.

Versions: axum 0.7+, tokio 1.x (rt-multi-thread), sqlx 0.7+ (NOT diesel — async-first), tower 0.4+ for middleware.

App shape:

  • AppState struct → Arc<AppState>Router::with_state(state). No globals.
  • Handlers take State<Arc<AppState>>, extractors typed, return Result<impl IntoResponse, AppError>.
  • AppError = single thiserror enum with IntoResponse impl → maps to HTTP status + JSON body.
  • #[tokio::main] ONLY in the binary crate. Library crates never pin a runtime.

Middleware stack (order matters):

  1. TraceLayer (tower-http) — request id + span
  2. CorsLayer — explicit allow-list, never Any in prod
  3. TimeoutLayer — hard cap per route
  4. CompressionLayer
  5. Auth middleware (custom) — short-circuits on 401

Crypto: Ed25519 for signing (ed25519-dalek); never roll your own. Secrets from env at startup, never in code.

sqlx: queries use sqlx::query! / query_as! macros (compile-time checked against live DB). Migrations under migrations/ managed by sqlx-cli. NEVER string-concat SQL.

Forbidden: unwrap() in handler paths, sqlx::query() with runtime strings, blocking calls (std::fs::read) without spawn_blocking, #[tokio::main] in lib crates (caller chooses runtime).