UAT: application/container.py violates clean architecture — imports from tui (presentation) layer at lines 116-117 #4127

Closed
opened 2026-04-06 10:30:40 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/clean-arch-application-tui-import
  • Commit Message: fix(application): remove tui layer imports from application container
  • Milestone: (none — backlog)
  • Parent Epic: #868

Background and context

docs/specification.md defines a strict boundary between the Presentation Layer (TUI/CLI) and the Application Layer. All communication between these layers must flow exclusively through the A2A (Agent-to-Agent) Protocol (JSON-RPC 2.0). The application layer must not have direct import dependencies on the TUI/presentation layer.

CONTRIBUTING.md line 402 states: "Clean Architecture: Separate concerns, maintain clear boundaries between layers."

This issue was discovered during UAT testing of code organisation and module structure.

Current behavior (for bugs)

src/cleveragents/application/container.py imports directly from the TUI (presentation) layer at lines 116-117:

from cleveragents.tui.persona.registry import PersonaRegistry
from cleveragents.tui.persona.state import PersonaState

This creates an upward dependency: applicationtui, which violates the clean architecture dependency rule. The application container should not know about TUI-specific concerns like persona registries.

Evidence:

$ grep -n "from cleveragents.tui" src/cleveragents/application/container.py
116:from cleveragents.tui.persona.registry import PersonaRegistry
117:from cleveragents.tui.persona.state import PersonaState

Steps to reproduce:

grep -rn "from cleveragents.tui\|from cleveragents.cli" src/cleveragents/application/ --include="*.py"

Impact:

  • The application layer cannot be used without the TUI layer being present
  • Unit testing the application container requires TUI dependencies
  • Breaks the clean architecture dependency rule defined in the specification

Expected behavior

The application layer must not import from the TUI/presentation layer. PersonaRegistry and PersonaState should either:

  1. Be moved to the domain or application layer (e.g., domain/models/core/persona.py or application/services/persona_service.py), or
  2. Be represented in the application layer as a protocol/interface that the TUI layer implements (dependency inversion principle)

All interaction between the application layer and TUI layer must flow through the A2A protocol as defined in docs/specification.md.

Acceptance criteria

  • src/cleveragents/application/container.py contains no imports from cleveragents.tui.* or cleveragents.cli.*
  • PersonaRegistry and PersonaState are accessible from the application layer without a direct TUI import (via domain model, application service, or protocol/interface)
  • grep -rn "from cleveragents.tui\|from cleveragents.cli" src/cleveragents/application/ returns no results
  • All existing functionality that depends on PersonaRegistry and PersonaState continues to work correctly
  • nox -e typecheck passes with no errors

Subtasks

  • Identify all usages of PersonaRegistry and PersonaState within application/container.py and determine the correct architectural home
  • Move or extract PersonaRegistry and PersonaState to the domain or application layer (or define a protocol/interface)
  • Update application/container.py to import from the new location
  • Update any TUI-layer code that previously defined these classes to import from the new canonical location
  • Tests (Behave): Add/update scenarios verifying the application container can be instantiated without TUI dependencies
  • Tests (Robot): Verify integration tests still pass after the refactor
  • Verify coverage >=97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • 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 (fix(application): remove tui layer imports from application container), 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 (fix/clean-arch-application-tui-import).
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • All nox stages pass
  • Coverage >= 97%

