Skill

implementing-controllers

Apply when creating, refactoring, modifying, planning (plan mode) or reviewing any file that is an HTTP controller, REST endpoint, API adapter, or global exception handler.

From kotlin-building-blocks
Install
1
Run in your terminal
$
npx claudepluginhub allousas/claude-code-plugins --plugin kotlin-building-blocks
Tool Access

This skill uses the workspace's default tool permissions.

Supporting Assets
View in Repository
examples.md
Skill Content

Purpose

Adapters that translate external http requests into application service calls or repositories. They are thin translation layers with no business logic.

Flow (HTTP Controllers)

  1. Receive HTTP request with DTOs
  2. Delegate to application service (commands) or query handler (queries)
  3. Map result to response DTO
  4. Return appropriate HTTP status code
  5. Let exceptions propagate to GlobalExceptionHandler

Guidelines

DO:

  • Keep adapters thin - delegate to application services or repositories, no business logic
  • Declare DTOs in the same file where they are used for cohesion
  • DTOs are pure data classes with no logic
  • Use internal private functions for mapping/conversion
  • File naming: <ExternalSystem><Concern>, e.g., TeamsHttpController
  • Model resources around domain entities (e.g., /teams, /teams/{id}/members)
  • Return appropriate status codes: 201 for creation, 204 for no content etc ...
  • Follow RESTful principles

DON'T:

  • Include business logic - only translation, mapping, and error handling
  • Use try-catch in controllers - delegate exception handling to GlobalExceptionHandler
  • Add validations at http dto level - delegate all validations to domain layer
  • Do not leak HTTP specific dtos, HTTP concerns or frameqrok related class into the application services

Commands vs Queries in Controllers

Commands (Write Operations):

  • Call command services from application/services
  • POST/PUT/PATCH/DELETE operations

Queries (Read Operations) - two approaches:

  • With orchestration/aggregation - Call query handlers or services if needed
  • Simple retrieval - Bypass application layer, call repositories/outbound ports directly

Global Exception Handler (Required)

Every project MUST have a single GlobalExceptionHandler that:

  1. Maps custom exceptions to HTTP status codes
  2. Logs all exceptions with use case context extracted from stack trace
  3. Returns consistent ErrorResponse(code, message) objects

Spring specifics

  • Use @ControllerAdvice for global exception handling

Examples

Please use always these examples as reference: examples.md

Similar Skills
cache-components

Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). **PROACTIVE ACTIVATION**: Use this skill automatically when working in Next.js projects that have `cacheComponents: true` in their next.config.ts/next.config.js. When this config is detected, proactively apply Cache Components patterns and best practices to all React Server Component implementations. **DETECTION**: At the start of a session in a Next.js project, check for `cacheComponents: true` in next.config. If enabled, this skill's patterns should guide all component authoring, data fetching, and caching decisions. **USE CASES**: Implementing 'use cache' directive, configuring cache lifetimes with cacheLife(), tagging cached data with cacheTag(), invalidating caches with updateTag()/revalidateTag(), optimizing static vs dynamic content boundaries, debugging cache issues, and reviewing Cache Component implementations.

138.5k
Stats
Parent Repo Stars1
Parent Repo Forks0
Last CommitFeb 25, 2026