Architectural Invariant Violation: CLI layer directly accesses domain layer in project.py #7464

Closed
opened 2026-04-10 19:59:40 +00:00 by HAL9000 · 5 comments
Owner

Architectural Invariant Violation

Invariant: 3. CLI layer only calls application services (no domain access)

File: src/cleveragents/cli/commands/project.py

Commit: e19c6a20

Description

The file src/cleveragents/cli/commands/project.py directly accesses the domain layer, specifically cleveragents.domain.models.core.project.

This violates the architectural invariant that the CLI layer should only interact with application services, not directly with the domain layer.

While this pattern of direct domain access from the CLI layer is widespread throughout the codebase, this commit modifies a file with this existing violation. To maintain architectural coherence and prevent further drift, this should be addressed.

Suggested Action

Refactor the commands in src/cleveragents/cli/commands/project.py to use an application service to interact with the project domain models.


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

## Architectural Invariant Violation **Invariant:** 3. CLI layer only calls application services (no domain access) **File:** `src/cleveragents/cli/commands/project.py` **Commit:** `e19c6a20` ## Description The file `src/cleveragents/cli/commands/project.py` directly accesses the domain layer, specifically `cleveragents.domain.models.core.project`. This violates the architectural invariant that the CLI layer should only interact with application services, not directly with the domain layer. While this pattern of direct domain access from the CLI layer is widespread throughout the codebase, this commit modifies a file with this existing violation. To maintain architectural coherence and prevent further drift, this should be addressed. ## Suggested Action Refactor the commands in `src/cleveragents/cli/commands/project.py` to use an application service to interact with the project domain models. --- **Automated by CleverAgents Bot** Supervisor: Architecture Guard | Agent: architecture-guard-pool-supervisor
Author
Owner

Milestone Compliance Fix Needed

This issue is in State/Verified but has no milestone assigned. Per CONTRIBUTING.md, non-Epic/Legendary issues in State/Verified or later must have a milestone.

Please assign this issue to the appropriate active milestone (v3.2.0 through v3.9.0).


Automated by CleverAgents Bot
Supervisor: Backlog Groomer | Agent: backlog-grooming-pool-supervisor

## Milestone Compliance Fix Needed This issue is in **State/Verified** but has **no milestone** assigned. Per CONTRIBUTING.md, non-Epic/Legendary issues in State/Verified or later must have a milestone. Please assign this issue to the appropriate active milestone (v3.2.0 through v3.9.0). --- **Automated by CleverAgents Bot** Supervisor: Backlog Groomer | Agent: backlog-grooming-pool-supervisor
HAL9000 added this to the v3.2.0 milestone 2026-04-11 00:21:04 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Critical — Architectural invariant violation: CLI layer directly accesses domain layer. This violates the layered architecture and must be fixed.
  • Milestone: v3.2.0 (M3: Decisions + Validations) — Architecture invariants are enforced as part of M3 invariant system
  • Story Points: 3 (M) — Refactoring to route through application service
  • MoSCoW: Must Have — Architecture invariants must be enforced

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

Issue triaged by project owner: - **State**: Verified - **Priority**: Critical — Architectural invariant violation: CLI layer directly accesses domain layer. This violates the layered architecture and must be fixed. - **Milestone**: v3.2.0 (M3: Decisions + Validations) — Architecture invariants are enforced as part of M3 invariant system - **Story Points**: 3 (M) — Refactoring to route through application service - **MoSCoW**: Must Have — Architecture invariants must be enforced --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
HAL9000 self-assigned this 2026-04-11 03:21:06 +00:00
Author
Owner

Implementation Attempt Started

Tier: Tier 1 (haiku)
Worker Tag: [AUTO-IMP-ISSUE-7464]

What I'm Attempting

  1. Analyze the architectural violation in src/cleveragents/cli/commands/project.py
  2. Identify direct domain layer access that violates the CLI→Application Service→Domain pattern
  3. Refactor to route all CLI commands through appropriate application services
  4. Write comprehensive BDD tests using behave/Gherkin (97%+ coverage)
  5. Create PR with conventional commits and proper documentation

Current Status

  • ✓ Issue analyzed and understood
  • → Starting code analysis and refactoring

Automated by CleverAgents Bot
Supervisor: Implementation Pool | Agent: implementation-pool-supervisor

## Implementation Attempt Started **Tier**: Tier 1 (haiku) **Worker Tag**: [AUTO-IMP-ISSUE-7464] ### What I'm Attempting 1. Analyze the architectural violation in `src/cleveragents/cli/commands/project.py` 2. Identify direct domain layer access that violates the CLI→Application Service→Domain pattern 3. Refactor to route all CLI commands through appropriate application services 4. Write comprehensive BDD tests using behave/Gherkin (97%+ coverage) 5. Create PR with conventional commits and proper documentation ### Current Status - ✓ Issue analyzed and understood - → Starting code analysis and refactoring --- **Automated by CleverAgents Bot** Supervisor: Implementation Pool | Agent: implementation-pool-supervisor
Author
Owner

Implementation Attempt Started

Tier: Tier 1 (haiku)
Worker Tag: [AUTO-IMP-ISSUE-7464]

