Skip to content

Refactor Monolithic pt_hub.py into Modular Components #35

@sjackson0109

Description

@sjackson0109

Overview

The main pt_hub.py file is currently 8,082 lines long, making it difficult to maintain, test, and understand. This violates the Single Responsibility Principle and creates maintenance challenges.

Current Issues

  • Monolithic architecture with mixed responsibilities
  • GUI components, business logic, and data handling in one file
  • Difficult to unit test individual components
  • Hard to onboard new contributors
  • Increased risk of merge conflicts

Proposed Refactoring

  1. Separate GUI Components

    • Extract chart/plotting functionality to chart_components.py
    • Move trading controls to trading_gui.py
    • Create settings_gui.py for configuration dialogs
  2. Business Logic Separation

    • Move training logic to training_controller.py
    • Extract order management to dedicated module
    • Create portfolio_manager.py for portfolio operations
  3. Data Layer

    • Separate data models into models/ directory
    • Create dedicated service layer for external API calls
    • Implement proper data validation

Benefits

  • Improved maintainability and readability
  • Better test coverage possibilities
  • Easier parallel development
  • Reduced coupling between components
  • Better separation of concerns

Implementation Strategy

  1. Create new module structure
  2. Gradually extract components with comprehensive tests
  3. Maintain backward compatibility during transition
  4. Update documentation and imports

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions