title
stringlengths
3
46
content
stringlengths
0
1.6k
21:124
21:125
Figure 21.7: Planning view
21:126
Also useful is the Sprints menu on the left, which enables each user to jump immediately to the current sprints of all the projects they are engaged in.
21:127
This is how these work items are created. Once you understand this mechanism, you will be able to create and plan any software project. It is worth mentioning that the tool itself will not solve problems related to team management. However, the tool is a great way to incentivize the team to update the project status, so you can maintain a clear perspective of how the project is evolving.
21:128
Now that we have defined how we will manage WWTravelClub requirements, it is time to start thinking about the code standard that will be followed by the developers. Let’s check this out in the next section.
21:129
Code standard for WWTravelClub – Dos and don’ts when writing code
21:130
In Chapter 4, Best Practices in Coding C# 12, we learned that, as a software architect, you must define a code standard that matches the needs of the company you are working for.
21:131
In the sample project of this book, this is no different. The way we decided to present the standard for it is by describing a list of dos and don’ts. We have followed this list while writing the samples we produced. It is worth mentioning that the list is a good way to start your standard and, as a software architect, you should discuss this list with the developers you have in the team so that you can develop it in a practical and good manner.
21:132
It is also important to remember that, in the Understanding and applying tools that can evaluate C# code section of Chapter 4, Best Practices in Coding C#12, we have discussed some good tools that can help you define a coding style for your team.
21:133
In addition, the statements below are designed to clarify the communication between team members and improve the performance and maintenance of the software you are developing.
21:134
You may consider the list below a waste of space in the book since we have great C# community coding standards without the need to enforce a standard. However, how can you guarantee maintainability without it? If defining coding standards was not necessary, we wouldn’t have so many projects with maintenance issues. So, let’s check the list of dos and don’ts defined for the WWTravelClub project:
21:135
21:136
DO write your code in English.
21:137
DO use PascalCasing for all public member, type, and namespace names consisting of multiple words.
21:138
DO use camelCasing for parameter names.
21:139
DO write classes, methods, and variables with understandable names.
21:140
DO comment public classes, methods, and properties.
21:141
DO use the using statement whenever possible.
21:142
DO use async implementation whenever possible.
21:143
DON’T write empty try-catch statements.
21:144
DON’T write methods with a cyclomatic complexity score of more than 10.
21:145
DON’T use break and continue inside for/while/do-while/foreach statements.
21:146
21:147
These dos and don’ts are simple to follow and, better than that, will yield great results for the code your team produces. It is worth mentioning that these DOs and DON’Ts are a guide, not a set of hard-and-fast rules to be followed by every team. They can be adapted as needed for the specific needs of a team before they are sent out to the team members. As a software architect, it is essential that all team members follow the same DOs and DON’Ts.
21:148
Considering we now have a coding standard defined, let’s learn how to apply SonarCloud as a tool for helping us in code analysis.
21:149
Applying SonarCloud to WWTravelClub APIs
21:150
Now that we have already created the WWTravelClub repository, we can Improve the code quality, as discussed in Chapter 4, Best Practices in Coding C# 12. As we saw in that chapter, Azure DevOps enables continuous integration, and this can be useful. In this section, we will discuss more reasons why the DevOps concept and the Azure DevOps platform are so useful.
21:151
For now, the only thing we would like to introduce is the possibility of analyzing code after it is committed by the developers but before it has been published. Nowadays, in a SaaS world for application life cycle tools, this is only possible because of some of the SaaS code analysis platforms that we have. This use case will use SonarCloud.
21:152
SonarCloud is the SaaS version provided by Sonar. Also, it might be worth noting that SonarCloud is exceptionally easy to self-host; this way, sensitive security information may be kept within an enterprise. It is free for open-source code and can analyze code stored in GitHub, Bitbucket, and Azure DevOps. The user needs a registration for these platforms. As soon as you log in, assuming your code is stored in Azure DevOps, you can follow the steps described in the following article to create a connection between your Azure DevOps and SonarCloud: https://docs.sonarcloud.io/.
21:153
21:154
Sonar also provides a self-managed edition that can be useful for scenarios where SonarCloud cannot be used. Please check https://www.sonarsource.com/ for more details.
21:155
21:156
After setting up the connection between your project in Azure DevOps and SonarCloud, you will have a build pipeline like the one that follows:
21:157
21:158
Figure 21.8: SonarCloud configuration in the Azure build pipeline
21:159
It is worth mentioning that C# projects do not have a GUID number, and this is required by SonarCloud. You can easily generate one using this link: https://www.guidgenerator.com/, or using the Create GUID tool in Visual Studio (Tools -> Create GUID). The GUID will need to be placed as in the following screenshot:
21:160
21:161
Figure 21.9: SonarCloud project GUID
21:162
As soon as you finish the build, the result of the code analysis will be presented in SonarCloud, as can be seen in the following screenshot. If you want to navigate to this project, you can visit https://sonarcloud.io/summary/overall?id=gabrielbaptista_wwtravelclub-4th:
21:163
21:164
Figure 21.10: SonarCloud results
21:165
Also, by this time, the code analyzed is not yet in the release, so this can be useful for getting the next step of quality before releasing your system. You can use this approach as a reference for automating code analysis during committal.
21:166
Considering we have implemented a way to continuously evaluate code quality, it is time to design reusable software. Let’s look at this in the next section.
21:167
Reusing code as a fast way to deliver good and safe software
21:168
As we checked in Chapter 5, Implementing Code Reusability in C# 12, a good approach for accelerating the delivery of good software is creating reusable components. The final design of the solution for evaluating content for WWTravelClub can be checked in the diagram below. This approach consists of using many topics that were discussed in that chapter. First, all the code is placed in a .NET 8 class library. This means that you can add this code to different types of solutions, such as ASP.NET Core web apps and Xamarin apps for the Android and iOS platforms:
21:169
21:170
Figure 21.11: WWTravelClub reuse approach
21:171
This design makes use of object-oriented principles such as inheritance, so you do not need to write properties and methods more than once that can be used in many classes. The design also makes use of the polymorphism principle so that you can change the behavior of the code without changing the name of the method.
21:172
To finish, the design abstracts the idea of the content by introducing generics as a tool that can facilitate the manipulation of similar classes, such as the ones we have in WWTravelClub, to evaluate content regarding cities, comments, destination experts, and travel packages.
21:173
The big difference between a team that incentivizes code reuse and one that does not is the velocity of delivering good software to end users. Of course, beginning this approach is not easy, but rest assured that you will get good results after some time working with it.
21:174
Since we have covered the possibilities of code reuse using object-oriented principles, what about organizing the application using domains created by domain-driven design (DDD)? We will check it in the next section.
21:175
Understanding the domains of the WWTravelClub application
21:176
In this section we will perform the DDD analysis of the WWTravelClub system, trying to identify all its domains (also called bounded contexts), that is, the subsystems characterized by different languages used by the experts. Once identified, each domain might be assigned to a different development team and will give rise to a different microservice.
21:177
From the requirements listed in the Introducing World Wild Travel Club and User needs and system requirements sections, we know that the WWTravelClub system is composed of the following parts:
21:178
21:179
Information about the available destinations and packages.
21:180
Reservation/purchase orders subsystem.
21:181
Communication with the experts/review subsystem.
21:182
Payment subsystem. We briefly analyzed the features of this subsystem and its relationship with the reservation purchase subsystem at the beginning of Chapter 7, in the Understanding DDD section.
21:183
User accounts subsystem.
21:184
Statistics reporting subsystem.
21:185
21:186
Do the preceding subsystems represent different bounded contexts? Can some subsystems be split into different bounded contexts? The answers to these questions are given by the languages that are spoken in each subsystem:
21:187
21:188
The language that’s spoken in subsystem 1 is the language of travel agencies. There is no concept of a customer, just of locations, packages, and their features.
21:189
The language that’s spoken in subsystem 2 is common to all service purchases, such as the available resources, reservations, and purchase orders. This is a separate bounded context.
21:190
The language that’s spoken in subsystem 3 has a lot in common with subsystem 1’s language. However, there are also typical social media concepts, such as ratings, chats, post sharing, media sharing, and so on. This subsystem can be split into two parts: a social media subsystem that has a new Bounded Context and an available information subsystem that is part of the Bounded Context of subsystem 1.
21:191
As we pointed out in the Understanding DDD section in Chapter 7, in subsystem 4, we speak the language of banking. This subsystem communicates with the reservation purchase subsystem and executes tasks that are needed to carry out a purchase. From these observations, we can see that it is a different Bounded Context and has a customer/supplier relationship with the purchase/reservation system.
21:192
Subsystem 5 is a separate Bounded Context (as in almost all web applications). It has a relationship with all the bounded contexts that have either the concept of a user or the concept of a customer because the concept of user accounts always maps to these concepts. You must be wondering how. Well, it’s quite simple—the currently logged-in user is assumed to be the social media user of the social media bounded context, the customer of the reservation/purchase bounded context, and the payer of the payment Bounded Context.
21:193
The query-only subsystem (that is, 6) speaks the language of analytics and statistics and differs a lot from the languages that are spoken in the other subsystems. However, it has a connection with almost all the bounded contexts since it takes all its input from them. The preceding constraints force us to adopt CQRS in its strong form, thereby considering it a query-only separated Bounded Context.
21:194
21:195
In conclusion, each of the listed subsystems defines a different Bounded Context, but part of the communication with the experts/review subsystem must be included in the information about the available destinations, and the package’s Bounded Context.
21:196
As the analysis continues and a prototype is implemented, some bounded contexts may split and some others may be added, but it is fundamental to immediately start modeling the system and to immediately start analyzing the relationships among the bounded contexts with the partial information we have since this will drive further investigations and will help us define the communication protocols and ubiquitous languages that are needed so that we can interact with the domain experts.
21:197
The following is a basic first sketch of the domain map:
21:198
21:199
Figure 21.12: WWTravelClub domain map. Thin black arrows represent data exchanged between bounded contexts, while thick blue arrows represent the relationships between bounded contexts (conformist, customer/supplier, and so on)
21:200
For simplicity, we’ve omitted the Statistics reporting bounded context. We say just that it collects statistics on the daily purchases of each package.
21:201
Here, we’re assuming that the User accounts and Social bounded contexts have a conformist relationship with all the other counded contexts that communicate with them because they are implemented with already existing software, so all the other components must adapt to them.
21:202
As we mentioned previously, the relationship between Reservation and Payments is customer/supplier because Payments provides services that are used to execute the tasks of Reservation. All the other relationships are classified as partners. The various concepts of customer/user that most bounded contexts have are coordinated by the User accounts Authorization token arrow, which indirectly takes care of mapping these concepts between all the counded contexts.
21:203
The Packages/locations subsystem communicates the following information to Reservation:
21:204
21:205
Chosen package info, which contains the package information that’s needed to carry out a reservation/purchase
21:206
Price changes, which takes care of informing pending purchase orders of possible price changes
21:207
21:208
Social interactions are started from an existing review provided by users (the Reviews arrow between Packages/locations and Social) and are supported by Location/review info communications from Packages/locations to Social.
21:209
Finally, Reservation communicates purchase codes, descriptions, and prices to Payments through the Prices/codes/descriptions arrow.
21:210
Having identified our application’s bounded contexts, we are in a position to organize the application DevOps cycle.
21:211
The WWTravelClub DevOps approach
21:212
During Chapter 8, Understanding DevOps Principles and CI/CD, screenshots from the WWTravelClub project showed the steps needed to implement a good DevOps cycle. The WWTravelClub team has decided to use Azure DevOps because they understand that the tool is essential for getting the best DevOps experience for the whole cycle. In fact, it appears the most complete of the tools offered by GitHub, since it covers the whole CI/CD cycle from requirements collection to deployment in staging and production. Moreover, all team members already know it very well.
21:213
The requirements were written using user stories, which can be found in the Work items section of Azure DevOps. The code is placed in the repository of the Azure DevOps project. Both concepts were explained in Chapter 3, Managing Requirements.
21:214
The management life cycle used for getting things done is Scrum, presented in Chapter 1, Understanding the Importance of Software Architecture. This approach divides the implementation into sprints, which forces value to be delivered by the end of each cycle. Using the CI facilities we learned in this chapter, code will be compiled each time the team merges new code into the master branch of the repository.
21:215
Once the code is compiled and tested, the first stage of the deployment is done. The first stage is normally named development/test because you enable it for internal tests. Both Application Insights and Test and Feedback can be used to get the first feedback on the new release.
21:216
If the tests and the feedback of the new release pass, it is time to go to the second stage, quality assurance. Application Insights and Test and Feedback can be used again, but now in a more stable environment.
21:217
The cycle ends with the authorization to deploy in the production stage. This certainly is a tough decision, but DevOps indicates that you must do it continuously so you can get better feedback from customers. Application Insights keeps being a useful tool since you can monitor the evolution of the new release in production, even comparing it to past releases.
21:218
The WWTravelClub project approach described here can be used in many other modern application development life cycles. As a software architect, you must oversee the process. The tools are ready to go, and it depends on you to make things right!
21:219
For this reason, even considering WWTravelClub as a hypothetical scenario, some concerns were considered while building it:
21:220
21:221
CI is enabled, but a multi-stage scenario is enabled too.
21:222
Even with a multi-stage scenario, the PR (Pull Request) is a way to guarantee that only good-quality code will be presented in the first stage.
21:223
To do a good job in the PR, peer reviews are undertaken.