Skip to content

Refactor client connection management and improve code formatting - #88

Open
NanaMein wants to merge 10 commits into
devfrom
chore/regintel-init-connection
Open

Refactor client connection management and improve code formatting#88
NanaMein wants to merge 10 commits into
devfrom
chore/regintel-init-connection

Conversation

@NanaMein

@NanaMein NanaMein commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR introduces clean architectural decoupling for connection management by migrating application startup/shutdown logic into a dedicated lifespan module and utilizing a centralized global application state (app_state).

Key Changes

  • Reduced main.py Verbosity: Extracted FastAPI lifespan context manager logic into a new dedicated module (app/core/lifespan.py).
  • Centralized Application State (app_state): Introduced a global state container to manage heavy client instances (Database/PGVectorStore, Groq LLM client, etc.).
  • Decoupled from Request Context: Eliminated the need for services and classes to depend on or extract connections from the FastAPI Request object.
  • Eager Initialization: Ensured all external connections and sockets are fully initialized during server startup before the application accepts any incoming HTTP traffic.

Benefits

  • Better Performance & Cleanliness: Avoids lazy-loading overhead or request-scoped connection passing.
  • Maintainability: Clear separation of concerns between HTTP routing (main.py), startup lifecycle (lifespan.py), and service logic.

@NanaMein NanaMein self-assigned this Aug 6, 2026
@NanaMein NanaMein added the Area: Backend/RegIntel Policy ingestion & normalization label Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Backend/RegIntel Policy ingestion & normalization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant