Skip to content

Latest commit

 

History

History
49 lines (37 loc) · 4.39 KB

File metadata and controls

49 lines (37 loc) · 4.39 KB

Codebase Refactoring Report: God Object Analysis

This report identifies "God Object" antipatterns in the codebase based on static analysis using radon. The files listed below exhibit high Cyclomatic Complexity (CC), high Lines of Code (LOC), and low Maintainability Index (MI), indicating they violate SOLID and DRY principles by taking on too many responsibilities.

Summary of Top Offenders

The following files are prioritized for refactoring. They are ranked by a "God Score" heuristic (combining LOC and Complexity) and architectural significance.

Priority File Path LOC Max CC Maintainability Issues
1 src/core/domain/translation.py 4446 130 Very Low Massive file likely handling all protocol translations. Violation of Single Responsibility Principle (SRP).
2 src/core/services/backend_service.py 3177 159 Very Low Central service managing backends. High complexity suggests it knows too much about backend implementation details.
3 src/core/cli.py 3187 189 Very Low Entry point containing significant business logic instead of just delegation. High coupling.
4 src/core/services/request_processor_service.py 1485 214 Very Low Extreme local complexity. A single function/block has 214 execution paths. High risk of bugs.
5 src/connectors/openai_codex.py 3963 72 Very Low Monolithic connector implementation. Should be broken down into smaller components.
6 src/core/ports/streaming_contracts.py 1797 111 Very Low Interface definition file that likely contains implementation logic or too many mixed abstractions.
7 src/core/config/app_config.py 2872 45 Very Low Configuration handling should be declarative, but high LOC suggests complex logic for config parsing/validation.
8 src/connectors/hybrid.py 2298 52 Very Low "Hybrid" connector likely mashing multiple strategies together.
9 src/core/services/tool_call_reactor_middleware.py 1629 69 Very Low Middleware doing too much heavy lifting.
10 src/core/di/services.py 2836 60 Low Dependency Injection container configuration. High LOC might indicate manual wiring complexity.

Detailed Analysis & Recommendations

1. src/core/domain/translation.py

  • Problem: With ~4,400 LOC, this file likely contains the translation logic for every supported format (OpenAI, Gemini, Anthropic, etc.).
  • Recommendation: Split into a translation package with separate modules for each format pair (e.g., openai_to_gemini.py, anthropic_to_openai.py). Use a Strategy or Adapter pattern to select the right translator dynamically.

2. src/core/services/backend_service.py

  • Problem: 3,100+ LOC and high complexity. It likely manages lifecycle, selection, failover, and execution for all backends.
  • Recommendation: Extract specific behaviors into smaller services: BackendLifecycleManager, BackendRouter, BackendHealthMonitor.

3. src/core/cli.py

  • Problem: CLI tools should be thin wrappers around services. ~3,200 LOC implies the CLI is implementing business logic directly.
  • Recommendation: Move logic into src/core/services/ or src/core/controllers/. The CLI should only parse arguments and call these services.

4. src/core/services/request_processor_service.py

  • Problem: Max CC of 214 is dangerous. This indicates a massive conditional structure (nested if/else, try/except loops) in a single method.
  • Recommendation: Identify the complex method (likely the main process_request or similar) and apply "Extract Method" refactoring immediately. Break down the flow into a pipeline of smaller steps.

5. src/connectors/openai_codex.py

  • Problem: ~4,000 LOC. Likely a copy-paste heavy implementation or handling too many Codex-specific nuances.
  • Recommendation: Identify shared logic with other OpenAI connectors and move to a base class. Split specific functional areas (e.g., streaming, token counting) into helper classes.

Methodology

  • Cyclomatic Complexity (CC): Measures the number of linearly independent paths through a program's source code.
  • LOC: Logical Lines of Code.
  • Maintainability Index (MI): A composite metric (0-100). Lower is worse. All listed files scored near 0, indicating high technical debt.

Report generated by Droid using radon static analysis.