Refactor: Decouple CLI from Application Services #8880

Open
opened 2026-04-14 03:18:12 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit Message: refactor(cli): decouple CLI commands from application services via command bus
  • Branch: refactor/decouple-cli-from-application-services

Background and Context

The CLI command files directly import and call services from the application.services layer. This creates a tight coupling between the CLI and the application logic, which violates the principles of layered architecture.

Evidence:

The following imports were found in src/cleveragents/cli/commands/plan.py:

  • from cleveragents.application.services.plan_lifecycle_service import PlanLifecycleService
  • from cleveragents.application.services.plan_service import PlanService
  • from cleveragents.application.services.project_service import ProjectService

Impacted Files:

  • src/cleveragents/cli/commands/plan.py
  • Other files in src/cleveragents/cli/commands/ may also be affected.

Recommended Remediation:

  • Introduce a command bus or a similar pattern to decouple the CLI from the application services. The CLI should dispatch commands, and the application services should handle them.
  • The CLI should not have any direct dependencies on the application services.
  • Refactor the existing CLI commands to use the new decoupling mechanism.

Relevant Specification Sections:

  • ADR-001-layered-architecture.md

Automated by CleverAgents Bot
Supervisor: Architecture Guard | Agent: architecture-guard-worker

Expected Behavior

The CLI layer (src/cleveragents/cli/) does not directly import or instantiate any class from src/cleveragents/application/services/. All CLI commands dispatch requests through an intermediary (e.g., a command bus, facade, or mediator), and the application services handle those requests independently.

Acceptance Criteria

  • No direct imports of cleveragents.application.services.* exist in any file under src/cleveragents/cli/commands/
  • A command bus or equivalent decoupling mechanism is introduced and documented
  • All existing CLI commands in src/cleveragents/cli/commands/plan.py are refactored to use the new mechanism
  • All other CLI command files under src/cleveragents/cli/commands/ are audited and refactored as needed
  • Existing tests pass; new unit tests cover the command bus dispatch path
  • Architecture linting / import boundary checks confirm no cross-layer violations remain

Subtasks

  • Audit all files in src/cleveragents/cli/commands/ for direct application.services imports
  • Design and implement a command bus or mediator pattern in an appropriate layer
  • Refactor src/cleveragents/cli/commands/plan.py to dispatch via the command bus
  • Refactor any other impacted CLI command files identified in the audit
  • Update or add unit tests for the new dispatch mechanism
  • Verify no remaining cross-layer import violations with a static analysis check
  • Update ADR-001-layered-architecture.md or relevant docs if the pattern changes the architecture

Definition of Done

This issue should be closed when:

  1. No file under src/cleveragents/cli/ directly imports from src/cleveragents/application/services/
  2. A command bus or equivalent decoupling mechanism is in place and tested
  3. All CLI commands have been refactored to use the new mechanism
  4. CI passes (tests + linting + import boundary checks)
  5. The change is reviewed and merged to main

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit Message**: `refactor(cli): decouple CLI commands from application services via command bus` - **Branch**: `refactor/decouple-cli-from-application-services` ## Background and Context The CLI command files directly import and call services from the `application.services` layer. This creates a tight coupling between the CLI and the application logic, which violates the principles of layered architecture. **Evidence:** The following imports were found in `src/cleveragents/cli/commands/plan.py`: * `from cleveragents.application.services.plan_lifecycle_service import PlanLifecycleService` * `from cleveragents.application.services.plan_service import PlanService` * `from cleveragents.application.services.project_service import ProjectService` **Impacted Files:** * `src/cleveragents/cli/commands/plan.py` * Other files in `src/cleveragents/cli/commands/` may also be affected. **Recommended Remediation:** * Introduce a command bus or a similar pattern to decouple the CLI from the application services. The CLI should dispatch commands, and the application services should handle them. * The CLI should not have any direct dependencies on the application services. * Refactor the existing CLI commands to use the new decoupling mechanism. **Relevant Specification Sections:** * ADR-001-layered-architecture.md --- **Automated by CleverAgents Bot** Supervisor: Architecture Guard | Agent: architecture-guard-worker ## Expected Behavior The CLI layer (`src/cleveragents/cli/`) does not directly import or instantiate any class from `src/cleveragents/application/services/`. All CLI commands dispatch requests through an intermediary (e.g., a command bus, facade, or mediator), and the application services handle those requests independently. ## Acceptance Criteria - [ ] No direct imports of `cleveragents.application.services.*` exist in any file under `src/cleveragents/cli/commands/` - [ ] A command bus or equivalent decoupling mechanism is introduced and documented - [ ] All existing CLI commands in `src/cleveragents/cli/commands/plan.py` are refactored to use the new mechanism - [ ] All other CLI command files under `src/cleveragents/cli/commands/` are audited and refactored as needed - [ ] Existing tests pass; new unit tests cover the command bus dispatch path - [ ] Architecture linting / import boundary checks confirm no cross-layer violations remain ## Subtasks - [ ] Audit all files in `src/cleveragents/cli/commands/` for direct `application.services` imports - [ ] Design and implement a command bus or mediator pattern in an appropriate layer - [ ] Refactor `src/cleveragents/cli/commands/plan.py` to dispatch via the command bus - [ ] Refactor any other impacted CLI command files identified in the audit - [ ] Update or add unit tests for the new dispatch mechanism - [ ] Verify no remaining cross-layer import violations with a static analysis check - [ ] Update `ADR-001-layered-architecture.md` or relevant docs if the pattern changes the architecture ## Definition of Done This issue should be closed when: 1. No file under `src/cleveragents/cli/` directly imports from `src/cleveragents/application/services/` 2. A command bus or equivalent decoupling mechanism is in place and tested 3. All CLI commands have been refactored to use the new mechanism 4. CI passes (tests + linting + import boundary checks) 5. The change is reviewed and merged to `main` --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.6.0 milestone 2026-04-14 03:26:11 +00:00
Author
Owner

Triage Decision: VERIFIED — MoSCoW/Must Have

Valid architectural refactoring: CLI commands directly importing from application services (bypassing the proper layered architecture) is an architecture violation per ADR-049. This creates tight coupling that makes testing and maintenance harder.

Priority/High — Architecture violations compound over time and are harder to fix later.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Triage Decision: VERIFIED — MoSCoW/Must Have** Valid architectural refactoring: CLI commands directly importing from application services (bypassing the proper layered architecture) is an architecture violation per ADR-049. This creates tight coupling that makes testing and maintenance harder. **Priority/High** — Architecture violations compound over time and are harder to fix later. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#8880
No description provided.