Backlog note: This issue was discovered during autonomous operation
on milestone (UAT sweep — no active milestone). It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/clean-arch-application-tui-import` - **Commit Message**: `fix(application): remove tui layer imports from application container` - **Milestone**: *(none — backlog)* - **Parent Epic**: #868 ## Background and context `docs/specification.md` defines a strict boundary between the Presentation Layer (TUI/CLI) and the Application Layer. All communication between these layers must flow exclusively through the A2A (Agent-to-Agent) Protocol (JSON-RPC 2.0). The application layer must not have direct import dependencies on the TUI/presentation layer. `CONTRIBUTING.md` line 402 states: *"Clean Architecture: Separate concerns, maintain clear boundaries between layers."* This issue was discovered during UAT testing of code organisation and module structure. ## Current behavior (for bugs) `src/cleveragents/application/container.py` imports directly from the TUI (presentation) layer at lines 116-117: ```python from cleveragents.tui.persona.registry import PersonaRegistry from cleveragents.tui.persona.state import PersonaState ``` This creates an upward dependency: `application` → `tui`, which violates the clean architecture dependency rule. The application container should not know about TUI-specific concerns like persona registries. **Evidence:** ``` $ grep -n "from cleveragents.tui" src/cleveragents/application/container.py 116:from cleveragents.tui.persona.registry import PersonaRegistry 117:from cleveragents.tui.persona.state import PersonaState ``` **Steps to reproduce:** ```bash grep -rn "from cleveragents.tui\|from cleveragents.cli" src/cleveragents/application/ --include="*.py" ``` **Impact:** - The application layer cannot be used without the TUI layer being present - Unit testing the application container requires TUI dependencies - Breaks the clean architecture dependency rule defined in the specification ## Expected behavior The application layer must not import from the TUI/presentation layer. `PersonaRegistry` and `PersonaState` should either: 1. Be moved to the domain or application layer (e.g., `domain/models/core/persona.py` or `application/services/persona_service.py`), or 2. Be represented in the application layer as a protocol/interface that the TUI layer implements (dependency inversion principle) All interaction between the application layer and TUI layer must flow through the A2A protocol as defined in `docs/specification.md`. ## Acceptance criteria - [ ] `src/cleveragents/application/container.py` contains no imports from `cleveragents.tui.*` or `cleveragents.cli.*` - [ ] `PersonaRegistry` and `PersonaState` are accessible from the application layer without a direct TUI import (via domain model, application service, or protocol/interface) - [ ] `grep -rn "from cleveragents.tui\|from cleveragents.cli" src/cleveragents/application/` returns no results - [ ] All existing functionality that depends on `PersonaRegistry` and `PersonaState` continues to work correctly - [ ] `nox -e typecheck` passes with no errors ## Subtasks - [ ] Identify all usages of `PersonaRegistry` and `PersonaState` within `application/container.py` and determine the correct architectural home - [ ] Move or extract `PersonaRegistry` and `PersonaState` to the domain or application layer (or define a protocol/interface) - [ ] Update `application/container.py` to import from the new location - [ ] Update any TUI-layer code that previously defined these classes to import from the new canonical location - [ ] Tests (Behave): Add/update scenarios verifying the application container can be instantiated without TUI dependencies - [ ] Tests (Robot): Verify integration tests still pass after the refactor - [ ] Verify coverage >=97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - 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 (`fix(application): remove tui layer imports from application container`), 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 (`fix/clean-arch-application-tui-import`). - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - All nox stages pass - Coverage >= 97% --- > **Backlog note:** This issue was discovered during autonomous operation > on milestone *(UAT sweep — no active milestone)*. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
Author
Owner

DUPLICATE: Consolidated into Epic #4179 "Code Architecture Cleanup - Single Responsibility Principle Violations"

This UAT finding about clean architecture violation in application/container.py is part of the broader architectural cleanup effort. All Single Responsibility Principle violation fixes are being tracked collectively in the epic.

Action: Closing as duplicate in favor of Epic #4179

**DUPLICATE**: Consolidated into Epic #4179 "Code Architecture Cleanup - Single Responsibility Principle Violations" This UAT finding about clean architecture violation in `application/container.py` is part of the broader architectural cleanup effort. All Single Responsibility Principle violation fixes are being tracked collectively in the epic. **Action**: Closing as duplicate in favor of Epic #4179
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.

Blocks
Reference
cleveragents/cleveragents-core#4127
No description provided.