Agent skill
service-layer-extraction
Use when a Typer/Click CLI module exceeds 300 LOC with mixed concerns. Extract business logic into a testable service layer.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/service-layer-extraction
Metadata
Additional technical details for this skill
- author
- shimo4228
- version
- 1.0
- extracted
- 2026-02-11
SKILL.md
Service Layer Extraction from CLI
Extracted: 2026-02-11 Context: Refactoring a Typer/Click CLI module to separate business logic into a testable service layer
Problem
CLI modules (e.g., main.py with Typer) accumulate business logic alongside CLI concerns. This makes the logic untestable without CLI runners and blocks reuse from other interfaces (Web UI, SDK).
Solution
Extract business logic into service.py with these translation rules:
| CLI Layer (main.py) | Service Layer (service.py) |
|---|---|
typer.BadParameter |
ValueError |
CLI enums (OutputFormat) |
Plain strings ("tsv", "off") |
console.print() (Rich) |
logger.info() (logging) |
Private names (_collect_files) |
Public names (collect_files) |
Conversion at the boundary (main.py):
# Catch service ValueError, convert to CLI output
try:
files = collect_files(path)
except ValueError as e:
console.print(f"[red]Error:[/red] {e}")
raise typer.Exit(code=1) from e
# Pass enum .value to service layer
result = process_file(quality=quality.value, fmt=fmt.value)
When to Use
- CLI module exceeds ~300 LOC with mixed concerns
- Business logic needs testing without CliRunner
- Planning a second interface (Web UI, API, SDK)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?