Mvc + Http Routing

R3zk0n · October 2, 2025

Contents

    MVC, Metadata-Driven Architecture and HTTP Routing

    Model-View-Controller Introduction

    • Input –> Process –> Output
    • Allows reusability in code, data is pulled from a central location and then reused throughout the application
    • http://ootips.org/mvc-pattern.html

    Controller

    • In the context of a web application, the controller handles the input received from the user.
    • This could be in the form of a HTTP route (i.e /user/update) or via a parameter (i.e. /me?action=update).
    • Regardless of the input method, the controller maps the user’s input to the function(s) that will be executed. Any user input logic is handled by the controller.

    Model

    • The model in Model-View-Controller maps data to a specific object and defines the logic that is needed to process the data

    View

    • The view is the final output that is provided to the user. In the context of a web application, this can be the HTML, XML, or any other final representation that is provided to the user to be consumed

    To put it all together:

    • The user interacts with a website’s view and the interaction is sent as a request to the controller.
    • The controller parses the user’s interaction and requests the data from the model.
    • The model provides the requested data.
    • The controller renders a view using the provided data and responds back to the user.

    Metadata-driven design patterns**

    A metadata-driven design pattern creates a layer of abstraction that eases the new application development process. An example would be Salesforce, that allows multiple users to have customised design suites. This also allows reuse of the same framework for different industries.

    • Frappe serves as the “kernel” –> central and important part, which DocType allows creation of Metadata documents.
    • DocTypes can be viewed in the application, and are accompanied with .py files that add more functions.

    HTTP Routing

    • In modern web applications, HTTP routing is used to map HTTP requests to their corresponding functions

    • Frappe uses a Python decorator with the function name whitelist to expose API endpoints.
    • This function is defined in apps/frappe/frappe/init.py.
    • This means that the client can call any Frappe function directly if the @frappe.whitelist() decorator is in use for that function. In addition, if “allow_guest=True” is also passed in the decorator, the user does not have to be authenticated to run the function.

    Twitter, Facebook