Skip to content

Eliminate mixins and move to pure service architecture #200

@astrogilda

Description

@astrogilda

Problem

The codebase currently uses an inconsistent hybrid approach with both mixins and services, creating architectural complexity and maintenance burden.

Issues with Current Architecture

  1. Fragile Mixin Dependencies: Mixins like StationarityMixin blindly assume host classes have certain attributes (self.residuals) without explicit contracts

  2. Multiple Inheritance Complexity: Diamond inheritance patterns create MRO issues and unpredictable behavior

  3. Single Responsibility Violations: Classes like BaseTimeSeriesBootstrap (737 lines) and TimeSeriesModel (770 lines) violate SRP by handling validation, serialization, sklearn compatibility, bootstrap logic, and state management

  4. Inconsistent Pattern Usage: Some functionality uses services, others use mixins, creating confusion about architectural direction

Concrete Examples

Hidden Dependencies in Mixins - StationarityMixin assumes self.residuals exists
Complex Multiple Inheritance - WholeResidualBootstrap inherits from ModelBasedBootstrap AND WholeDataBootstrap
God Object Pattern - TimeSeriesModel has 770 lines doing everything

Solution: Pure Service Architecture

Move to a 100% service-based architecture with explicit dependencies and single inheritance only.

Benefits

  1. Explicit Dependencies: Services declare exactly what they need
  2. Easy Testing: Each service can be tested in isolation
  3. Clear Contracts: No hidden assumptions about host class structure
  4. Single Inheritance: Eliminates MRO complexity
  5. Modular Composition: Features composed through service injection

Migration Plan

Phase 1: Extract Mixin Functionality to Services

  • StationarityMixin → StationarityTestingService
  • WholeDataBootstrap → WholeDataResamplingService
  • BlockBasedBootstrap → BlockResamplingService

Phase 2: Eliminate Multiple Inheritance

  • Each bootstrap class inherits only from BaseTimeSeriesBootstrap
  • Behavior differences achieved through service composition
  • Update all concrete bootstrap implementations

Phase 3: Decompose Monoliths

  • Break down TimeSeriesModel into focused services
  • Simplify BaseTimeSeriesBootstrap to pure orchestration

Phase 4: Update Tests and Documentation

  • Update all tests to work with new service architecture
  • Update documentation to reflect architectural changes
  • Add migration guide for users

Success Criteria

  • Zero mixins in the codebase
  • All classes use single inheritance only
  • Service container pattern used throughout
  • All tests pass with new architecture
  • Performance benchmarks show no regression
  • Clear migration path for users

This refactoring will result in a much more maintainable, testable, and understandable codebase that follows clear architectural principles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions