Refactor Massive Plan Domain Model #1327

Open
opened 2026-04-02 16:51:22 +00:00 by freemo · 1 comment
Owner

The Plan model in src/cleveragents/domain/models/core/plan.py is a very large and complex class with over 50 fields. This is a violation of the Single Responsibility Principle and makes the code difficult to understand and maintain.

Key Issues:

  • Massive Class: The Plan class is a "god object" that is responsible for too many things.
  • Violation of SRP: The class manages its own identity, lifecycle, project links, invariants, automation profiles, subplans, costs, execution environments, and more.
  • Lack of Cohesion: Many of the fields are not directly related to the core concept of a plan.
  • Mixing of Concerns: The as_cli_dict method is a presentation-layer concern that has been mixed into the domain model.
  • Helper Class in Same File: The SubplanFailureHandler class should be in its own file.

Recommendation:

Refactor the Plan model into a smaller, more focused aggregate root. Extract related fields into separate value objects or entities. For example:

  • Move cost_metadata, skeleton_metadata, and multi_project_metadata to a PlanExecutionDetails entity.
  • Move subplan-related fields to a SubplanManager class.
  • Move execution environment fields to an ExecutionEnvironment value object.
  • Remove the as_cli_dict method and move it to a presentation model or renderer.
  • Move the SubplanFailureHandler class to its own file.
The `Plan` model in `src/cleveragents/domain/models/core/plan.py` is a very large and complex class with over 50 fields. This is a violation of the Single Responsibility Principle and makes the code difficult to understand and maintain. **Key Issues:** * **Massive Class:** The `Plan` class is a "god object" that is responsible for too many things. * **Violation of SRP:** The class manages its own identity, lifecycle, project links, invariants, automation profiles, subplans, costs, execution environments, and more. * **Lack of Cohesion:** Many of the fields are not directly related to the core concept of a plan. * **Mixing of Concerns:** The `as_cli_dict` method is a presentation-layer concern that has been mixed into the domain model. * **Helper Class in Same File:** The `SubplanFailureHandler` class should be in its own file. **Recommendation:** Refactor the `Plan` model into a smaller, more focused aggregate root. Extract related fields into separate value objects or entities. For example: * Move `cost_metadata`, `skeleton_metadata`, and `multi_project_metadata` to a `PlanExecutionDetails` entity. * Move subplan-related fields to a `SubplanManager` class. * Move execution environment fields to an `ExecutionEnvironment` value object. * Remove the `as_cli_dict` method and move it to a presentation model or renderer. * Move the `SubplanFailureHandler` class to its own file.
freemo self-assigned this 2026-04-02 18:45:22 +00:00
Author
Owner

Label compliance fix applied:

  • Removed duplicate label: Type/Task
  • Reason: This issue has both Type/Refactor and Type/Task. Per CONTRIBUTING.md, each issue should have exactly one Type/* label. Since the issue is clearly a refactoring task, Type/Refactor is the more specific and accurate label. Type/Task has been removed.

Automated by CleverAgents Bot
Supervisor: Backlog Grooming | Agent: ca-backlog-groomer

Label compliance fix applied: - Removed duplicate label: `Type/Task` - Reason: This issue has both `Type/Refactor` and `Type/Task`. Per CONTRIBUTING.md, each issue should have exactly one `Type/*` label. Since the issue is clearly a refactoring task, `Type/Refactor` is the more specific and accurate label. `Type/Task` has been removed. --- **Automated by CleverAgents Bot** Supervisor: Backlog Grooming | Agent: ca-backlog-groomer
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#1327
No description provided.