This article is the 24th day of the 2020 RevComm Advent Calendar. The day before was @ zoetaka38's "Create a serverless API with Swagger with Serverless/Flask".
I'm @ qii-purine, a lead engineer at RevComm. I am usually involved in the development of MiiTel, ranging from creating small functions to code review and product management.
What kind of architecture do you use for development? What did you think about that choice?
This time, I would like to think about the application architecture in a certain situation.
What do you associate with architecture? There are MVC, layered architecture, clean architecture, VIPER and so on. In a broad sense, it extends to DDD, DI, CQRS, object-oriented, aspect-oriented, and design patterns.
In any case, it is devised to easily solve problems during development and operation, and is used in various systems.
Well, I said that I thought about the architecture quickly, but I think that there are various conditions depending on the product.
The conditions this time are like this.
--The language is python. --The framework is django (drf). --Create a Restful API, nothing that returns html. --UnitTest does. --More than 10 people make changes.
This time as a general candidate Consider three things: a pattern that uses drf's ModelViewSet, a layered architecture, and a clean architecture.
Here is the reference. https://www.django-rest-framework.org/api-guide/viewsets/#modelviewset
When building complex logic, the following layered architecture mechanism will be partially introduced.
--Code to create
Use ViewSet, which is the Base Class of ModelViewSet. https://www.django-rest-framework.org/api-guide/viewsets/#viewset-actions
--Code to create --ViewSet (Application layer) --Serializer (Application layer) --UseCase (Domain layer) --Model (Infrastructure layer)
It's an architecture you've heard a lot over the last few years. By using DI well, you can reverse the dependencies of the infrastructure part.
--Code to create
The python mock is reasonably powerful and allows you to mock global variables. This makes it possible to test without depending on infrastructure parts such as DB without reversing the dependencies like the clean architecture.
You don't have to think about changing frameworks or infrastructure that are unlikely to be encountered. Also, creating a common understanding within the team is necessary no matter what you do. If it's not too difficult, the cost to pay is almost the same.
Minimum Viable
Whichever you choose, there are advantages and disadvantages, but the layered architecture seems to be good in terms of code volume. The disadvantage of being difficult to test can also be solved with mock. Also, DI is a mechanism you want depending on the mounting location, so let's make it available.
In summary, is it like this?
--Code to create
What do you think. This time, it fits in the form of layered architecture + DI, but I think that the selection will change depending on the scale of the product, the team structure, and the development period. If you are a few elite and everyone is familiar with drf, ModelViewSet may be sufficient. Alternatively, a clean architecture may be suitable if you have enough time to operate it for a long period of time.
Choose the architecture that suits you.
Tomorrow is the last day. This is an article by @zomaphone. I look forward to working with you.
Recommended Posts