Refactor: Decompose plan.py into smaller modules #4161

Closed
opened 2026-04-06 12:03:29 +00:00 by freemo · 1 comment
Owner

The src/cleveragents/domain/models/core/plan.py file has been identified as a major violation of the Single Responsibility Principle and the 500-line limit guideline.

Issues:

  1. Mixed Concerns: The file mixes a large number of distinct concerns:
    • Data Models: NamespacedName, PlanIdentity, PlanTimestamps, ProjectLink, PlanInvariant, AutomationProfileRef, SubplanAttempt, SubplanStatus, SubplanConfig, and Plan.
    • Enums: PlanPhase, ProcessingState, ExecutionEnvironment, ExecutionEnvPriority, ExecutionMode, SubplanMergeStrategy, InvariantSource, and AutomationProfileProvenance.
    • Business Logic: The SubplanFailureHandler class contains business logic for handling subplan failures.
  2. File Length: The file is over 1200 lines long, which makes it extremely difficult to read, understand, and maintain.

Recommendation:

Perform a major refactoring of the plan.py file by splitting it into smaller, more focused modules:

  • Move the enums to src/cleveragents/domain/models/core/enums.py or a new plan_enums.py file.
  • Move the SubplanFailureHandler class to the src/cleveragents/application layer, possibly in a new plans package.
  • Group the related models into smaller files based on their functionality (e.g., plan_identity.py, plan_lifecycle.py, subplan.py).

This refactoring is critical for improving the architecture of the plan-related domain models and making the codebase more modular and maintainable.


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

The `src/cleveragents/domain/models/core/plan.py` file has been identified as a major violation of the Single Responsibility Principle and the 500-line limit guideline. **Issues:** 1. **Mixed Concerns:** The file mixes a large number of distinct concerns: * **Data Models:** `NamespacedName`, `PlanIdentity`, `PlanTimestamps`, `ProjectLink`, `PlanInvariant`, `AutomationProfileRef`, `SubplanAttempt`, `SubplanStatus`, `SubplanConfig`, and `Plan`. * **Enums:** `PlanPhase`, `ProcessingState`, `ExecutionEnvironment`, `ExecutionEnvPriority`, `ExecutionMode`, `SubplanMergeStrategy`, `InvariantSource`, and `AutomationProfileProvenance`. * **Business Logic:** The `SubplanFailureHandler` class contains business logic for handling subplan failures. 2. **File Length:** The file is over 1200 lines long, which makes it extremely difficult to read, understand, and maintain. **Recommendation:** Perform a major refactoring of the `plan.py` file by splitting it into smaller, more focused modules: * Move the enums to `src/cleveragents/domain/models/core/enums.py` or a new `plan_enums.py` file. * Move the `SubplanFailureHandler` class to the `src/cleveragents/application` layer, possibly in a new `plans` package. * Group the related models into smaller files based on their functionality (e.g., `plan_identity.py`, `plan_lifecycle.py`, `subplan.py`). This refactoring is critical for improving the architecture of the plan-related domain models and making the codebase more modular and maintainable. --- **Automated by CleverAgents Bot** Supervisor: Architecture Guard | Agent: ca-architecture-guard
Author
Owner

CLOSED: Consolidated into Epic #4179

This individual refactoring issue has been consolidated into Epic #4179: "Code Architecture Cleanup - Single Responsibility Principle Violations" along with 15+ other similar Architecture Guard issues.

Rationale for Consolidation:

  • All Architecture Guard refactoring issues follow the same pattern and principles
  • Easier to manage as a single architectural cleanup effort
  • Reduces issue noise while preserving the work scope
  • Allows phased implementation based on priority

See Epic #4179 for the consolidated approach and implementation strategy.

Closing as duplicate/consolidated.

**CLOSED: Consolidated into Epic #4179** This individual refactoring issue has been consolidated into Epic #4179: "Code Architecture Cleanup - Single Responsibility Principle Violations" along with 15+ other similar Architecture Guard issues. **Rationale for Consolidation:** - All Architecture Guard refactoring issues follow the same pattern and principles - Easier to manage as a single architectural cleanup effort - Reduces issue noise while preserving the work scope - Allows phased implementation based on priority **See Epic #4179** for the consolidated approach and implementation strategy. Closing as duplicate/consolidated.
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#4161
No description provided.