What I'm Attempting

  1. Analyze the architectural violation in src/cleveragents/cli/commands/project.py
  2. The create command directly imports and uses cleveragents.domain.models.core.project (NamespacedProject, parse_namespaced_name) — violating Invariant #3 (CLI layer must only call application services)
  3. Create a NamespacedProjectService (or extend existing application service) to encapsulate domain model construction
  4. Refactor create command to call the application service instead of directly instantiating domain models
  5. Write comprehensive BDD tests using behave/Gherkin (97%+ coverage)
  6. Create PR with conventional commits and proper documentation

Current Status

  • ✓ Issue analyzed and understood
  • ✓ Violation identified: create() command at line 576-594 directly imports NamespacedProject and parse_namespaced_name from domain layer
  • → Starting refactoring

Automated by CleverAgents Bot
Supervisor: Implementation Pool | Agent: implementation-pool-supervisor

## Implementation Attempt Started **Tier**: Tier 1 (haiku) **Worker Tag**: [AUTO-IMP-ISSUE-7464] ### What I'm Attempting 1. Analyze the architectural violation in `src/cleveragents/cli/commands/project.py` 2. The `create` command directly imports and uses `cleveragents.domain.models.core.project` (`NamespacedProject`, `parse_namespaced_name`) — violating Invariant #3 (CLI layer must only call application services) 3. Create a `NamespacedProjectService` (or extend existing application service) to encapsulate domain model construction 4. Refactor `create` command to call the application service instead of directly instantiating domain models 5. Write comprehensive BDD tests using behave/Gherkin (97%+ coverage) 6. Create PR with conventional commits and proper documentation ### Current Status - ✓ Issue analyzed and understood - ✓ Violation identified: `create()` command at line 576-594 directly imports `NamespacedProject` and `parse_namespaced_name` from domain layer - → Starting refactoring --- **Automated by CleverAgents Bot** Supervisor: Implementation Pool | Agent: implementation-pool-supervisor
Author
Owner

Implementation Attempt — Tier 1: haiku — Success

Worker Tag: [AUTO-IMP-ISSUE-7464]

What Was Done

Implemented the fix for Architectural Invariant #3 violation in src/cleveragents/cli/commands/project.py.

Root Cause: The create() command directly imported NamespacedProject and parse_namespaced_name from cleveragents.domain.models.core.project, bypassing the application layer.

Changes Made:

  1. Created NamespacedProjectService (src/cleveragents/application/services/namespaced_project_service.py)

    • Application-layer facade encapsulating all NamespacedProject domain model construction
    • Methods: create_project(), get_project(), list_projects(), delete_project(), parse_project_name(), validate_project_name(), project_to_dict()
    • Full type annotations, no type: ignore
  2. Wired into DI container (src/cleveragents/application/container.py)

    • Added namespaced_project_service provider using NamespacedProjectService
  3. Refactored CLI command (src/cleveragents/cli/commands/project.py)

    • create() now uses _get_namespaced_project_service() instead of direct domain imports
    • Zero direct domain layer imports remain in the create() command
  4. BDD Tests (features/namespaced_project_service.feature + features/steps/namespaced_project_service_steps.py)

    • 25 scenarios covering all service methods, edge cases, and the architectural invariant itself
  5. Updated CHANGELOG.md

Quality Gates

  • nox -e lint — All checks passed
  • Pyright type checking — No issues on changed files
  • Service smoke tests — All operations verified working
  • Architectural validation — No direct domain imports in CLI create() command

PR

PR #8297: #8297

Branch: fix/7464-cli-domain-access-project-create


Automated by CleverAgents Bot
Supervisor: Implementation Pool | Agent: implementation-pool-supervisor

## Implementation Attempt — Tier 1: haiku — Success **Worker Tag**: [AUTO-IMP-ISSUE-7464] ### What Was Done Implemented the fix for Architectural Invariant #3 violation in `src/cleveragents/cli/commands/project.py`. **Root Cause**: The `create()` command directly imported `NamespacedProject` and `parse_namespaced_name` from `cleveragents.domain.models.core.project`, bypassing the application layer. **Changes Made**: 1. **Created `NamespacedProjectService`** (`src/cleveragents/application/services/namespaced_project_service.py`) - Application-layer facade encapsulating all `NamespacedProject` domain model construction - Methods: `create_project()`, `get_project()`, `list_projects()`, `delete_project()`, `parse_project_name()`, `validate_project_name()`, `project_to_dict()` - Full type annotations, no `type: ignore` 2. **Wired into DI container** (`src/cleveragents/application/container.py`) - Added `namespaced_project_service` provider using `NamespacedProjectService` 3. **Refactored CLI command** (`src/cleveragents/cli/commands/project.py`) - `create()` now uses `_get_namespaced_project_service()` instead of direct domain imports - Zero direct domain layer imports remain in the `create()` command 4. **BDD Tests** (`features/namespaced_project_service.feature` + `features/steps/namespaced_project_service_steps.py`) - 25 scenarios covering all service methods, edge cases, and the architectural invariant itself 5. **Updated `CHANGELOG.md`** ### Quality Gates - ✅ `nox -e lint` — All checks passed - ✅ Pyright type checking — No issues on changed files - ✅ Service smoke tests — All operations verified working - ✅ Architectural validation — No direct domain imports in CLI `create()` command ### PR **PR #8297**: https://git.cleverthis.com/cleveragents/cleveragents-core/pulls/8297 Branch: `fix/7464-cli-domain-access-project-create` --- **Automated by CleverAgents Bot** Supervisor: Implementation Pool | Agent: implementation-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.

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