refactor: split shared.py god module into focused utility modules#245
Open
benjuntilla wants to merge 3 commits intomainfrom
Open
refactor: split shared.py god module into focused utility modules#245benjuntilla wants to merge 3 commits intomainfrom
benjuntilla wants to merge 3 commits intomainfrom
Conversation
- Extract Flask app + CORS config into modules/utils/app.py with ExtendedFlask subclass - Add config singleton to modules/utils/config.py - Add db_connect singleton to modules/utils/db.py - Add token_manager singleton to modules/utils/TokenManager.py - Extract Notion client into modules/utils/notion.py - Move token cleanup scheduler into main.py initialize_app() - Reduce shared.py to thin re-export shim for backward compatibility - Remove shared.pyi (no longer needed with ExtendedFlask subclass) - Fix circular import in TokenManager (import from modules.utils.db instead of shared) Amp-Thread-ID: https://ampcode.com/threads/T-019c4efd-7298-7219-a8fd-4b87c3e8bee1 Co-authored-by: Amp <amp@ampcode.com>
- Move Sentry initialization and create_auth_bot() into main.py
- Update all imports to use modules.utils.{app,config,db,TokenManager,logging_config,notion}
- Rename tokenManager to token_manager everywhere (PEP 8)
Amp-Thread-ID: https://ampcode.com/threads/T-019c4f02-ee9c-74d4-9e35-174c10061404
Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019c4f08-01fd-773b-b695-28d6a1bf88cf Co-authored-by: Amp <amp@ampcode.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
Splits the monolithic
shared.pyinto focused modules, each owning its own singleton instance. This eliminates the central bottleneck, reduces circular dependency risk, and makes the codebase easier to test and reason about.Changes
shared.pymodules/utils/app.pyshared.pymodules/utils/config.pyshared.pymodules/utils/db.pyshared.pymodules/utils/TokenManager.pyshared.pymodules/utils/notion.pycreate_auth_botshared.pyshared.py(kept as re-export shim)shared.pymain.pyinitialize_app()shared.pyi)shared.pyiExtendedFlasksubclassBackward compatibility
shared.pyis kept as a thin re-export shim, so all existingfrom shared import ...statements continue to work without changes. Consumers can be migrated to import directly frommodules/utils/over time.Key fixes
TokenManager._get_db_connect()now imports frommodules.utils.dbinstead ofsharedExtendedFlasksubclass properly typesauth_botandmulti_org_calendar_serviceattributes (eliminatestyerrors)