The Furniture Store Backend follows a modular Flask architecture using the Application Factory Pattern. The system is organized into logical components with clear separation of concerns, making it maintainable, testable, and scalable.
The application uses the factory pattern to create and configure the Flask app instance. This approach provides flexibility for testing and deployment.
The create_app() function in app/__init__.py serves as the application factory:
app/__init__.py
from flask import Flaskfrom config import Configfrom .exceptions import register_error_handlersfrom .extensions import csrf, db, migratedef create_app(): """ Factory de la aplicación Flask. Crea y configura la instancia de la aplicación Flask, inicializa extensiones y registra blueprints. """ # Create Flask application app = Flask(__name__) # Initialize environment variables app.config.from_object(Config) # Initialize extensions db.init_app(app) migrate.init_app(app, db) csrf.init_app(app) # Import models to register them with SQLAlchemy from . import models # Register error handlers register_error_handlers(app) # Register blueprints from .catalogs.colors import colors_bp app.register_blueprint(colors_bp, url_prefix='/colors') from .catalogs.roles import roles_bp app.register_blueprint(roles_bp, url_prefix='/roles') from .catalogs.wood_types import woods_types_bp app.register_blueprint(woods_types_bp, url_prefix='/wood-types') from .catalogs.unit_of_measures import unit_of_measures_bp app.register_blueprint(unit_of_measures_bp, url_prefix='/unit-of-measures') return app
The factory pattern allows creating multiple app instances with different configurations, which is especially useful for testing and running multiple environments.
This pattern avoids circular import issues and allows the same extension instances to be used across multiple app instances. Extensions are created once and can be initialized with different app configurations.