---
name: "tower-composable-service-middleware"
description: "Author modular, reusable middleware and service pipelines across Axum, Tonic, and Hyper."
metadata:
  author: "Tower"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "implement tower service trait"
  - "servicebuilder compose layers"
  - "tower rate limit layer"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Tower Composable Asynchronous Services & Middleware Layers

Implements Tower Service trait: Service<Request>, Layer trait, building reusable middleware (authentication, rate-limiting, circuit-breaking, retries), and composing with ServiceBuilder.

## When to Invoke
Invoke this skill whenever you need to:
- implement tower service trait
- servicebuilder compose layers
- tower rate limit layer

## Execution SOP & Rules
1. Implement trait: impl<R> Service<R> for MyMiddleware { type Response = ...; type Future = ...; }.
2. Handle poll_ready() backpressure checking before invoking call().
3. Compose layers: let middleware = ServiceBuilder::new().timeout(Duration::from_secs(10)).layer(TraceLayer::new()).service(inner);
4. Share middleware across any framework adhering to Tower abstractions.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
