code-structure

Guides extraction of duplicated operational logic from actions into a shared service layer.

Updated May 5, 2026
One-click install
npx skills add https://github.com/josippapez/ai-setup --skill code-structure-josippapez
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-structure
Source: https://github.com/josippapez/ai-setup/tree/main/claude/plugins/dev-core/skills/code-structure
Command: npx skills add https://github.com/josippapez/ai-setup --skill code-structure-josippapez

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? When the same operational logic (sandbox creation, email sending, payment processing) is copy-pasted across multiple action files, bug fixes fail to propagate and behavior drifts. This Skill provides a decision framework for separating domain rules from reusable mechanics. ## Core Features & Use Cases - Two-layer architecture guidance: Actions own domain rules (auth, state transitions, error classification) while a service layer owns reusable mechanics (provider calls, command execution, health checks). - Extraction criteria: Clear triggers for when to extract shared logic (2+ callers) versus when to keep logic in actions (single caller, domain-specific). - Migration checklist: Step-by-step process to extract one capability block, replace one caller, verify, then migrate the rest. - Use Case: You notice sandbox creation code duplicated in three workflow files. Use this Skill to extract composable service functions with explicit parameters and structured returns, keeping orchestration in the actions. ## Quick Start Ask the AI to review where this duplicated logic should live and refactor it into a shared service layer using the code-structure guidelines.

Frequently Asked Questions about code-structure

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

FAQPage Schema
How do I decide between actions and a service layer?

Keep domain rules in actions: auth checks, state transitions, failure classification, and user-facing errors. Move reusable mechanics to the service layer: provider interactions, command execution, and health checks. The rule of thumb is actions own the why and when, services own the how.

When should I extract duplicated code into a shared service?

Extract when the same low-level operation appears in two or more callers, such as sandbox creation or email sending across multiple flows. Skip extraction when logic is genuinely domain-specific with only one caller, since that leads to over-abstraction.

How should service layer functions be designed?

Design service functions as composable capability blocks rather than one monolithic method. Each function accepts explicit parameters, returns structured outputs, never touches the database directly, and surfaces failures as structured results instead of swallowing errors.

What are common service layer anti-patterns?

The main anti-patterns are the god service (one huge function hiding control flow), the leaky service (mutating database tables directly), inconsistent APIs across functions, and over-abstraction by extracting logic used by only one caller.

How do I migrate duplicated logic to a service layer safely?

Write the flow in action code first, mark repeated operational chunks, then extract only the repeated non-domain parts. Replace one caller, verify it works, then migrate the rest, finishing with typecheck and lint to confirm all flows still work.