Answer the question
In order to leave comments, you need to log in
How to organize the project in such a way that when developing modules, it does not require the project itself?
In a Python project, I'm trying to follow the MVC approach. The project has grown and adding functionality to it to solve specific problems has become unprofitable. I decided to try adding the ability to create modules.
I made a modules folder and import its contents based on the names of the subfolders. That is, you create a folder with a specific name, and through this name, the module is imported and activated.
The module pulls controllers from the main project for its work. Access to the database is also through controllers.
How best to distribute the main project, so that it is convenient to write modules. Everything is simple for me, everything is in one repository. But what if there is no access to the repository, but only a truncated copy of the project?
Answer the question
In order to leave comments, you need to log in
The module pulls controllers from the main project for its work.
You contradict yourself:
It turns out that your module will not be able to work without a project. Generally.
It seems to me that you should make modules smaller so that they solve only some specific small task.
Look in the direction of how the Middleware mechanism in Django is arranged - there is a list of middleware and the request is sequentially passed to each of them, and the modified request returned is passed to the next one.
Regarding access to the database, Django is also a good example. During initialization, a connection to the database is opened and placed in some configuration storage, from where it can be taken by modules and used. So, with separate development of modules, it will be possible to put your own, but in the assembled project the global one will be used, which will reduce the time to open the connection.
In order to build the development of such modules - designate a clear interface for each type of module. For example, the modules responsible for working with the user receive a user object as input and also give the user object, but either do something along the way, or somehow modify it.
Well, here, in my opinion, there is only one answer - this is SOLID and clean architecture . This approach will allow you to develop a testable and extensible application.
For example, the fact that your application accesses the database from the controllers is no longer good, since to test the business logic you will have to use the infrastructure, namely http. On a good note, you should have a business logic layer that is injected into the controller, and a business logic layer should be injected into, for example, a data access layer. Thus, you can test any layer independently of each other, since you will have loose coupling of system components.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question