Refactor: break up messages_service.py monolith into domain modules#195
Merged
Refactor: break up messages_service.py monolith into domain modules#195
Conversation
Extract ~1200 lines from the 3155-line messages_service.py god module: - Create common/utils/firestore_helpers.py with shared Firestore utilities (doc_to_json, doc_to_json_recursive, hash_key, log_execution_time, cache mgmt) - Create services/hackathons_service.py with 17 hackathon functions (~600 lines) - Expand services/nonprofits_service.py with 10 raw-Firestore nonprofit functions - Redirect 9 re-exported imports in teams_service.py to their real sources - Redirect newsletter_service.py imports to db.db No API routes, URLs, or behavior changes. All 17 existing tests pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Extract 8 team functions into services/teams_service.py (~480 lines) - Extract 6 email functions into services/email_service.py (~260 lines) - Move get_db() import to db.db (eliminate local duplicate) - Deduplicate add_utm() helper (was copied in hackathons_service) - Update imports in messages_views, judging_service, teams_service - Remove unused imports from messages_service (github, slack, oauth) - messages_service.py reduced from ~1970 to ~1200 lines Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Extract news/praise functions into services/news_service.py (~150 lines) - Extract feedback functions into services/feedback_service.py (~140 lines) - Extract giveaway functions into services/giveaway_service.py (~75 lines) - Extract onboarding feedback into services/onboarding_service.py (~90 lines) - Clean up unused imports from messages_service.py - messages_service.py reduced from ~1200 to ~760 lines (3155 → 760 total, 76% reduction) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Breaks up the
messages_service.pymonolith (originally 3155 lines, ~68 functions) into proper domain modules, reducing it to ~1200 lines (62% reduction).Phase 1: Foundation
common/utils/firestore_helpers.py): Extracteddoc_to_json,doc_to_json_recursive,hash_key,log_execution_time,clear_all_cachesservices/hackathons_service.py): Extracted 17 hackathon functions (~600 lines)services/nonprofits_service.py): Merged 10 raw-Firestore functions from messages_serviceapi/teams/,api/newsletters/,api/judging/to real sourcesPhase 2: Teams & Email
services/teams_service.py): Extracted 8 team functions (~480 lines)services/email_service.py): Extracted 6 email/lead functions (~260 lines)add_utm()consolidated from 2 copies intoemail_service.pyWhat remains in messages_service.py (~1200 lines):
_oldfunctions)Files changed
common/utils/firestore_helpers.pyservices/hackathons_service.pyservices/teams_service.pyservices/email_service.pyservices/nonprofits_service.pyapi/messages/messages_service.pyapi/messages/messages_views.pyapi/judging/judging_service.pyapi/teams/teams_service.pyapi/newsletters/newsletter_service.pyTest plan
pytest— all tests pass (same pre-existing failures, no regressions)🤖 Generated with Claude Code