.claude/skills/interceptor-pipeline/SKILL.md
Use when cross-cutting concerns (logging, metrics, validation, authorization) are tangled into command handlers or service methods, when building database command pipelines with reorderable concerns, or when HTTP client pipelines or message handlers need composable, independently-replaceable processing stages. Covers ICommandInterceptor interface, InterceptorPipeline with reverse-chain construction, zero-cost Empty sentinel to skip overhead when no interceptors are registered, and ConfigureAwait(false) discipline for library code. Domain: Architecture, Cross-Cutting Concerns. Level: Intermediate. Tags: interceptor, pipeline, middleware, decorator, cross-cutting-concerns.
npx skillsauth add klod68/littlerae interceptor-pipelineInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Cross-cutting concerns (logging, metrics, validation, authorization) get tangled into core business logic, making methods long and responsibilities unclear. Each concern is copy-pasted into every command handler.
Wrap command execution with a pipeline of interceptors. Each interceptor handles one concern and delegates to the next. When no interceptors are registered, a zero-cost Empty sentinel skips the chain entirely.
public interface ICommandInterceptor
{
Task<T> InterceptAsync<T>(CommandContext context, Func<Task<T>> next);
}
public sealed class InterceptorPipeline
{
public static readonly InterceptorPipeline Empty = new([]);
private readonly IReadOnlyList<ICommandInterceptor> _interceptors;
public InterceptorPipeline(IReadOnlyList<ICommandInterceptor> interceptors)
{
_interceptors = interceptors;
}
public bool HasInterceptors => _interceptors.Count > 0;
public async Task<T> ExecuteAsync<T>(CommandContext context, Func<Task<T>> operation)
{
if (_interceptors.Count == 0)
return await operation().ConfigureAwait(false);
// Build the chain from innermost (last) to outermost (first)
Func<Task<T>> chain = operation;
for (int i = _interceptors.Count - 1; i >= 0; i--)
{
var interceptor = _interceptors[i];
var next = chain;
chain = () => interceptor.InterceptAsync(context, next);
}
return await chain().ConfigureAwait(false);
}
}
public sealed class LoggingInterceptor : ICommandInterceptor
{
private readonly ILogger _logger;
public LoggingInterceptor(ILogger logger) => _logger = logger;
public async Task<T> InterceptAsync<T>(CommandContext context, Func<Task<T>> next)
{
_logger.LogInformation("Executing {Command}", context.CommandName);
var sw = Stopwatch.StartNew();
try
{
var result = await next().ConfigureAwait(false);
_logger.LogInformation("Completed {Command} in {Elapsed}ms",
context.CommandName, sw.ElapsedMilliseconds);
return result;
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed {Command} after {Elapsed}ms",
context.CommandName, sw.ElapsedMilliseconds);
throw;
}
}
}
public sealed class MetricsInterceptor : ICommandInterceptor
{
public async Task<T> InterceptAsync<T>(CommandContext context, Func<Task<T>> next)
{
using var activity = ActivitySource.StartActivity(context.CommandName);
return await next().ConfigureAwait(false);
}
}
Empty sentinel avoids null checks and has zero overhead — it skips the chain entirely.next() exactly once — failing to call it silently drops the operation.ConfigureAwait(false) throughout the chain for library code.development
Use when writing integration tests for Razor Pages, MVC, or Minimal API applications to validate routing, middleware, page rendering, and HTTP behavior without a browser or live server, or when adding fast smoke tests to a CI pipeline. Covers WebApplicationFactory<Program> setup with public partial class Program, in-memory test server, AngleSharp HTML parsing, CSS selector assertions, redirect and status code testing, and a shared static fixture pattern for minimal per-test startup overhead. Domain: Testing, ASP.NET Core. Level: Intermediate. Tags: integration-testing, webapplicationfactory, razor-pages, anglesharp, http-testing.
development
Use when designing indexes for new tables, diagnosing slow queries that are not using indexes efficiently, reviewing index fragmentation and maintenance, or when the current indexing strategy results in key lookups, table scans, or missing index warnings. Covers clustered index key selection (narrow, unique, ever-increasing), non-clustered index design for query patterns, covering indexes with INCLUDE columns, filtered indexes for subset queries, composite index column ordering, DMV-based monitoring for missing and unused indexes, and rebuild vs reorganize maintenance thresholds. Domain: Database, Performance. Level: Intermediate. Tags: index, sql-server, covering-index, filtered-index, performance, dmv, maintenance.
development
Use when building a searchable in-memory catalog or registry for documentation sites, admin panels, or type/API browsers where you need keyword matching, fuzzy search, and ranked results without an external search engine or database. Covers RegistryService with weighted scoring across name, description, keywords, and method names; Levenshtein fuzzy matching; synonym expansion; category and subcategory filtering; and singleton DI registration for datasets of hundreds to low thousands of items. Domain: Search, Data Access Patterns. Level: Intermediate. Tags: search, registry, fuzzy-matching, in-memory, catalog, filtering.
tools
Use when adding database persistence to a Truenorth.Components.* library, migrating legacy persistence code to the standard pattern, or adding new entities to an existing component following the stored-procedure-only architecture with EXECUTE-only permissions. Covers the 8-artifact pattern: embedded settings, language constants, static repository, component factory, DbMappings, Insert/Update/Delete commands, SelectAll/SelectById/Exists queries, and a CrudPersistenceHelper-based persistence service with IList/IListCollectable/ITableCollectable output variants. Domain: Data Access / Persistence. Level: Advanced. Tags: persistence, stored-procedure, CRUD, ADO.NET, provider-agnostic.