Utilities
The ./design/08_utilities.md
directory contains helper modules, classes, and functions that provide common functionalities used across different parts of the OpenAlgo application. Encapsulating these utilities promotes code reuse and separation of concerns.
Key Utility Modules
Based on the directory listing, here are some of the key utility modules and their likely responsibilities:
utils/env_check.py
:Responsible for loading environment variables from the
.env
file at application startup.Performs checks to ensure essential configuration variables are present and potentially valid.
Called very early in
app.py
.
utils/plugin_loader.py
:Contains logic to dynamically discover and load modules, specifically observed loading broker authentication functions (
load_broker_auth_functions
called inapp.py
).Allows the application to easily recognize and use new broker integrations placed in the
broker/
directory without manual registration in the core code.
utils/session.py
:Provides utilities related to Flask session management.
Likely contains the
@check_session_validity
decorator used to protect routes that require a logged-in user.May include logic for session expiry checks based on the
SESSION_EXPIRY_TIME
config.
utils/latency_monitor.py
:Implements middleware and functions to monitor the processing time of API requests.
Records latency metrics, likely storing them in the database via
database/latency_db.py
.Initialized in
app.py
.
utils/traffic_logger.py
:Implements middleware to log details about incoming HTTP requests and their corresponding responses.
Stores traffic logs, likely using
database/traffic_db.py
.Initialized in
app.py
.
utils/httpx_client.py
:Provides a shared/configured instance of the
httpx
HTTP client library.Using a shared client can improve performance through connection pooling for outgoing HTTP requests (e.g., to broker APIs).
utils/auth_utils.py
:Likely contains helper functions related to authentication or authorization logic that are shared between different modules (e.g., token generation/validation, password complexity checks).
utils/config.py
:Might contain constants or helper functions specifically for accessing or processing configuration values beyond simple
os.getenv
.
utils/constants.py
:Defines constant values used throughout the application (e.g., order statuses, transaction types, exchange names) to avoid hardcoding strings.
utils/version.py
:Provides a mechanism (
get_version()
) to retrieve the application's current version, potentially reading from a file or variable.Used in
app.py
to inject the version into template contexts.
utils/api_analyzer.py
:A potentially large module containing significant logic related to API analysis features, possibly including data processing, calculations, or report generation tied to the
analyzer
blueprint andanalyzer_db
.
Using these utilities helps keep the main application logic in blueprints, database modules, and broker adapters cleaner and more focused on their specific tasks.
Last updated