Refactor: Decompose repositories.py into smaller modules #4169

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

The src/cleveragents/infrastructure/database/repositories.py file has been identified as a major violation of the Single Responsibility Principle, the "clear, single purpose per directory" rule, and the 500-line limit guideline.

Issues:

  1. God Module: The file is a massive "god module" that contains 15 different repository classes and 15 custom exception classes. This makes the file extremely difficult to read, understand, and maintain.
  2. File Length: The file is over 6000 lines long, which is a massive violation of the 500-line limit.
  3. Mixed Concerns: The file mixes repository logic for many different domain models, as well as custom exception classes.

Recommendation:

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

  • Create a new repositories directory within src/cleveragents/infrastructure/database.
  • Move each repository class into its own file within the new repositories directory (e.g., project_repository.py, plan_repository.py, etc.).
  • Move all the custom exception classes to a central exceptions module (e.g., src/cleveragents/core/exceptions.py).

This refactoring is critical for improving the architecture of the persistence layer and making the codebase more modular, maintainable, and testable.


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

The `src/cleveragents/infrastructure/database/repositories.py` file has been identified as a major violation of the Single Responsibility Principle, the "clear, single purpose per directory" rule, and the 500-line limit guideline. **Issues:** 1. **God Module:** The file is a massive "god module" that contains 15 different repository classes and 15 custom exception classes. This makes the file extremely difficult to read, understand, and maintain. 2. **File Length:** The file is over 6000 lines long, which is a massive violation of the 500-line limit. 3. **Mixed Concerns:** The file mixes repository logic for many different domain models, as well as custom exception classes. **Recommendation:** Perform a major refactoring of the `repositories.py` file by splitting it into smaller, more focused modules: * Create a new `repositories` directory within `src/cleveragents/infrastructure/database`. * Move each repository class into its own file within the new `repositories` directory (e.g., `project_repository.py`, `plan_repository.py`, etc.). * Move all the custom exception classes to a central exceptions module (e.g., `src/cleveragents/core/exceptions.py`). This refactoring is critical for improving the architecture of the persistence layer and making the codebase more modular, maintainable, and testable. --- **Automated by CleverAgents Bot** Supervisor: Architecture Guard | Agent: ca-architecture-guard
Author
Owner

CLOSED: Consolidated into Epic #4179 - Repositories.py refactoring consolidated into Epic #4179 (Infrastructure Files - Phase 2). Closing as duplicate.

**CLOSED: Consolidated into Epic #4179** - Repositories.py refactoring consolidated into Epic #4179 (Infrastructure Files - Phase 2). Closing as duplicate.
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#4169
No description provided.