Intermediate framework layered design — starting from data


I have been thinking about how simple the framework design should be, how to reduce the difficulty of developers, and finally came up with a more satisfactory framework design.

The framework is divided into front-end UI, back-end API and database

Front end UI and back-end API interact through dto model

The back-end API interacts with the database through the ORM model

The relationship between database and ORM model:

In view of the project may reuse multiple databases, back-end engineers may need to master a variety of database SQL statements and the corresponding SQL statement optimization, increasing the difficulty of development.

In view of the ability to master SQL statements and optimize SQL statements, I think the framework should use ORM technology to disassemble data tables into ORM models, and there is no correlation between models.

We get the single table ORM model in the code, and then assemble it into the dto model needed by the foreground.

This idea depends on the idea of DDD domain aggregation. In order to reduce the domain development mode, each single table is regarded as an aggregation root.

This has the following advantages:

  • The execution efficiency of front-end language and database language is not as high as that of back-end language
  • Optimization difficulty: front end > Database > back end
  • The problem is complex and highly concentrated in the back end, which is convenient for debugging and tracking
  • Developers only need to master the corresponding development language and focus on code logic and code optimization


The relationship between dto model obtained by front-end UI and ORM model obtained by back-end API is as follows

The ORM model obtained from the database can be directly transformed into a simple dto model through map, and then the simple dto model is assembled into a complex dto model through code, which is transmitted to the front-end UI to complete the reuse of dto model.


This framework is not designed for Alibaba Tencent, but for small and medium-sized companies to simplify the problem process and speed up development.