axum-service-architecture

Design layered Axum service architectures with AppState and Tower middleware.

3|Updated Nov 16, 2025
One-click install
npx skills add https://github.com/matthewharwood/engmanager.xyz --skill axum-service-architecture
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: axum-service-architecture
Source: https://github.com/matthewharwood/engmanager.xyz/tree/main/.claude/skills/axum-service-architecture
Command: npx skills add https://github.com/matthewharwood/engmanager.xyz --skill axum-service-architecture

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a blueprint for organizing Axum services into clear layers (Router → Handler → Service → Repository) and wiring dependencies via AppState and FromRef, enabling maintainable, scalable Rust web services.

Core Features & Use Cases

  • Layered Architecture: Separate routing, business logic, and data access to improve testability and maintainability.
  • AppState Dependency Injection: Use FromRef to inject dependencies into handlers without global state.
  • Middleware Composition: Build a deterministic middleware stack with Tower ServiceBuilder for observability, timeouts, and retries.
  • Modular Router Organization: Compose routers by domain/module for scalable API design.

Quick Start

Create a new Axum service using the layered pattern described above: define AppState, implement Router → Handler → Service → Repository, and wire them together with a Tower middleware stack.

Frequently Asked Questions about axum-service-architecture

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I organize an Axum service with layered architecture?

Layered architecture in Axum separates routing, business logic, and data access into distinct Router, Handler, Service, and Repository layers. This pattern improves testability and maintainability by enforcing clear separation of concerns and making dependencies explicit.

How do I inject dependencies into Axum handlers without global state?

Use AppState with FromRef to inject dependencies directly into handlers. This approach avoids global state, keeps dependencies explicit, and enables testable handler functions that declare their requirements upfront.

What's the best way to compose middleware in Axum with Tower?

Build a deterministic middleware stack using Tower ServiceBuilder to layer observability, timeouts, retries, compression, and CORS in a predictable order. This ensures production-grade concerns apply consistently across your service.

How do I structure routers by domain in a scalable Axum API?

Organize routers modularly by domain or feature module, then compose them together at the top level. This approach keeps API routes grouped logically and makes the codebase easier to navigate as services scale.

Can I use this layered pattern for services that need middleware timeouts and tracing?

Yes, the layered architecture integrates Tower middleware composition for timeouts, tracing, and other cross-cutting concerns. The pattern satisfies functional requirements for production-grade middleware stacks alongside clean separation of logic.

Why separate handlers, services, and repositories in Axum?

Separating these layers isolates concerns: handlers manage HTTP semantics, services encapsulate business logic, and repositories handle data access. This enables testing each layer independently and makes logic reusable across multiple endpoints.