"""init module for the Flask application.""" import logging from flask import Flask from app.config import Config from app.database import engine from app.migrations import run_migrations from app.models import Base from app.views import bp def create_app(): """Create and configure an instance of the Flask application.""" app = Flask(__name__, instance_relative_config=True) app.config.from_object(Config) # Set up Flask logger if not app.logger.handlers: handler = logging.StreamHandler() handler.setFormatter( logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") ) app.logger.addHandler(handler) app.logger.setLevel(logging.DEBUG) # Create database tables if they don't exist Base.metadata.create_all(engine) # Register blueprints app.register_blueprint(bp) # Run migrations after tables are created with app.app_context(): run_migrations(app) app.logger.info("Application initialized successfully") return app