Controllers

Business logic coordination between routes and services.

Controllers should:

  • Handle business logic and orchestration between services
  • Handle environment variables and configuration
  • Coordinate multiple service calls
  • Implement business rules and validation
  • Handle service business logic layer (result.success)

Examples

Webhook Handler Pattern (tasks.controller.ts)

The handleUrlWebhook function follows the webhook handler pattern:

  • Takes Hono Context as parameter
  • Returns HTTP responses directly
  • Handles webhook payload parsing and validation
  • Implements business logic for URL updates
  • Provides comprehensive logging and error handling

Data API Pattern (glimpse.controller.ts)

The glimpseHandler function follows the data API pattern:

  • Takes Hono Context as parameter
  • Returns JSON data responses
  • Filters and transforms service data
  • Handles error responses with appropriate status codes