Application initialization

Every SPLENT product includes an __init__.py file that defines how the application is created and initialized. This file implements the Flask Application Factory pattern, which allows the application to be created in a structured and extensible way.

The factory is responsible for:

  • Creating the Flask application
  • Loading configuration
  • Initializing core services
  • Registering features

All SPLENT products follow the same initialization structure.


Table of contents

  1. The application factory
  2. Initialization sequence
    1. Namespace initialization
    2. Configuration loading
    3. Database initialization
    4. Session initialization
    5. Logging configuration
    6. Error handlers
    7. Jinja context
    8. Feature registration
  3. Generated automatically

The application factory

The entry point of a SPLENT product is the create_app() function.

def create_app(config_name="development"):
    app = Flask(__name__)

    _init_namespaces(app)
    _load_config(app, config_name)
    _init_db(app)
    _init_sessions(app)
    _init_logging(app)
    _init_error_handlers(app)
    _init_jinja_context(app)
    _init_features(app)

    return app

This function creates the Flask application and then executes a sequence of initialization steps managed by the SPLENT framework.

Initialization sequence

During startup, SPLENT performs the following steps:

create_app()
   │
   ├─ NamespaceManager
   ↓
   ├─ ConfigManager
   ↓
   ├─ MigrateManager
   ↓
   ├─ SessionManager
   ↓
   ├─ LoggingManager
   ↓
   ├─ ErrorHandlerManager
   ↓
   ├─ JinjaManager
   ↓
   └─ FeatureManager

Each step is handled by a dedicated manager.

Namespace initialization

NamespaceManager.init_app(app)

Initializes the internal namespace structure used by SPLENT to organize features and modules.

Configuration loading

ConfigManager.init_app(app, config_name)

Loads the product configuration and injects it into app.config.

Configuration is resolved using:

  • the selected environment (development, production, etc.)
  • the SPLENT_APP environment variable

Database initialization

MigrateManager(app)

Initializes the database layer and migration system.

This manager prepares the application for database usage and schema migrations.

Session initialization

SessionManager(app)

Initializes the session system used by the application.

Depending on the configuration, sessions may use different backends such as Redis.

Logging configuration

LoggingManager(app).setup_logging()

Configures the logging system for the application.

This includes log formatting, handlers, and log levels.

Error handlers

ErrorHandlerManager(app).register_error_handlers()

Registers global error handlers for common HTTP errors and application exceptions.

Jinja context

context = {"SPLENT_APP": os.getenv("SPLENT_APP")}
JinjaManager(app, context)

Adds global variables to the Jinja template context.

In this example, the current product name (SPLENT_APP) becomes available in templates.

Feature registration

FeatureManager(app, strict=False).register_features()

Loads and registers all features enabled for the product.

The FeatureManager is responsible for:

  • discovering installed features
  • loading their blueprints
  • initializing their services
  • applying feature configuration

This step effectively activates the modular functionality of the application.

Generated automatically

The init.py file is generated automatically when a product is created with the SPLENT CLI.

Developers normally do not need to modify this file, since it already contains the standard initialization pipeline used by all SPLENT applications.