The Muebles Roble system implements a layered MVC architecture (Model-View-Controller) following the principles of separation of concerns and loose coupling. It uses Jinja2 as the template engine for rendering HTML views.
The system uses the Application Factory Pattern to create and configure the Flask application instance. This pattern allows for flexible configuration and testing.
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 # noqa: F401 # 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') return app
The factory pattern allows multiple instances of the application to be created with different configurations, which is especially useful for testing.