Bootstrapping full-stack web applications following domain-driven design with domainfstool

BOOTSTRAPPING FULL-STACK WEB APPLICATIONS  
FOLLOWING DOMAIN-DRIVEN DESIGN WITH  
DOMAINFSTOOL  
SVTH: Đỗ Hải Bì nh  
GVHD: TS Lê Minh Đức  
Tó m tắt: Phá t triển phần mềm đã trở thành một ngành cô ng nghiệp hiện đại, giúp thu về lợi  
nhuận cao. Tuy nhiên, có nhiều tá c vụ trong phá t triển phần mềm lặp đi lặp lại nhưng không thể sao  
ché p nguyên bản vì cá c vấn đề này khô ng hoàn toàn giống nhau. Do vậy, ngành cô ng nghiệp phần  
mềm đã đưa ra khái niệm framework, một cô ng cụ hỗ trợ phá t triển ứng dụng. Trong bản bá o cá o này,  
một cô ng cụ tương tự, DomainFSTool (Domain-driven Full-Stack Tool) sẽ được đưa ra bàn luận.  
Abstract: Software development has become a large business, contributing a high portion of  
global revenue. In software development, several tasks are similar across specific applications;  
however, they are not fully reusable due to subtle differences between distinct problem domains. To  
address this problem, developing a software framework that helps to bootstrap these similar  
components based on the core domain model is a more viable and effective alternative than  
developing a perfect software product that fits into every possible use case. A generative software  
development utility, DomainFSTool, which stands for Domain-driven Full-Stack Tool, will be briefly  
discussed in this paper.  
Keywords: jDomainApp, DomainFSTool, domain-driven design, full-stack web development,  
Spring Boot, React.js, generative software development.  
1.Introduction  
No matter how large a software product is, the quality of a software product is highly  
dependent on the level of customer satisfaction of how the product resolves a specific  
business problem. To address this problem, Eric Evans, a software engineer, proposed an  
approach called domain driven design which attempts to bridge the gap between the  
developers and domain experts [1]. Ever since the introduction of the term, several software  
frameworks have been adopting this approach. In the Faculty of Information Technology,  
Hanoi University, there is also a framework following domain driven design approach, which  
is jDomainApp by Dr Le Minh Duc. The utility allows bootstrapping a Swing Java  
application from a set of domain models, which helps students of the faculty focus on  
building the correct domain model that accurately reflects the business case. However, one of  
the biggest problems with jDomainApp is the lack of support for the Web. This paper  
proposes a new tool, DomainFSTool, which wraps around jDomainApp and take advantage  
of Spring Boot and React.js to bring Web support to jDomainApp.  
185  
2.Main content  
2.1. The three musketeers: jDomainApp, Spring Boot and React.js  
DomainFSTool is an extension of jDomainApp, which has no support for the Web yet.  
For jDomainApp to work in the Web environment, additional components must also be  
employed. When it comes to Java Web backend development, the Spring framework and its  
descendant, Spring Boot, are among the most popular. Whereas, for the frontend, React.js is  
the hottest Javascript frontend library. The combination of those three big technologies may  
result in a new state-of-the-art full-stack web development toolkit.  
jDomainApp: This Java domain-driven-design application framework has been  
available to Hanoi University students for a while. It promotes the use of domain constraints  
specific language (DCSL), a set of meta-attributes embedded in the domain models.  
Resource-based management systems using Java Swing as the presentation technology  
bootstraps quickly using this utility. Despite developed in the modern setting, the support of  
jDomainApp and its current extensions on the Web is limited. Moreover, the lack of  
documentation and regular support also keeps the framework away from the mainstream  
developer world.  
Spring Boot: Contrary to the unpopularity of jDomainApp, Spring Boot is one of the  
most prominent frameworks in the Java world. Inheriting the best of the Spring framework,  
including the Inversion of Control (IoC) container and Aspect-oriented programming, along  
with lightweight, annotation-based configuration, Spring Boot has gained much attraction  
from the Java developer community. It is also one of the predominant web backend  
technologies on the market, packed with literally all necessary Web development libraries. Its  
market dominance also creates a large community that responds to every problem, which is  
beneficial for the development of DomainFSTool.  
React.js: One of the top trending web frontend frameworks, React.js provides  
component-based view modelling. Along with that is the reactivity powered by virtual DOM  
(Document Object Model), which is its best selling point. Moreover, the use of JSX  
(JavaScript Extension) contributes to the library’s ease of use by a convenient syntax to  
embed HTML into JavaScript. In addition to all aforementioned features, React.js also has a  
large community responsive to bugs and help requests. All of those have highly influenced  
the decision to use React.js for the frontend in DomainFSTool.  
To sum up, the combo of Spring Boot and React.js is perhaps the missing pieces for the  
extension of jDomainApp to the Web platform.  
2.2.  
Bringing domain-driven-design software to the web  
In a short development time, it is impossible to include every functionality of  
186  
jDomainApp. Only a subset of jDomainApp’s functionalities has been selected, including  
automatic software generation from domain model and domain object manipulation (referred  
to as CRUD operations). Following is the discussion of the functionalities implemented in  
DomainFSTool compared to those in jDomainApp.  
2.2.1. Software generation from the domain model  
Modular software generation from a set of domain models is a feature boasted by the  
author of jDomainApp to be much superior compared to its contenders [2]. This function  
employs a predefined set of meta-attributes to be scanned by the framework to generate  
module configurations and software configuration. The module configurations (MCC) are  
then used in view constructions, whereas the software configuration (SCC) constructs the  
application welcome screen. DomainFSTool also takes advantage of the well-tested MCC and  
SCC, along with the domain models, to generate its output, including a REST API for the  
backend and React.js view modules. The extension also allows the specification of distinct  
output paths for the two components.  
Figure 1. The project structure, including bootstrapped files and folders.  
2.2.2. Domain object manipulation  
High-quality applications are not judged by how well-rounded the bootstrappers are  
but by how good the applications perform their intended business logic. Being an extension of  
jDomainApp, DomainFSTool provides the same capabilities of manipulating domain objects,  
including CRUD operations. Following is a discussion and comparison of DomainFSTool to  
its predecessor in terms of domain object manipulation.  
Creating a domain object: This function gathers data from the view, instantiates an  
object by invoking a suitable constructor and stores the object in the application. By taking  
advantage of the REST API design, DomainFSTool can also create associative objects for an  
object given a specific type.  
187  
Updating a domain object: Changed fields are gathered and sent to the handler in the  
backend component to retrieve the original object, perform updates on it then store it back to  
the application.  
Figure 2. Creating and updating an object can be in its main form.  
Retrieving domain objects: Originally, jDomainApp only supports the retrieval of  
objects by queries, which outputs only objects matching the given criteria. DomainFSTool  
extended this functionality to support specific functionalities such as retrieval by ID,  
retrieving a list of items with pagination support, commonly seen in the world of REST API.  
The design of REST API also allows for retrieving associated objects of an object given a  
specific type.  
Figure 3. Viewing associated (one-to-many) objects.  
188  
Deleting a domain object: As straightforward as it sounds, this function removes a  
domain object from the application.  
2.2.3.  
Modular RESTful web application architecture  
For DomainFSTool to successfully bootstrap an application, the applications should  
follow an easy-to-follow architecture with well-defined components. Following is the  
proposed architectural view of applications generated by DomainFSTool.  
Figure 4. Modular RESTful Web applications architecture  
DomainFSTool’s architecture is an extension over jDomainApp’s [2] with slight  
modifications for the Web platform. At the heart of the architecture is the domain model,  
which is unchanged compared to the original architecture.  
About the backend, it is composed of three components: Services that invoke suitable  
domain methods to fulfil their operations, and Associative controllers and Controllers which  
handle HTTP request mapping then delegate the request to the Service to perform application  
operations.  
On the other hand, a View still consists of several data fields as with jDomainApp.  
Each data field is the reflection of a domain field whereas a domain class corresponds to a  
View. There are two types of Views: the form view which contains input fields and the list  
view which presents a list of objects in a tabular format. A view can also be embedded in  
another view as a sub-form.  
On the software scale, there is the Software component which aggregates several  
modules. The corresponding view of this component is the MainView component, which  
presents the welcome page and handles redirection to the views of other modules.  
189  
2.3.  
Bootstrapping over manual creation  
When discussing the DomainFSTool, code generation plays an important role.  
Without code generation, DomainFSTool would not be considered outstanding. This section  
will briefly discuss the help of DomainFSTool in bootstrapping a full-stack web application.  
2.3.1. Bootstrapping the backend  
Backend bootstrapping involves collecting the information from the domain model to  
output controllers and services for the model classes. The process is represented by the  
following sequence diagram:  
Figure 5. Overall sequence diagram of the backend generation module.  
Firstly, an instance of WebServiceGenerator is constructed. All the bootstrapping  
work is done through contact with this instance. Once the instance is obtained, the client may  
optionally provide a function to be called when bootstrapping completes. Then, the  
WebServiceGenerator  
invokes  
all  
of  
its  
generation  
methods  
including  
generateAutowiredServiceType, getRestfulController and getNestedRestfulController.  
These generator methods perform the heavy work, including generating and save the source  
code, compile the source code in memory and returning the compiled classes, which can be  
seen in more detail in a later paper. Finally, when all three generators have done their jobs, if  
there is a function attached to the onGenerateCompleteCallback, it will be invoked with the  
190  
list of compiled versions of all generated classes. That means, after bootstrapping, the classes  
can be used right away without triggering a recompilation. This feature is great when quick  
prototypes are in need. The bootstrapper also generates source files, which helps backend  
development teams shorten their development time.  
2.3.2. Bootstrapping the frontend  
Frontend development teams also greatly benefit from DomainFSTool, since the tool  
also includes a module to generate React.js frontend modules. These frontend modules are  
modelled after the conceptual frontend components shown in Figure 4 in Section 2.2.3.  
DomainFSTool models the frontend in terms of Views and View fields. There are two main  
types of views as shown in the architecture, including the Form view and the List view. A  
View is also embeddable into another view as a sub-view, which is modelled as a separate  
type of view (SubView). A typical structure of a form view is illustrated in the following  
figure:  
Figure 6. Common form view with: (1) input field, (2) one-to-one associative field,  
(3) many-to-one associative field, and (4) one-to-many associative field (subview).  
Coming to view fields, there are three types: simple input fields which include an  
input for a single value, associative input fields which include ID input to fill in with an  
object instance, applying for one-to-one and many-to-one relationships, and one-to-many  
fields which are expandable subviews. The relationships between these components are  
191  
illustrated in the class diagram in Appendix B. In addition to the frontend models, there is a  
ViewBootstrapper that takes as input the domain models, module configurations and software  
configurations, and output all bootstrapped view files to the specified path. For the views to  
be generated correctly as shown in Figure 6, a comprehensive algorithm has to be applied.  
The algorithm, which extends from that of jDomainApp, is illustrated in the following figure:  
Figure 7. The compact generateViewFields algorithm  
The algorithm deals with the generation of a form view. It scans every domain fields  
and obtains the field def for each field. If it recognizes the field to be a primitive field or enum  
field, a SimpleViewField is created. Else, the algorithm recognizes the field to be either an  
associative input field or a one-to-many field, so it tries to find the association type and the  
association end type. If the association type is One2Many and the end type is One, the  
association is one-to-many and is represented by an OneToManyField. Else, if the association  
is either one to one or many to one, that means the view field is an AssociativeViewField.  
Due to the length of this paper, the implementation details could not be included, however,  
readers who interest may refer to the source code repository given in Appendix A.  
2.3.3. Software development with DomainFSTool  
Software development with DomainFSTool is a straightforward process, starting with  
developing the domain models and configuring the modules using jDomainApp’s annotations.  
Next, the backend application is generated by writing the main method that refers to the  
domain model, module configurations and output path, followed by invoking the backend  
generators as shown in Figure 5. The frontend application is also bootstrapped in the same  
way as the backend, with an extra step of copying the generated code files to an existing  
React application. That said, DomainFSTool allows frontend and backend development teams  
to work in parallel, which is expected to improve productivity in Web development.  
192  
3. Conclusion  
To sum up, this paper has briefly introduced DomainFSTool, a domain-driven design  
full-stack web application bootstrapper that is based on the powerful jDomainApp. In such a  
short paper, it is impossible to deliver every detail of the tool; however, the most important  
details have been included in this paper. The tool so far has been working well enough given  
its functionalities. While there is certainly more room for improvements, the author is  
confident that in the future, DomainFSTool will become an even more helpful and popular  
tool than the jDomainApp which it extends from.  
REFERENCES  
APPENDIX  
Appendix A. DomainFSTool source code repository on Github.  
Source  
code  
of  
DomainFSTool  
is  
available  
online  
at:  
Appendix B. Design diagrams of DomainFSTool.  
Class diagrams of DomainFSTool can be found in high-quality at:  
193  
pdf 9 trang baolam 19440 Free
Bạn đang xem tài liệu "Bootstrapping full-stack web applications following domain-driven design with domainfstool", để tải tài liệu gốc về máy hãy click vào nút Download ở trên

File đính kèm:

  • pdfbootstrapping_full_stack_web_applications_following_domain_d.pdf