04-service-layer

Move business rules from controllers into services with explicit dependency injection.

Updated Mar 9, 2026
One-click install
npx skills add https://github.com/kennypallchizaca-coder/agentic-full-stack-skills --skill 04-service-layer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: 04-service-layer
Source: https://github.com/kennypallchizaca-coder/agentic-full-stack-skills/tree/main/skills-backend/04-service-layer
Command: npx skills add https://github.com/kennypallchizaca-coder/agentic-full-stack-skills --skill 04-service-layer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Controllers should handle transport concerns, not business decisions. This skill defines a service layer where validations, workflows, calculations, and orchestration live behind a clean use-case boundary with explicit dependency injection and test seams.

Core Features & Use Cases

  • Encapsulates business logic behind a service boundary to enable reuse across controllers, jobs, tests, and event handlers.
  • Provides explicit dependency injection, test seams, and clean DTO/command boundaries.
  • Supports end-to-end workflow orchestration while keeping controllers thin.

Quick Start

Encapsulate business logic in a dedicated service and wire it to a thin controller that handles transport only.

Frequently Asked Questions about 04-service-layer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I move business logic out of controllers into a service layer?

A service layer encapsulates business rules, validations, and workflows behind a clean boundary using explicit dependency injection. It separates business logic from HTTP transport concerns, enabling controllers to remain thin while services orchestrate workflows across multiple endpoints.

Why should backend architecture separate business rules from controllers?

Separating business rules from controllers improves reusability, testability, and independence from HTTP transport layers. By establishing clear service boundaries, you can reuse the same business logic across jobs, tests, and event handlers without duplicating transport-specific code.

How do I set up dependency injection for service layer testability?

Setting up dependency injection for testability requires defining explicit test seams and clean DTO/command boundaries. Injecting dependencies directly into services allows you to isolate business logic during unit testing without relying on HTTP transport mechanisms.

Can I reuse a backend service layer across event handlers and jobs?

Yes, you can reuse a service layer across event handlers, jobs, and tests. Encapsulating business logic behind a clean use-case boundary with explicit dependencies keeps services independent of HTTP transport and accessible to multiple endpoint consumers.

What is the best way to orchestrate workflows across multiple endpoints?

The best way to orchestrate workflows across multiple endpoints is consolidating them within a dedicated service layer. This ensures end-to-end workflow orchestration remains decoupled from transport layers, allowing thin controllers to delegate business decisions efficiently.

When should I not use a service layer in backend architecture?

You might avoid a service layer if your application lacks complex business rules or requires only basic transport handling without validations or orchestration. Implementing explicit dependency injection and service boundaries adds architectural overhead unnecessary for simple logic.