Skip to content

Refactor: adjust simulator and roster apps to adhere to Clean Architecture + added test cases for 100% coverage #306

Merged
IlyaK27 merged 18 commits intomainfrom
305-refactor-simulation-and-rosters
Dec 3, 2025
Merged

Refactor: adjust simulator and roster apps to adhere to Clean Architecture + added test cases for 100% coverage #306
IlyaK27 merged 18 commits intomainfrom
305-refactor-simulation-and-rosters

Conversation

@Xera-phix
Copy link
Collaborator

refactored backend (simulator and roster apps) to clean architecture!

refactors the simulator and roster apps to adhere to clean architecture principles. moved a large chunk of business logic out of views.py and into dedicated service layers so that views remain focused solely on http concerns.

key changes I made:

simulator app

  • service layer: added run_simulation_flow to simulationservice. this handles the full orchestration (fetching players, validation, and simulation).
  • views: removed the _handle_simulation_request helper. endpoints now simply call the service flow thus simplifying views.py even more

roster app

  • ranking logic: created playerrankingservice to handle sorting logic (because lots of it was simply done in views before)
  • view cleanup: removed redundant function-based views (players, player_detail) in favor of the existing playerviewset.
  • new action: replaced standalone ranking views with a new sort_by_woba action on playerviewset.
  • import logic: consolidated csv import logic into a single playerimportservice and updated management commands (there were like three separate instances of this before scattered about.

deletions & cleanup

  • deleted obsolete files: roster/services/importer.py and roster/services/load_csv.py.
  • removed unused and duplicate view functions.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the simulator and roster apps to follow Clean Architecture principles by moving business logic from views into dedicated service layers. The refactoring improves code organization and separation of concerns, though several issues need to be addressed.

Key Changes:

  • Created SimulationService.run_simulation_flow() to orchestrate player fetching, validation, and simulation
  • Introduced PlayerRankingService to encapsulate player sorting logic
  • Consolidated three separate CSV import implementations into a single PlayerImportService
  • Removed redundant function-based views in favor of ViewSet actions
  • Cleaned up views to focus solely on HTTP concerns

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
backend/simulator/views.py Simplified view by delegating business logic to SimulationService; removed PlayerService import and helper function
backend/simulator/services/simulation.py Added run_simulation_flow method to orchestrate the full simulation pipeline including player fetching
backend/roster/views.py Removed redundant function-based views; added sort_by_woba as ViewSet action
backend/roster/urls.py Removed standalone sort-by-woba URL pattern (now handled by ViewSet router)
backend/roster/services/player_ranking.py Added PlayerRankingService class; removed duplicate get_all_players_with_stats function
backend/roster/services/player_import.py New consolidated service replacing importer.py and load_csv.py
backend/roster/services/load_csv.py Deleted obsolete CSV import implementation
backend/roster/services/importer.py Deleted obsolete CSV import implementation
backend/roster/management/commands/import_test_data.py Updated to use new PlayerImportService
Comments suppressed due to low confidence (1)

backend/roster/services/player_import.py:4

  • Import of 'Tuple' is not used.
from typing import Any, Dict, List, Optional, Tuple

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Xera-phix Xera-phix self-assigned this Dec 2, 2025
@Xera-phix Xera-phix changed the title Refactor: adjust simulator and roster apps to adhere to Clean Architecture Refactor: adjust simulator and roster apps to adhere to Clean Architecture + added test cases for 100% coverage Dec 3, 2025
Copy link
Collaborator

@IlyaK27 IlyaK27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good changes Luke! Thanks for implementing what we talked about on call.

@IlyaK27 IlyaK27 merged commit 2851819 into main Dec 3, 2025
1 check passed
@leajosephine12 leajosephine12 deleted the 305-refactor-simulation-and-rosters branch January 22, 2026 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: adjust all code in simulation and rosters folder to adhere to cleaner architecture (interactor, presenter, SOLID)

3 participants