Welcome to ModularBr

Discover how to implement the ModularBr framework in your Delphi projects.

What is ModularBr?

ModularBr for Delphi offers a modularized solution for two common challenges in API development with Delphi:

  • ROUTES : Modules per route

  • BINDS : Dependency injection

  • IMPORTS : Importing binds exported by other modules

  • ROUTEHANDLERS : Route handler

  • EXPOSEDBINDS : Exporting binds to other modules

ModularBr is a framework that provides a modular development architecture for applications, allowing the separation of resources into independent and interconnected modules. With this architecture, it is possible to achieve benefits such as code organization, greater scalability, easier and clearer maintenance, more efficient testability, and a more agile development process.

With modularization, it is possible to develop and test each module independently, as well as reuse modules in different projects. This approach allows the development team to work on different areas of the application simultaneously, increasing productivity and reducing development time.

ModularBr offers several useful features for developers, such as dependency injection and route-based module management. Dependency injection is a technique that allows easy swapping of class implementations during application execution or API requests, making the code more flexible and modular. Route management enables organized instantiation of modules, providing resources that can be used in a simple, manageable, and decoupled manner. Additionally, ModularBr allows route interception, enabling validation of permissions and user authentication before granting access to certain routes. These features are essential for ensuring scalability and maintainability in more complex projects.

See the benefits of using a modular architecture in your project:

Better understanding of resources

By dividing the scope of resources, it is possible to have a clearer view of each part of the system, which helps in maintaining and evolving the project.

Fewer changes that can break the system

By managing each resource independently, changes in one module do not affect others, reducing the risk of system breaking.

Adding new features without conflicts

With modularization, it is possible to add new features without conflicts, as each module is independent.

Fewer blind spots in the core business rule

By separating resources into modules, it is possible to have a clearer view of the core business rule and avoid blind spots.

Greater developer turnover

With a modular architecture, it is easier for new developers to understand the system and start working on new functionalities.

More readable code and extended project lifespan.

The separation of resources into modules makes the code more readable and facilitates maintenance, extending the project's lifespan.

A practical example of a modular architecture is a standard MVC model with 3 resources (Authentication, Home Page, and Products). With modularization, each resource can be managed independently, without interfering with other parts of the system.

Typical MVC (Model-View-Controller)

projeto
├── models                      # All models
│   ├── auth_model.pas          
│   ├── home_model.pas          
│   └── product_model.pas       
├── controllers                 # All controllers
│   ├── auth_controller.pas     
│   ├── home_controller.pas     
│   └── product_controller.pas  
├── views                       # All views
│   ├── auth_form.pas           
│   ├── home_form.pas           
│   └── product_form.pas        
├── core                        # Tools and utilities
│   ├── database.pas            
│   ├── utils.pas               
│   └── validation.pas          
├── app.pas                     # Main class containing the app logic
└── main.pas                    # Run the application

Above, we presented a common structure using the MVC pattern, which is very useful in virtually all types of applications.

Structure divided by scope

projeto
├── modules                       # All modules
│   ├─ auth                       # Authentication MVC
│   │  ├── auth_model.pas
│   │  ├── auth_controller.pas
│   │  └── auth_form.pas
│   ├─ home                       # Home Page MVC
│   │  ├── home_model.pas
│   │  ├── home_controller.pas
│   │  └── home_form.pas
│   └─ product                    # Product MVC
│      ├── product_model.pas
│      ├── product_controller.pas
│      └── product_form.pas
├── core                          # Tools and utilities
│   ├── database.pas              
│   ├── utils.pas                 
│   └── validation.pas           
├── app.pas                       # Main class containing the application logic
└── main.pas                      # Runs the application

What we did in this structure was to continue using MVC, but this time on a scope basis. This means that each functionality has its own MVC, and this simple approach solves many scalability and maintenance issues. We call this approach "Smart Structure". However, there were still two things that were global and conflicted with the structure itself, so we created ModularBr to resolve this impasse.

In summary, ModularBr is a solution for modularizing the routing system and dependency injection, making each scope have its own routes and injections independent of any other factor in the structure. We created objects to group the Routes and Injections, and we call them Modules.

Ready to get started?

ModularBr is not only brilliant for accomplishing something amazing, like componentizing routes and dependency injections, but also for doing it all in a simple way!

Go to the next topic and begin your journey towards an intelligent structure.

Last updated