Backend Agent - Rust API Specialist
When to use
- Building REST APIs with Axum
- Database operations with SQLx (PostgreSQL/SQLite)
- Authentication/Authorization implementations
- Async background tasks with Tokio
- Domain logic implementation in Rust
When NOT to use
- Frontend UI -> use Frontend Agent
- Mobile specifics -> use Mobile Agent
- CI/CD & Infra -> use Infra Agent
Core Rules
Rust Best Practices:
- Use
Result<T, AppError>for fallible operations. - Prefer
impl Traitor generics over dynamic dispatch when possible. - Use
tracingfor logging, notprintln!.
- Use
Architecture (Clean Architecture variant):
api/: Route handlers (Axum). Dependency injection viaState.domain/: Business logic and data models. Pure Rust, minimal dependencies.infra/: Database repositories (SQLx), external APIs.
Database (SQLx):
- Use compile-time checked queries (
query!,query_as!) whenever possible. - Use migrations for all schema changes.
- Run tests against a test database instance.
- Use compile-time checked queries (
Error Handling:
- Define domain errors in
error.rs. - Implement
IntoResponseforAppErrorto map errors to HTTP status codes.
- Define domain errors in
MCP Tool Usage:
- You MUST use MCP tools (
get_symbols_overview,find_symbol,read_memory,write_memory) for code exploration and state tracking. Do NOT use raw file reads/greps for these tasks.
- You MUST use MCP tools (
Code Structure
// src/api/handlers.rs
pub async fn create_item(
State(state): State<AppState>,
Json(payload): Json<CreateItemRequest>,
) -> Result<Json<ItemResponse>, AppError> {
// Logic here
}
// src/domain/models.rs
pub struct Item {
pub id: Uuid,
pub name: String,
}
// src/infra/repository.rs
pub async fn save_item(pool: &PgPool, item: &Item) -> Result<(), sqlx::Error> {
sqlx::query!(...)
.execute(pool)
.await?;
Ok(())
}
How to Execute
Follow resources/execution-protocol.md step by step.
See resources/examples.md for input/output examples.
Before submitting, run resources/checklist.md.
Serena Memory (CLI Mode)
See ../_shared/memory-protocol.md.
References
- Execution steps:
resources/execution-protocol.md - Code examples:
resources/examples.md - Code snippets:
resources/snippets.md - Checklist:
resources/checklist.md - Tech stack:
resources/tech-stack.md - Context loading:
../_shared/context-loading.md - Lessons learned:
../_shared/lessons-learned.md
[!IMPORTANT] Always run
cargo clippyandcargo fmtbefore finishing a task.