Abstract: Chair, a Web framework based on Node.js, was launched by alipay’s front-end team and is suitable for most Web applications. This article briefly introduces the design idea, functional architecture and development status of Chair. Historically, the front-end projects of Alipay were developed directly based on the Java backend. In this architecture, front-end engineers create web templates (based on Velocity templates…
Chair, a Web framework based on Node.js, is launched by the front-end team of Alipay and is suitable for most Web applications.
This article briefly introduces the design idea, functional architecture and development status of Chair.
Review images
1. The origin and design idea of Chair
Historically, Alipay front-end projects are directly based on Java backend development. In this architecture, the front-end engineer creates web templates (VM files based on the Velocity templating engine) that are rendered by the Back-end Java engine. The Java engine used by Alipay is an MVC framework named Sofa.
Review images
For front end engineers, this architecture has a lot of inconveniences. First, you need to understand the back-end implementation and rely on the DEV server in the development environment for debugging development. Secondly, the development details need to communicate with the backend Java engineers, communication costs are quite large; Finally, it is difficult to initiate technological innovation because it is very difficult to drive when it involves tweaking the back end. Today, with the rapid development of front-end technology, this has become more and more a pain in the heart of front-end engineers.
The Chair framework was born in this context. We hope to accelerate front-end development, improve r&d efficiency, and improve the overall performance of the website and the maintainability of the system by adding a Node layer.
As an alternative to Sofa, Chair communicates directly with the underlying Java service, while the client browser communicates with Chair, eliminating the use of Sofa. This allows front-end engineers to leave Java alone and use the familiar JavaScript language while iterating quickly across the browser and server.
Review images
In fact, the name Chair comes from a contrast to Sofa, in that both seats a person, but Chair is much lighter than Sofa. Alipay already has a sofa, and we want to add a chair to it.
Chair brings a lot of convenience to front-end development.
- Improved r&d efficiency, front-end engineers can directly modify the server, avoiding unnecessary communication costs with the Java back end.
- Clearer division of responsibilities, front-end for presentation layer (View) development, back-end for business and data (Controller and Model) development.
- With better engineering, the front end can do unit testing, integration testing, and automated release on its own.
- To save labor, the same components (such as templates and routes) need to be written once instead of for the browser and the server.
- Expected performance improvements, Node has a strong ability to handle HTTP requests on the server side.
Chair is already in production, and Sofa supports different Alipay Web applications. Expect to see more Chair-based Web applications in the near future.
2, Chair structure
The underlying code for Chair is a redevelopment of the Koa framework using the next generation JavaScript, ECMAScript 6, and the template engine is Nunjucks, but other engines are also available. Also compatible with Velocity templates, most of the existing template files can be rendered without modification.
Review images
From browser to server, the framework is divided into five layers:
- Routers are HTTP requests that adapt to different paths
- Middleware layer (Middlewares) : Processes HTTP requests
- Controllers: Deploy the business logic
- Services: Provides an internal unified API that can be invoked by different businesses
- Proxy layer: Is responsible for communicating with Java services and providing data in a uniform format
In addition to the template engine, Chair deplores functional components such as mock (data simulation) and Logger (logger).
Chair is highly customized based on business requirements and existing architectures. While Chair is structurally capable of providing full back-end functionality, it is currently primarily used for template rendering and routing. The real business logic and data processing is left to the Java services on the back end.
Third, performance improvement
The addition of Node provides significant performance improvements for many functions. According to the pressure test results, the response time and system load capacity of using Chair (Web in the image below) more than doubled when using the original solution (Portal in the image below).
Review images
Review images
Iv. Chair development schedule
In early December, Chair released version 0.5. In addition to Bug fixes, this release mainly adds the following features.
- Cookie Session support, independent of TAIR
- Connect to the MySQL database
- Supports MVC STAT and RPC STAT log statistics
- Supports unified navigation unINAV templates
- Page data emulates Pagemock
Currently, Chair is in intensive development and is expected to release version 1.0.0 in the first half of next year.
The article is from alibaba Technology Association (ATA) collection
Author: Brother Bunny