[AUTO-GUARD-1] Refactor: Application module depends on Infrastructure and TUI layers #9009

Open
opened 2026-04-14 05:25:48 +00:00 by HAL9000 · 0 comments
Owner

Metadata

  • Commit Message: refactor(application): remove direct dependencies on infrastructure and tui layers
  • Branch: refactor/auto-guard-1-application-layer-violations

Background and Context

The application module has direct dependencies on the infrastructure and tui modules, which violates the principles of clean architecture.

The application layer should not have direct knowledge of the infrastructure layer (e.g., database implementations, event bus implementations) or the tui layer (presentation logic). Instead, it should depend on abstractions (e.g., interfaces, ports) defined in the domain layer.

Concrete violations identified:

  • from cleveragents.infrastructure.database.repositories import ... in src/cleveragents/application/container.py
  • from cleveragents.tui.persona.registry import PersonaRegistry in src/cleveragents/application/container.py

These imports invert the correct dependency direction. In clean architecture, the dependency arrow must always point inward — from outer layers (infrastructure, TUI) toward inner layers (application, domain). The application layer importing from infrastructure or tui reverses this and creates tight coupling that makes the system harder to test, maintain, and evolve independently.

Expected Behavior

The application layer depends only on abstractions (protocols/interfaces) defined in the domain layer. Concrete implementations (repositories, event buses, persona registries) are injected at runtime by the composition root, not imported directly by the application layer. The tui layer depends on the application layer — not the other way around.

Acceptance Criteria

  • No import in src/cleveragents/application/ references any symbol from cleveragents.infrastructure.*
  • No import in src/cleveragents/application/ references any symbol from cleveragents.tui.*
  • Repository interfaces (protocols) are defined in the domain layer
  • Concrete repository implementations in infrastructure implement the domain-layer interfaces
  • Dependency injection wires concrete implementations to the application layer at the composition root (outside the application module itself)
  • The tui layer continues to function correctly after the refactor
  • All existing Behave BDD scenarios pass (nox -s unit_tests)
  • All existing Robot Framework integration tests pass (nox -s integration_tests)
  • Test coverage remains ≥ 97% (nox -s coverage_report)
  • nox (all default sessions) passes with no errors

Subtasks

  • Audit all imports in src/cleveragents/application/ and list every cross-layer violation
  • Define repository interfaces (protocols) in src/cleveragents/domain/ for each violated import
  • Update concrete repository implementations in src/cleveragents/infrastructure/ to implement the new domain interfaces
  • Refactor src/cleveragents/application/container.py to depend only on domain-layer abstractions
  • Move or remove the PersonaRegistry dependency from application/container.py; ensure the tui layer wires it in from outside
  • Update the composition root (entry point / DI wiring) to inject concrete implementations
  • Update Behave step definitions and mocks as needed to reflect the new interfaces
  • Run nox -s unit_tests and fix any failures
  • Run nox -s integration_tests and fix any failures
  • Run nox -s coverage_report and verify coverage ≥ 97%
  • Run nox (all default sessions) and fix any remaining errors

Definition of Done

This issue is complete when:

  • All imports in src/cleveragents/application/ are free of references to cleveragents.infrastructure.* and cleveragents.tui.*
  • Repository abstractions exist in the domain layer and are implemented by infrastructure layer classes
  • The composition root (not the application module) performs all concrete dependency wiring
  • All subtasks above are completed and checked off
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit Message**: `refactor(application): remove direct dependencies on infrastructure and tui layers` - **Branch**: `refactor/auto-guard-1-application-layer-violations` ## Background and Context The `application` module has direct dependencies on the `infrastructure` and `tui` modules, which violates the principles of clean architecture. The `application` layer should not have direct knowledge of the `infrastructure` layer (e.g., database implementations, event bus implementations) or the `tui` layer (presentation logic). Instead, it should depend on abstractions (e.g., interfaces, ports) defined in the `domain` layer. **Concrete violations identified:** - `from cleveragents.infrastructure.database.repositories import ...` in `src/cleveragents/application/container.py` - `from cleveragents.tui.persona.registry import PersonaRegistry` in `src/cleveragents/application/container.py` These imports invert the correct dependency direction. In clean architecture, the dependency arrow must always point inward — from outer layers (infrastructure, TUI) toward inner layers (application, domain). The `application` layer importing from `infrastructure` or `tui` reverses this and creates tight coupling that makes the system harder to test, maintain, and evolve independently. ## Expected Behavior The `application` layer depends only on abstractions (protocols/interfaces) defined in the `domain` layer. Concrete implementations (repositories, event buses, persona registries) are injected at runtime by the composition root, not imported directly by the `application` layer. The `tui` layer depends on the `application` layer — not the other way around. ## Acceptance Criteria - [ ] No import in `src/cleveragents/application/` references any symbol from `cleveragents.infrastructure.*` - [ ] No import in `src/cleveragents/application/` references any symbol from `cleveragents.tui.*` - [ ] Repository interfaces (protocols) are defined in the `domain` layer - [ ] Concrete repository implementations in `infrastructure` implement the domain-layer interfaces - [ ] Dependency injection wires concrete implementations to the `application` layer at the composition root (outside the `application` module itself) - [ ] The `tui` layer continues to function correctly after the refactor - [ ] All existing Behave BDD scenarios pass (`nox -s unit_tests`) - [ ] All existing Robot Framework integration tests pass (`nox -s integration_tests`) - [ ] Test coverage remains ≥ 97% (`nox -s coverage_report`) - [ ] `nox` (all default sessions) passes with no errors ## Subtasks - [ ] Audit all imports in `src/cleveragents/application/` and list every cross-layer violation - [ ] Define repository interfaces (protocols) in `src/cleveragents/domain/` for each violated import - [ ] Update concrete repository implementations in `src/cleveragents/infrastructure/` to implement the new domain interfaces - [ ] Refactor `src/cleveragents/application/container.py` to depend only on domain-layer abstractions - [ ] Move or remove the `PersonaRegistry` dependency from `application/container.py`; ensure the `tui` layer wires it in from outside - [ ] Update the composition root (entry point / DI wiring) to inject concrete implementations - [ ] Update Behave step definitions and mocks as needed to reflect the new interfaces - [ ] Run `nox -s unit_tests` and fix any failures - [ ] Run `nox -s integration_tests` and fix any failures - [ ] Run `nox -s coverage_report` and verify coverage ≥ 97% - [ ] Run `nox` (all default sessions) and fix any remaining errors ## Definition of Done This issue is complete when: - All imports in `src/cleveragents/application/` are free of references to `cleveragents.infrastructure.*` and `cleveragents.tui.*` - Repository abstractions exist in the `domain` layer and are implemented by `infrastructure` layer classes - The composition root (not the `application` module) performs all concrete dependency wiring - All subtasks above are completed and checked off - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done --- **Automated by CleverAgents Bot** Agent: new-issue-creator
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#9009
No description provided.