Agent skill
middleware-design
Designing robust middleware chains (Auth, Rate Limiting, Logging).
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/architecture-andreibesleaga-gabbe-2
SKILL.md
middleware-design Skill
This skill guides the creation of the request processing pipeline ("The Onion Architecture").
1. The Standard Pipeline (Order Matters)
- Request ID: Generate
trace_idimmediately. (Before logs). - CORS: Allow/Block origins. (Before processing).
- Body Parser: JSON/Form parsing. (Limit size to prevent DoS).
- Rate Limiter: Token Bucket algorithm. (Stop abuse cheaply).
- Authentication: Verify JWT/Session. (Who is it?).
- Authorization: Check Roles/Scopes. (Can they do it?).
- Validation: Zod/Pydantic schema check. (Is input valid?).
- Controller: Business Logic.
- Error Handler: Catch exceptions, format JSON, scrub sensitive data.
2. Implementation Rules
- Fail Fast: If Rate Limit check fails, return 429 immediately. Do not parse body.
- Context Passing: Pass
userandtrace_idvia Context (Go/React) or Request Object (Express/FastAPI). - No Business Logic: Middleware should be generic. Don't query
SELECT * FROM ordersin middleware.
3. Specific Patterns
Rate Limiting
- Global: 1000 req/min/IP.
- Route-Specific: Login = 5 req/min/IP.
- Storage: Use Redis. Local memory rate limiting doesn't work in clustered apps.
Response Interceptors
- Use for consistent response formatting.
data: { ... },meta: { trace_id: ... }.
Error Handling Middleware
- NEVER return raw stack trace to client in Production.
- ALWAYS log raw stack trace to logger.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?