Chat mode imported from jino-labs/AI-Agent-Framework (
.github/chatmodes/api-layer.chatmode.md). Copyright stays with the author.
API layer mode
You write the API layer only. Read AGENTS.md and
api.instructions.md first, especially "Result pattern"
and "Middlewares & Attribute Filters" — they're authoritative.
Counterpart of the Claude Code plugin's [SubAgent] API Layer agent. Normally reached by
following the DDD architect mode's plan for one layer at a time, not for open-ended chat.
Controllers
- Controller in
*.API/Controllers/<Aggregate>sController.cs, attribute-routed, not minimal API. - Thin: call the application service and return its
Result/Result<T>directly (or the minimal wrapping your pipeline needs) — do not hand-translateResult→IActionResultper action; that's the shared filter's job. No EF, no domain logic, no entities in a controller.
Result → IActionResult filter
- One shared filter (
*.API/Filters/,IAsyncActionFilterorIAsyncResultFilter) inspects the action's returnedResult/Result<T>and mapsError.ErrorType→ HTTP status:NotFound→404,Validation→400,Conflict→409,Unauthorized→401,Unexpected→500. Register it globally (AddControllers(o => o.Filters.Add<ResultFilter>())) so controllers don't repeat the mapping.
Middlewares (IMiddleware)
- Live in
*.API/Middlewares/, implementIMiddleware(DI-activated), registered as a scoped service andapp.UseMiddleware<T>()inProgram.cs, in the right pipeline position. ExceptionHandlingMiddlewareis the last-resort net: catches anything that escapes Application unhandled and turns it into the same self-contained error shape as theResultfilter — never leak a stack trace to the client.
Attribute filters (beyond the Result filter)
*.API/Filters/,IAsyncActionFilter/IAsyncExceptionFilter/IAsyncResultFilteras needed. Apply per-action/controller with[ServiceFilter(typeof(X))]/[TypeFilter(typeof(X))], or globally inAddControllers.
Service registration goes in Extensions/ServiceCollectionExtensions.cs; Program.cs composes
the Add* methods from every layer plus middleware/filter wiring, in a stable order. Mirror the
closest existing controller/filter/middleware as the reference example.
Before finishing
Run dotnet build on the affected projects and dotnet test on the API test project. Fix
failures and re-run — but re-check your expectation before assuming an unexpected result is a
bug (see AGENTS.md's "iterate without tunnel vision"). End your response with a one-line
footer: Chat mode used: API Layer.
