Skip to main content

Vision General

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.

Architecture Diagram

┌─────────────────────────────────────────────────────────────────┐
│                      WEB BROWSER                                │
│                   (User / Client)                               │
└─────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────┐
│                 WEB APPLICATION (Flask + Jinja2)                │
├─────────────────────────────────────────────────────────────────┤
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐              │
│  │   Colors    │  │  Wood Types │  │  Furniture  │   ...        │
│  │   Module    │  │   Module    │  │   Module    │              │
│  └─────────────┘  └─────────────┘  └─────────────┘              │
├─────────────────────────────────────────────────────────────────┤
│                    VIEW LAYER                                   │
│              (Jinja2 Templates / HTML)                          │
├─────────────────────────────────────────────────────────────────┤
│                    SERVICE LAYER                                │
│              (Business Logic / Validations)                     │
├─────────────────────────────────────────────────────────────────┤
│                    MODEL LAYER                                  │
│                  (ORM SQLAlchemy)                               │
├─────────────────────────────────────────────────────────────────┤
│                    DATABASE                                     │
│                       (MySQL)                                   │
└─────────────────────────────────────────────────────────────────┘

Core Technologies

Flask

Web framework providing routing, request handling, and application structure

SQLAlchemy

ORM for database operations and model definitions

Jinja2

Template engine for rendering dynamic HTML views

Flask-WTF

Form handling with CSRF protection and validation

Application Factory Pattern

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 Flask
from config import Config
from .exceptions import register_error_handlers
from .extensions import csrf, db, migrate

def 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.

Data Flow Patterns

GET Request (Read Operation)

Browser → routes.py → services.py → models/ → Database

Browser ← template.html ← routes.py ← services.py ← models/ ← Data

POST Request (Create Operation)

Browser (Form) → routes.py (receive request.form)

              services.py (business validation)

              models/ (create entity)

              Database (INSERT)

              routes.py → flash() + redirect

Browser ← Redirect to view (PRG Pattern)
The system follows the Post/Redirect/Get (PRG) pattern to prevent duplicate form submissions.

Design Principles

The architecture follows these key design principles:
Each layer has a single, well-defined responsibility. Views handle presentation, services contain business logic, and models manage data persistence.
Layers communicate through well-defined interfaces. Changes in one layer have minimal impact on others.
Related functionality is grouped together in the same module. Each module is self-contained and focuses on a specific domain.
Reusable code is extracted into utilities and shared services to avoid duplication.
Validation happens early in the request lifecycle with clear error messages to improve debugging and user experience.

Next Steps

MVC Layers

Learn about the presentation, service, and model layers

Module Organization

Understand how modules are structured and organized

Database Models

Explore the data models and their relationships

Error Handling

Learn about the exception hierarchy and error management

Build docs developers (and LLMs) love