Chapter 11.  Defining an Architecture

Sonargraph 8 and higher allows the definition of an architecture as code via a Domain Specific Language (DSL) that is expressive and readable enough so that every developer is able to understand it. The graphical representation in Sonargraph 7 allowed the creation of your architectural blueprint in one single diagram. This leads to potentially very big and complex diagrams that are difficult to understand.

The requirements for the new DSL approach were the following:

  1. It should be possible to describe an architecture in a set of files. Some of them should be generic enough so that they could be reused by many projects, e.g. a generic template describing the layering of a system.

  2. It should be possible to describe an architecture in form of several completely independent aspects. E.g. one aspect describes layering, another aspect describes components and a third aspect looks at separation of client and server logic.

  3. On the other hand the language should also be powerful to describe the complete architecture in a single aspect.

  4. The DSL must be easy to read and easy to learn.

  5. The restrictions for dependencies should allow also the specification of dependency types (e.g. "new", "inheritance", etc.).

To create an architecture description you select "New Architecture File..." from the menu "File/New...". That will open an editor window where you can work on your architecture description. You can have as many architecture files as you like. To enable Sonargraph to use your description to check for architectural violations you also must add your architecture file to Sonargraph's architecture check. This is done in the "Files" tab of the navigation view by right-clicking on your architecture file and select "Add to Architecture Check..." from the context menu. If you later decide to remove the file from Sonargraph's architecture check you can also do this over the context menu.

It is also recommended to open the "Architecture View" while working on an architectural model. You can open that view from the "Window / Show View" menu. The view is split vertically into three main sections. In the top section you can see all architecture descriptions that are not actively checked at this time in a tree view. This might also include files that imported by currently checked architectural models.

Architecture View
Figure 11.1. Architecture View

In the middle section you have two tabs, one for physical models and one for logical models. (Models are explained in the next section). They contain architectural models that are actively checked. That means you will be able to see which elements are assigned to which artifact by browsing through the tree. You can also easily see which elements have not been assigned to any architectural artifact by inspecting the nodes for "Unassigned internal/external components".

The bottom section lists all architecture violations of the element selected in he middle section. If no element is selected all architecture violations from all models are shown. If you click on a line in that table the associated violating dependencies are shown in the "Parser Dependencies Out" slave view.