Skip to content

refactor: split shared.py god module into focused utility modules#245

Open
benjuntilla wants to merge 3 commits intomainfrom
refactor/split-shared-module
Open

refactor: split shared.py god module into focused utility modules#245
benjuntilla wants to merge 3 commits intomainfrom
refactor/split-shared-module

Conversation

@benjuntilla
Copy link
Member

Summary

Splits the monolithic shared.py into 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

Responsibility Old location New location
Flask app + CORS shared.py modules/utils/app.py
Config singleton shared.py modules/utils/config.py
DB connection singleton shared.py modules/utils/db.py
TokenManager singleton shared.py modules/utils/TokenManager.py
Notion client shared.py modules/utils/notion.py
Sentry init, create_auth_bot shared.py shared.py (kept as re-export shim)
Cleanup scheduler shared.py main.py initialize_app()
Type stubs (shared.pyi) shared.pyi Removed — replaced by ExtendedFlask subclass

Backward compatibility

shared.py is kept as a thin re-export shim, so all existing from shared import ... statements continue to work without changes. Consumers can be migrated to import directly from modules/utils/ over time.

Key fixes

  • Circular import in TokenManager._get_db_connect() now imports from modules.utils.db instead of shared
  • ExtendedFlask subclass properly types auth_bot and multi_org_calendar_service attributes (eliminates ty errors)

- 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>
@benjuntilla benjuntilla requested a review from a team as a code owner February 11, 2026 23:20
return False


import modules.auth.models # noqa: F401, E402
benjuntilla and others added 2 commits February 11, 2026 16:26
- 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>
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.

1 participant