Complete guide to clean route definitions and controller patterns. ❌ Access database directly ❌ Implement validation logic (use Zod + controller) ❌ Format compl
The Routing and Controllers skill provides a structured approach to defining clean API routes and implementing controller logic with consistent patterns. It emphasizes separating routing from business logic, using a BaseController to centralize error handling, response formatting, validation, and performance tracking. This skill avoids direct database access within controllers, instead encouraging validated inputs and standardized outputs for maintainable and testable code.
This skill is designed for backend engineers supporting marketing platforms, API developers managing data endpoints, and growth leads overseeing scalable service architectures. It suits performance marketers needing reliable data pipelines, agency strategists integrating third-party APIs, and product engineers responsible for consistent error reporting and monitoring across microservices.
Practitioners start by defining routes that delegate requests to controller methods without embedding business logic. They extend a BaseController to handle common tasks such as error reporting with Sentry, formatting success and failure responses, and validating incoming request data using a schema validator like Zod. Next, they implement specific controller methods to call service layers for data retrieval or updates, wrapping operations in performance-tracking spans. Finally, they add detailed logging and custom metrics to monitor API health and diagnose issues efficiently.
How do I handle validation errors in controllers? Use the BaseController’s validation method to check required fields and return standardized 400 responses with detailed error messages. Can I access the database directly from controllers? No, the pattern discourages direct database calls in controllers; use service classes to encapsulate data operations for better separation of concerns. How is error tracking integrated? Errors and warnings are captured via Sentry with contextual tags and breadcrumbs for easier debugging.
Attach this skill to your Metaflow agent task by linking your controller logic and route definitions within the workflow’s service layer. Expect consistent API responses, integrated error monitoring, and validated input handling that align with Metaflow’s observability standards. This setup ensures your service endpoints maintain reliability and traceability across campaigns and data flows.
For broader context, see our roundup of marketing skills claude, and read common Claude Code content mistakes for related setup guidance.