4.1. Architecture

4.1.1. Introduction

This section covers the setup of the Axivion Suite for software architecture erosion protection. You will learn about the three main inputs to architecture analysis – the as-is system structure, the architecture, and the mapping – how to create them, and how to set up the architecture analysis process itself.

4.1.2. Architecture Analysis

Three components are required to set up an architecture check. Each component is represented by one or more views in the RFG.

An abstraction

of the as-is structure, as derived from the source code of your software system. This is extracted from the code by the Axivion Suite language analysis front ends. For details, refer to the language analysis chapters for the programming language(s) used in your system. For C and C++, the system structure consists of two separate parts: source code elements and their relationships, and the hierarchy of files, modules, and directories. Therefore, this aspect is represented by two views in the RFG. For C#, this aspect is condensed into a single view.

An architecture

model representing the intended system structure. This is stored as a hierarchical graph in an RFG view. There are several ways of obtaining an architecture:

Manual Modeling

You can model (draw) the architecture manually using Gravis. Some approaches for doing this are described below.

Import from Modeling Tool

You can import the architecture from a UML CASE tool via XMI exchange or from any other modeling tool that exports to an open exchange format.

Note

Import support is available for Enterprise Architect (XMI and .qea/.qeax files), IBM Rhapsody, PlantUML including PlantUML C4, and AUTOSAR ARXML. Other tools (like Visual Paradigm, Ameos, Microsoft Visio) can be supported relatively easily via Python scripting (please contact us).

Script your Architecture

You can create the architecture using Python scripts based on external knowledge (e.g., naming schemes, directory structures, etc.).

In all cases, you can post-process the architecture using scripts to add implicit knowledge, remove irrelevant parts of the graph, etc. These strategies can be combined; for example, if you have partial models in a CASE tool and want to assemble the architecture for checking, or if you have optional parts that must be removed before checking a system variant.

The best strategy depends on your development approach, process, and tool environment.

A mapping

that associates nodes in the system’s source code with nodes in the conceptual architecture. The mapping is typically created alongside the architecture and follows the same processing steps. A mapping view contains nodes from the architecture and the hierarchy view, along with edge-maps-to Maps_To edges.

Before setting up continuous architecture checking, you can use the interactive architecture checking feature of Gravis to run one-off analyses. Gravis can also visualize imported or generated architecture and mapping graphs, serving as a debugging tool to verify that your architecture and mapping creation process is working.

Once you have created and validated your architecture and the corresponding mapping, you can integrate the architecture checking step into continuous integration.

If you model the architecture and the mapping in Gravis, set up an architecture project. It manages the files of the architecture checks and keeps the check options of Gravis and continuous integration consistent. Architectures imported from modeling tools or created by scripts are processed by rules in continuous integration instead (see Modeling using CASE tools and Architecture-As-Code).

Please see the list of available architecture rules here: Supported Architecture rules

4.1.2.1. Architecture Projects

An architecture project bundles the architecture checks of a software system for Gravis and for continuous integration. Each check consists of an architecture view, a mapping view, a layout of the architecture view, the base and hierarchy views to check against, and the analysis options. The project is stored in a project file with the extension .gaproj. The architecture and mapping views are stored as GXL files and the architecture layouts as layout files in the same directory, the project directory. The project directory belongs under version control, for example next to the analysis configuration of the software system. The RFG is not part of the project: as with any other architecture workflow, you download the current RFG of the software system from the dashboard and store it outside version control.

Using an architecture project has the following advantages:

  • Gravis loads the architecture views, mapping views, and layouts from the project directory when opening the project, tracks changes to them, and saves them to the project directory. You do not need to export GXL files, copy layout files, or remember their locations.

  • When closing the project, Gravis reminds you of unsaved changes to the views and layouts of the project only. Changes to the RFG itself are irrelevant, because the RFG is replaced by the next download from the dashboard.

  • The analysis options are stored for each check. You run a check with a single click, without using the Analysis dialog, and an existing result window is updated in place.

  • A project can contain several checks, for example for different source abstractions or for different parts of the system. The roles of the views are assigned automatically for each check.

  • The rule Architecture-GravisArchitectureProject reads the project file and runs all of its checks in continuous integration. It uses the options stored in the project, so the results in continuous integration match the results in Gravis.

The user interface for architecture projects is described in Architecture Projects.

Setting up a new architecture project

  1. Download the RFG of the software system from the dashboard, store it in a directory outside version control, and open it in Gravis.

  2. Choose File → ic_new_architecture_project New architecture project.... Enter a project name and choose a location under version control. Tick Create project directory to create a separate directory for the project.

  3. In the New Architecture Check dialog that opens next, enter a check name, for example Architecture Check, and choose the check type, which determines the base and hierarchy views (see Choosing the source abstraction). Enter Architecture as the architecture view name and Mapping as the mapping view name. Gravis creates these views, which are initially empty, and an architecture layout named Default.

  4. Click the ic_edit_no_frame button of the architecture view entry in the Architecture Project Tree and model the architecture as described in Creating the Architecture.

  5. Click the ic_edit_no_frame button of the mapping view entry and create the mapping as described in Setting up the Mapping view.

  6. If needed, click the ic_settings button of the check entry to adapt the analysis options (see Architecture check options).

  7. Click ic_continue Run in the check entry to run the check and evaluate the result (see Viewing Analysis Results).

  8. Click ic_save_flat Save all in the project entry and add the project directory with all its files to version control.

  9. In axivion_config, add the rule Architecture-GravisArchitectureProject to the Architecture pipeline by selecting Add to active list... from its context menu (or drag the rule from the Available actions section to the list of active actions). Set the option architecture_project_file of the added rule to the project file (see also the FAQ).

To add further checks, choose ic_architecture_check New architecture check... from the context menu of the project entry.

Converting an existing setup to an architecture project

If you have modeled the architecture in Gravis without an architecture project, the analysis configuration contains instances of the rule Architecture-GravisArchitecture that import the architecture and mapping from GXL files. The RFG downloaded from the dashboard then contains the architecture and mapping views, and you may have created a persistent layout for the architecture view. An architecture check can take over existing views and layouts:

  1. Download the current RFG from the dashboard and open it in Gravis. If you have modified the architecture or the mapping since the last analysis, import the current GXL files using File → ic_open_view Import views... after deleting the outdated views.

  2. Create a new architecture project as described above.

  3. In the New Architecture Check dialog, choose the check type that matches the base and hierarchy views of your setup. Choose the existing architecture view and mapping view from the drop-down lists. Enter the name of the existing persistent layout of the architecture view, as shown in the Layout column of the graph View Box, to take it over. The project saves the views and the layout to the project directory.

  4. Click the ic_settings button of the check entry and set the options to the values used in the configuration of Architecture-GravisArchitecture: root_edge_type_name corresponds to Type hierarchy, declaration_forwarding and declare_edge_type to Declaration forwarding, allow_dependencies_to_parents to Allow dependencies to parents, and ignored_edge_types to Ignored edge types.

  5. Repeat the previous two steps for each instance of Architecture-GravisArchitecture.

  6. Click ic_save_flat Save all and add the project directory to version control.

  7. In axivion_config, remove the instances of Architecture-GravisArchitecture from the Architecture pipeline. Add Architecture-GravisArchitectureProject to the pipeline by selecting Add to active list... from its context menu, and set its option architecture_project_file to the project file. The previous GXL files are no longer used and can be removed from version control.

Note

Architecture-GravisArchitectureProject reports violations with the name of the check appended to the error number (see option append_check_name). Since the rule name and the error numbers differ from those of Architecture-GravisArchitecture, the Dashboard treats the violations found after the conversion as new findings.

Evaluating and updating the architecture

The typical cycle for keeping the architecture up to date is:

  1. Download the current RFG from the dashboard and replace the RFG file used by the project. The project refers to the RFG by its path, so store the new version under the same path.

  2. Open the project file in Gravis, for example using File → Open recent. If the project is already open, choose File → Reload architecture project instead.

  3. Click ic_continue Run all in the project entry, or ic_continue Run in a check entry, and evaluate the results (see Viewing Analysis Results).

  4. For each violation, decide whether the code or the architecture needs to change. To change the architecture, use ic_accept Accept violation... (see Accepting Violations) or edit the architecture view or the mapping using the ic_edit_no_frame buttons in the Architecture Project Tree.

  5. Click ic_restart Update in the check entry to run the check again with the changes. The result window keeps its position and layout, and an open Violations List of the check is updated as well. To discard changes that did not work out, choose ic_revert Revert from project from the context menu of the check entry or of the view entry. This restores the state saved in the project directory without reloading the project.

  6. Modified views and layouts are shown in blue with an asterisk in the Architecture Project Tree. Click ic_save_flat Save all and commit the changed files in the project directory. The next analysis in continuous integration uses them.

Editing an architecture project

The following changes to a project are made in the Architecture Project Tree:

  • To add a check, choose ic_architecture_check New architecture check... from the context menu of the project entry.

  • To remove a check, choose ic_architecture_check Delete check '<check name>' from the context menu of the check entry. You can choose whether its files in the project directory are deleted as well.

  • To change the analysis options of a check, click the ic_settings button of the check entry.

The name, the check type, and the views of a check cannot be changed. Create a new check instead. These changes modify the project file. Save it using ic_save_flat Save all and commit it together with the other files of the project directory.

The project file contains the path of the RFG file that was loaded when the project was created. Gravis loads this file when opening the project. If the file does not exist, for example after checking out a project created by another user, Gravis asks for the RFG and offers to store its location in the project file (see Opening and closing an architecture project). Architecture-GravisArchitectureProject ignores this path and checks the RFG of the running analysis.

4.1.2.2. Manual Modeling

This section describes a top-down approach to manual architectural modeling.

Open the system RFG in Gravis.

Immediately after source code analysis, and without additional configuration, the RFG will contain the views Code Facts and Module, as well as Declaration Facts and File. The difference between these two pairs of views will be explained later during the mapping process.

If you use an architecture project, create the project and its first check as described in Setting up a new architecture project. The check creates the views Architecture and Mapping. Click the ic_edit_no_frame button of the architecture view entry in the Architecture Project Tree to open an initially empty window.

Without an architecture project, create two new (and initially empty) views via File → ic_new_viewNew View… from the main menu. Use the names Architecture and Mapping. Double-clicking the Architecture view in the View Box opens an initially empty window.

You can now start modeling the architecture in this window.

Creating the Architecture

The Node Types and Edge Types panels list all available node and edge types. In the Node Types window, expand the node-architecture-entity Architecture_Entity entry and select node-cluster Cluster.

Note

By convention, use the node-cluster Cluster node type when modeling manually. Additional node types can be added if you wish to explicitly use Layers, Tiers, Domains, Components, etc. For now, node-cluster Cluster is sufficient, as it generically represents any kind of hierarchical grouping.

Select the nodetool1Node Tool. You can now create nodes by clicking in any empty space in the window. Each time a new node is created, a dialog box appears where you can enter the node’s name. This sets the node’s Source.Name attribute.

Note

The Source.Name and Linkage.Name attributes are used to identify a node across analysis runs and exports/imports. The identification mechanism works as follows: if a node has a Source.Name but no Linkage.Name, it is identified by its Source.Name. In this case, do not add a second node with the same Source.Name, as it would not survive an export/import cycle. If the node has a Linkage.Name, this attribute is used to identify the node. In this case, you can use the same Source.Name for other nodes, provided they have different Linkage.Name attributes.

Please note that if you create a node using the Node Tool, the node’s Linkage.Name attribute is automatically set to a randomly generated hex string to give the node a unique identity.

When distributing modeling work across a team, it is important to remember that by default, each created node has its own unique identity. Thus, if several partial models contain a node called ”MemoryManager”, the unique Linkage.Name attribute of each node ensures they are all treated as distinct nodes when the partial views are eventually merged. This default behavior allows team members to assign node names without fear of clashing with those assigned by others. Conversely, if several team members wish to share nodes across their partial views, they must ensure that they all use the same Linkage.Name attribute. This does not have to be a hex string; it can be set to a more human-readable description, such as ”Shared.MemoryManager”.

Once each team member has completed their partial view of the architecture model, the individual parts can be merged by importing the views into Gravis and unifying them. Upon import, Gravis treats all nodes with matching Source.Name and Linkage.Name as identical, as described above, which links the models if they share any nodes.

Typically, an architecture has several hierarchical levels. To model the contents of a hierarchical node, double-click it while using the navigator1Navigate, selecttool1Select, marktool1Mark, or reparenttool1Hierarchy Tool. The node will display an expanded area containing its children. Initially, this area is empty; new nodes created within this expanded area become children of that node.

If a node’s expanded area overlaps other collapsed or expanded nodes, you can remove the overlaps at all hierarchical levels by Shift-double-clicking the window background. This invokes the ic_visualization_styleVisualization → ic_remove_overlaps_deepRemove overlaps (deep) operation. To remove overlaps only at the top level or inside a specific expanded node, double-click the background at the respective level (i.e., the window background for the top level or the node’s expanded background).

Note

To move a node from one container node to another (i.e., re-parent the node) or make a node inside a container a top-level node, use the reparenttool1Hierarchy Tool. Simply moving a node around using any of the other tools will not implicitly change its location in the hierarchy.

Once the first draft of the architecture hierarchy is complete, add the desired dependencies by creating edges using the edgetool1Edge Tool. First, select the appropriate kind of dependency you want to allow in the Edge Types panel. Typically, this will be either a edge-source-dependency Source_Dependency or one of its subtypes, such as edge-call Call or edge-reference Reference.

Note

Edges that are not subtypes of edge-source-dependency Source_Dependency only make sense if custom analysis data was added via an RFG or IR script (e.g., for modeling interprocess communication). Even then, it is recommended to integrate the respective custom types into the type hierarchy under edge-source-dependency Source_Dependency.

To create an edge, hover the mouse pointer over the source node until it is highlighted, then click and move the pointer over the target node until it is highlighted, then click again to place the edge. Alternatively, you can click the source node, hold the mouse button down, move the pointer over the target node until it is highlighted, and then release the mouse button to place the edge.

Some hints for working with dependencies:

  • An edge from parent P to parent Q means that all children of P are permitted to have dependencies on all children of Q.

  • Dependencies among children of the same parent must be modeled explicitly. To allow a dependency from one child C to all other children of the same parent, add a dependency from C to its parent.

  • A dependency that is already covered by a dependency of a parent node is said to be obscuring.

Once the architecture is complete, save it. With an architecture project, click the ic_save_flat button of the architecture view entry or ic_save_flat Save all in the project entry of the Architecture Project Tree. Without an architecture project, select ic_save_viewExport as GXL… from the context menu of the Architecture entry in the View Box.

You are now ready to specify the manual mapping.

Creating the Mapping

The mapping establishes a relationship between the nodes in the architecture view and the nodes in the source model.

With an architecture project, the base and hierarchy views are determined by the check type chosen when creating the check (see Choosing the source abstraction below), and Gravis assigns the roles automatically, so the role assignment described below is not needed.

Without an architecture project, assign roles to the views to cover one of the aspects discussed above. Roles are displayed in the leftmost column of the view box. Open the context menu for the Architecture view, then choose the ic_view_architecture Architecture role from the ic_set_roleSet role sub-menu. Similarly, apply the ic_view_mapping Mapping role to the Mapping view.

Additionally, views are required for the ic_view_base Base and ic_view_hierarchy Hierarchy roles.

Choosing the source abstraction

The software system’s source code is represented by two RFG views: the Base view, which contains the actual source code entities analyzed during architecture analysis, and the Hierarchy view, which provides those elements with a hierarchical structure. This structure facilitates the mapping process by allowing an entire sub-structure of source code entities to be mapped to an architecture component in one go.

The specific views used depend on the programming language. For some languages, there are several combinations of views that can be chosen. For others, these two roles can be filled by a single view.

For C and C++, there are three possible pairs of views that can serve as the source abstraction. The best choice depends on how dependencies among components are expressed in your architecture.

Code Facts as base and Module as hierarchy view

The Code Facts view considers only definitions and all template instances, omitting declarations. Language elements that can be defined multiple times are placed arbitrarily (e.g., classes with multiple definitions). Headers (e.g., driver.h) and implementation files (e.g., driver.c or driver.cpp) with the same base name are combined into modules. These modules are positioned at the location of the .c/.cpp files. The Code Facts and Module view pair is used to express the logical language view of the system.

Declaration Facts as base and File as hierarchy view

The Declaration Facts view contains all declarations and definitions, including instantiating declarations but excluding template instances. The File view shows all .h and .c/.cpp files.

Include as base and File as hierarchy view

The Include view contains #include dependencies between files. In contrast to the two pairs above, this view only allows the checking of #include dependencies, excluding low-level dependencies such as calls or type/variable usages.

For C#, there are two possible ways to obtain a source abstraction:

Assembly as both base and hierarchy view

The Assembly view contains all assemblies (see Language Schema) in the project as root nodes together with their content. As this view is focused on assemblies as the top-level unit, namespaces may appear multiple times, once in each assembly that contributes to a namespace.

Code Facts as both base and hierarchy view

The Code Facts view is centered around namespaces. Thus, each namespace exists only once, combining all its elements in a single place. Assemblies do not exist in the Code Facts view.

For combined C, C++ and C# cross-language analyses, there are two possible ways to obtain a source abstraction:

Combine C/C++ Declaration Facts and C# Assembly as the base view, and C/C++ File and C# Assembly as the hierarchy view.

Combine C/C++ Code Facts and C# Code Facts as the base view, and C/C++ Module and C# Code Facts as the hierarchy view.

For more information on setting up a combined cross-language analysis involving C/C++ and C#, see Cross-Language Analysis Setup Guide. For a description of the available cross-language options regarding RFG creation, see Architecture-Dependencies/cross_language_options.

You must choose one of these combinations; mixing them will not yield any meaningful results. Note that it is possible to set up several architecture analysis runs with different view combinations.

For a combined C, C++ and Rust cross-language analysis, the following default view combinations are recommended:

  • C/C++ Code Facts and Rust Code Facts as the base view

  • C/C++ Module and Rust Code Facts as the hierarchy view

Note

These combinations are recommended because AxivionRustFrontend does not generate Declaration Facts or File views. View merging can be configured using Architecture-Dependencies/cross_language_options.

Setting up the Mapping view

For the purposes of this walkthrough, let us use the pair Declaration Facts and File.

Caution

If a view must serve as both the base and hierarchy view (as is the case for C#), this is achieved by assigning the ic_view_hierarchy Hierarchy role only and leaving the ic_view_base Base role unassigned.

With an architecture project, open the mapping view by clicking the ic_edit_no_frame button of the mapping view entry in the Architecture Project Tree. Without an architecture project, once all roles are assigned, you can open the mapping view by double-clicking the ic_view_mapping Mapping view in the view box. Note that the mapping view window has a different layout. On the left is the node hierarchy from the hierarchy view; on the right, the architecture nodes are organized as a tree.

Note

You can also create the mapping with a graphical view of the architecture by opening the Mapping window via Edit → ic_mappingArchitectural mapping → ic_view_open_hierarchicalArchitecture as graph in the main menu, or with an architecture project, by holding down Shift while clicking the ic_edit_no_frame button of the mapping view entry. The mapping process is identical; the main difference is the way you navigate the architecture. You can transfer the layout of your architecture view using ic_layout_to_fileLayout storage → ic_layout_to_fileExport layout... to save the layout from the Architecture view window, and ic_layout_to_fileLayout storage → ic_layout_from_fileImport layout... to load it into the architecture section of the Mapping window.

You can map elements by dragging them from left to right using the mappingtoolltr1Mapping Tool, which is only available in this window. Dragging an unselected node maps only that node. Dragging a selected node maps all currently selected elements; ensure only the elements you want to map are selected. Click on a node to select it; this deselects all other nodes. To add to the selection, hold down Ctrl while clicking.

You may map directories, files, or even elements from within a file (e.g., a single variable). Mapping source entities that do not align with the directory structure typically indicates that refactoring is needed to improve the system structure. Medium- and large-scale systems should generally be mapped at the directory level, and in specific cases, at the file level.

Mapping a directory means that if you add a subdirectory or file to that directory, it will be implicitly mapped. Mapping elements individually means that any new additions to that directory must be handled manually. Since architectures are based on abstraction, it is generally preferable to map higher-level elements and allow lower-level elements to be mapped implicitly.

To remove a mapping, use the context menu on the left side of the mapping dialog: ic_mappingMapping → ic_unmapUnmap node (flat) (removes the mapping for a single node), ic_mappingMapping → ic_unmap_deepUnmap node (deep) (removes mappings for a node and all its descendants), ic_mappingMapping → ic_unmap_selectionUnmap selection (flat), or ic_mappingMapping → ic_unmap_selection_deepUnmap selection (deep) (as above, but for the selected nodes).

Once the mapping is correct, save it. With an architecture project, click the ic_save_flat button of the mapping view entry or ic_save_flat Save all in the project entry of the Architecture Project Tree. Without an architecture project, select ic_save_viewExport as GXL… from the context menu of the mapping view in the View Box.

Note

These two files (Architecture.gxl and Mapping.gxl) serve as input files for the architecture check mechanism in continuous integration. With an architecture project, they are stored in the project directory and Architecture-GravisArchitectureProject finds them via the project file.

Note

It is recommended to keep the GXL files (or the project directory) under version control alongside the source code of your system.

Running Architecture Analysis

Now we are ready to perform our first architecture check.

With an architecture project, click ic_continue Run in the check entry of the Architecture Project Tree. The check uses the options stored in the project (see Architecture check options) and opens the graphical result view using the layout of the architecture view. To open the ic_violations_listViolations List, choose ic_view_open_violations Open violations... from the context menu of the check entry.

Without an architecture project, open the analysis dialog from the main menu via Edit → ic_analysisRun analysis…. In the tree display on the left side of the dialog, make sure that Perform Check in the Architecture Checking section is selected. If you have configured the roles as described above, the appropriate views for the roles mentioned in the upper part of the dialog should already be set up. Otherwise, please choose the appropriate views from the drop-down menus. You can skip most of the remaining options and leave them at their default values. Ensure that Open result list is checked and Open graphical result view is unchecked, then click Run analysis.

A progress bar is displayed in the lower-left corner of the main window of Gravis. Once the analysis has completed, the ic_violations_listViolations List window opens, displaying a list of all divergences and absences.

Viewing Analysis Results

A divergence is a source code dependency that was not specified in the architecture. It is represented by a edge-divergence Divergence edge between architecture entities in the result view. Each divergence can be caused by more than one “causing” (violating) edge. The ic_violations_listViolations List is essentially a list of causing edges. The details of the causing edge are shown in the Causing source, Causing edge, and Causing parent columns. The Parent of source and Parent of target columns show the parents of the source and target nodes to simplify identification.

An absence indicates a missing source code dependency that contradicts the expected source code dependencies defined in the architecture model. It is represented by an edge-absence Absence edge between architecture entities in the result view. In essence, an edge-absence Absence between two nodes A and B is generated if an edge of type edge-source-dependency Source_Dependency (or a type derived from Source_Dependency) exists between A and B in the architecture view, but the analysis does not detect any type-matching dependencies between A and B. If the edge-source-dependency Source_Dependency edge between A and B has the Architecture.Is_Optional attribute set, no absence edge will be generated.

The Violation kind, Violation source, and Violation target columns indicate the divergence to which this causing edge belongs, i. e., the divergence it causes. The total number of edges that caused the given divergence is displayed in the Causing edge count column. Initially, the entries are grouped by divergence, so all the causing edges belonging to the same divergence are shown in consecutive rows.

Double-clicking a divergence entry shows the source code for the violation.

Note

If you have moved the source code or you are using an RFG that has been generated with the source code at a different path, you can make your source code available for browsing via File → Source base path…, which allows you to set the base path that is prefixed to the source code paths of nodes and edges.

The context menu for each list entry provides options to display more information and to mark the individual entities listed in the graph. The menu is sensitive to the column you click. For instance, when clicking a column showing a node, you can display the Node information window for the node or mark it. Regardless of the column clicked, you can show the Edge information window for the causing edge and mark the causing edge and its endpoints (Mark causing elements), the divergence edge and its endpoints (Mark architecture elements), or both (Mark architecture and causing elements).

The analysis result is a view containing the architecture model enhanced with additional information. With an architecture project, this view is named after the check and opened automatically. Without an architecture project, this view is named Architecture Check 1 by default and can be viewed as a graph. If the option Open graphical result view was selected in the Architecture Analysis window, the graphical view opened automatically. To open the graphical analysis results manually, double-click the Architecture Check 1 view in the View Box.

Note

With an architecture project, the result view uses the layout of the architecture view automatically. Without an architecture project, you can transfer the layout of your architecture to the graphical analysis result window using ic_layout_to_fileLayout storage → ic_layout_to_fileExport layout... in the window showing the architecture and ic_layout_to_fileLayout storage → ic_layout_from_fileImport layout... in the window showing the graphical result view.

The graphical result view consists of the architecture view enhanced with architecture check result edges and a browsable mapping; i. e., each architecture component contains the source code elements mapped to it as children. This arrangement allows you to navigate from a edge-divergence Divergence summary edge down to its causing edges by drilling down the hierarchy – i.e., by sequentially expanding the nodes at both ends of the edge (provided that both the result edges and the causing edges are lifted in the result view, which is the default).

Double-clicking a edge-divergence Divergence edge opens a Violations List window displaying all source code edges that caused this divergence. If the edge-divergence Divergence is a summary edge, the list contains the causing edges of all actual divergences represented by the summary edge.

You can now change and update your architecture to match the current state of your system. With an architecture project, click ic_restart Update in the check entry to run the check again after a change; the result window keeps its position and layout.

Caution

You need to update your architecture in the window showing the Architecture view, not the window showing the result view.

The goal is not to remove all divergences, but rather to end up with the “correct set” of divergences that actually violate the architecture and should be removed or refactored eventually.

Caution

Without an architecture project, export the GXL files for the Architecture and Mapping views each time you want to save your work. With an architecture project, use ic_save_flat Save all instead; Gravis marks modified views in the Architecture Project Tree and asks you to save them when closing the project. Saving the entire RFG is not advisable, as it also contains the representation of the analyzed software system. The separate GXL files for the Architecture and Mapping views can be imported into an RFG representing a later version of the software system. If you decide to save the entire RFG, it is advisable to delete any architecture result views first, because they will not retain all their functionality when saved and reloaded. If needed, they can be regenerated by re-running the analysis after loading the RFG.

Note

Remember to remove unused analysis results from the view box, as the RFG has a limit on the number of views. Result views also store a significant amount of additional analysis information; deleting unused result views helps reduce the memory consumption of Gravis.

4.1.2.3. Handling C/C++ Declarations

Prerequisites

For some architecture analyses, it is important to distinguish between different kinds of declarations in the code. In this section, we describe our approach to several issues arising from this fact. We assume that the Declaration Facts and File views are used for the architecture analysis; for the Code Facts and Module views, the information in this section is not applicable, since these views only consider definitions and do not represent other declarations.

Programs written in C and C++ use declarations to introduce identifiers for types, objects, and functions. In the following, we refer to the declared elements as entities. A definition of an entity is a special declaration that contains all information necessary for the compiler to construct and represent an entity.

We call a declaration that is not a definition a simple declaration.

In general, for a declaration d of an entity o, there is at most one corresponding definition of o if the program is well-formed. However, there are certain exceptions, most notably involving the One Definition Rule (see the C++11 language standard, section 3.2). Friend declarations differ from ordinary declarations in that they do not introduce the name of the entity (at least according to the standard, although some compilers treat them as implicit forward declarations).

Declarations as Targets for Source Dependencies

In the Declaration Facts view of the RFG, declarations and definitions are represented as nodes. Within one file, all declarations of the same entity are subsumed into one node. Simple declarations have a Declare edge to their respective definition, if such a definition exists. Therefore, in general, declarations and the definition of an entity form a star-like subgraph in the RFG. If no definition is present, there is no connection between declarations of an entity. In the Declaration Facts view of the RFG, source dependencies like calls or variable accesses have declarations as their targets. However, there may be more than one declaration of the same entity; therefore, there is generally no “best” or “unique” declaration for a dependency target. For example, two header files might be included in a source file, and each header file might contain its own (forward) declaration of the entity. The declaration chosen as the target of a source dependency in the RFG is arbitrary; we only know that it is indeed a declaration of the target entity.

This ambiguity in source dependency targets poses a challenge for architectural designs. Assume that a simple declaration node d of an entity o is (directly or indirectly) mapped to an architecture entity A. Let B be another architecture entity. The central question is then: If an architecture entity B has a dependency on A, does this imply that elements mapped to B have the permission to access entity o?

Example of forward declarations in a header file and their dependencies. :rfgelement:`Declare` edges are colored black, :rfgelement:`Static_Call` edges are colored blue. Only one of the two :rfgelement:`Static_Call` edges will be represented in the RFG; the choice is arbitrary.

Figure 1: Example of forward declarations in a header file and their dependencies. Declare edges are colored black, Static_Call edges are colored blue. Only one of the two Static_Call edges will be represented in the RFG; the choice is arbitrary.

Example architecture with mapping for the example code project. :rfgelement:`Maps_To` edges are colored blue, :rfgelement:`Source_Dependency` edges are colored gray.

Figure 2: Example architecture with mapping for the example code project. Maps_To edges are colored blue, Source_Dependency edges are colored gray.

For example, A might represent an interface in a C program, represented in the code by a header file component_a.h (see Figure 1). The header contains declarations of routines that should be visible to other code components, such as get_value(). A corresponding source file component_a.c contains the definitions of the routines declared in the header, as well as other routines that may be “private” to the implementation of component A, such as compute(). The routine start() calls get_value(), but the target of the corresponding call dependency may either point to the definition or to one of the simple declarations of get_value(). This is illustrated in the figure by the two Static_Call-edges outgoing from start(): only one of them is contained in the Declaration Facts view, and this choice is arbitrary.

In the architectural model, the header file is mapped to the architecture entity A_public and the source file is mapped to A_private (see Figure 2). The architectural entity A_private is not accessible to other architecture entities. In this case, the declaration of get_value() in component_a.h should signal that A_public “offers” the entity get_value() to other architectural entities such as B: the declaration should allow any architecture entity that has a dependency on component A to also access get_value(), even though its definition is not mapped to A_public.

However, a declaration d of the entity o might be required in a source file for technical reasons – for example, a forward declaration of a class which avoids an include statement. If the source file in question is mapped to an architecture entity a, this forward declaration should generally not imply that architecture entities dependent on a are allowed to access o. Therefore, the desired semantics of a declaration with respect to an architecture model cannot be expressed in C or C++.

The following section describes the means provided by the Axivion Suite to formalize these differing interpretations of declarations. Broadly, the approach works as follows: for each architectural dependency target that is a declaration, we compute a set of possible architecture entities for the target. This set contains:

  1. the architecture entity to which the definition of the target code entity is mapped, if one exists, and

  2. the architecture entities to which declarations of the code entity are mapped, provided they have a (possibly indirect) “Declaration forwarding” dependency on the architecture entity corresponding to the definition.

A convergence is generated if there is a corresponding dependency in the architecture view targeting any element in this set. If no element in the set results in a convergence, a single divergence is reported, with the original code dependency as the causing edge. The architecture target of this divergence is the architecture entity to which the definition of the code entity is mapped. The edge type for “Declaration forwarding” dependencies is Declare by default, but can also be specified by the user before analysis.

4.1.2.4. Modeling using CASE tools and Architecture-As-Code

In addition to modeling and mapping the architecture entirely within Gravis, it is also possible to perform an architecture analysis using input from CASE tools or Architecture-As-Code approaches. The Axivion Suite provides built-in support for models from Sparx Enterprise Architect, IBM Rational Rhapsody, AUTOSAR ARXML files, and a subset of models written in the PlantUML format, including PlantUML C4. Other input formats are supported via custom import scripts. Architectures can also be expressed using a Python-based description language (the “Architecture-As-Code” approach).

Basics

The following section illustrates how the architecture check can be implemented based on a CASE tool model. The examples provided are intended to serve as a foundation for your own checks. Many other modeling styles can be supported by developing corresponding transformation and mapping rules. To ensure that the resulting check results are meaningful, you must clarify your modeling approach and how your model is related to the source code before you create an architecture analysis. The hierarchy and base views can be selected in the same way as the manual modeling approach described earlier. Obtaining an architecture view, a mapping view, and a results view involves four steps. These steps are typically performed using rules already provided by the Axivion Suite or by using rules specifically written for the check in question. The specific rule configuration depends on the modeling approach and the structure of the source code.

  1. Import the model into the RFG. This step creates a separate view in the RFG where the architecture model is represented as RFG nodes and RFG edges. Typically, these nodes are subtypes of UML Node and edges are subtypes of UML Dependency. Attributes are used to represent additional information from the model, such as names, stereotypes, tagged values, or GUIDs.

  2. The structure of the imported model must be transformed to be usable by the architecture check. In the second step, the model view is transformed into a new view. This “transformed model view” serves as the basis for an architecture check; specifically, it will be assigned the Architecture role described earlier. In the simplest cases (see Example 1), packages or components are connected by simple edges to express dependencies. In such cases, only the dependency edge types need to be interpreted (i.e., transformed into edge types that are subtypes of Source_Dependency), such as Call relations if only calls are permitted between entities. If the model uses more sophisticated dependency relations, such as interface-based connections, a customized rule is used to translate, for example, a dependency modeled using provided and required interfaces into a dependency that can be processed by the architecture verification (see Example 2).

  3. Create a mapping view that maps nodes from the hierarchy view to the transformed model view. The mapping can be obtained in various ways. The rule Architecture-HierarchicalMapping connects entities with the same or similar names; for example, directories in the code are mapped to packages in the model if their names match (see Example 1). More complex mapping rules are also possible. Special transformations can then be applied to, for example, connect interface elements to their respective functions, variables, or methods (see Example 2). It is also possible to provide information about code locations as tagged values in the model. Rules like Architecture-TaggedValuesMapping can use these to create a mapping view.

  4. Execute the architecture check and obtain convergence, divergence, and absence information.

Example Analyses included in the Axivion Suite

The rules and configurations described in the examples can be found in the archives example/architecture_examples.zip (Windows) or example/architecture_examples.tar.xz (Linux and macOS) in the installation of the Axivion Suite, along with a small C source code project called engine_demo and configurations for building and analyzing the project using the different modeling approaches. Further details on running the analyses are provided in the README.txt file within the archive.

Example 1: Package Model (Enterprise Architect)

In the first example, Sparx Enterprise Architect is used as the tool for modeling architectures. The modeling entities are

  • packages and

  • edges of type Dependency between packages.

Package names correspond directly to directory names in the source code project. A dependency X -> Y indicates that all code corresponding to X may depend on all code corresponding to Y; for example, a function in X can call another function in Y, or access fields of a class in Y, etc. The configuration is located within engine_demo/axivion/package_model in the example archive.

The analysis is performed using rules provided by the Axivion Suite:

  1. The model file package_model.xmi is imported into the RFG by an instance of the rule Architecture-EAImporter, generating an EA Architecture view. In the resulting RFG, packages are represented by nodes of type UML Package, and dependency edges are represented by edges of type UML Dependency. The result of the import can be inspected in Gravis:

    package_model_ea_architecture_view

  2. An instance of the rule Architecture-EdgeInterpretation transforms the UML Dependency edges in the model into Source_Dependency edges, resulting in the Architecture view; this is visible via the changed shape and color of the edges:

    package_model_architecture_view

  3. An instance of the rule Architecture-HierarchicalMapping creates a mapping between File (code) and Architecture; by default, directories are mapped to nodes of type UML Package:

    package_model_mapping_view

  4. Finally, an instance of the rule Architecture-ArchitectureCheck performs the actual architecture check and generates convergences, divergences, and absences, creating a check view:

    package_model_result_view

Rules such as Architecture-HierarchicalMapping can also issue warnings if, for example, name inconsistencies arise between code elements and model elements. These are processed as stylecheck findings.

Example 2: Port Model (Enterprise Architect)

The second example also uses Sparx Enterprise Architect as the CASE tool for modeling architectures. The metamodel is more complex than the previous one, as it incorporates detailed aspects of communication between software components. In particular, dependencies between components are specified using provided and required interfaces.

The modeling entities are

  • components and packages,

  • interfaces,

  • ports,

  • required and provided interfaces, and

  • edges of type Dependency between provided and required interfaces.

The configuration is located within engine_demo/axivion/port_model in the example archive.

Two customized rules are created for this architecture analysis: Architecture-PortModelTransformation and Architecture-PortModelMapping. Their code can be found in the directory engine_demo/axivion/port_model/rules.

The analysis is performed using the following rules:

  1. The model file port_model.xmi is imported into the RFG by an instance of the rule Architecture-EAImporter, generating an EA Architecture view:

    port_model_ea_architecture_view

    In the resulting RFG, components, ports, required interfaces, provided interfaces, interfaces, and operations are represented by nodes of type UML Component, UML Port, UML RequiredInterface, UML ProvidedInterface, UML Interface, and UML Operation, respectively. Interfaces are specified separately in the Interfaces package; they each contain one or more operations. An interface is implemented by a component; this is represented in the model by a port that contains a provided interface (e.g., the output interface is provided by component display). It can also be used by another component if that component contains a port with a required interface of the same name as the interface (e.g., output in component app). Components that use interface operations without such a required interface violate the model.

  2. The UML Port elements cannot be checked directly by the architecture analysis; they must be transformed. Similarly, the interfaces in this example are not located within their respective components, but separately in a package. Let us look at this detail of the model:

    port_model_transformation_a

    The customized rule Architecture-PortModelTransformation copies each interface (e.g., sensor_b) and its contained operations to the component that provides that interface (e.g., sensors for sensor_b). It then removes the ports and the provided and required interfaces, replacing them with edges of type Call, with the source being a component requiring an interface I, and the target being the interface itself (e.g., app -> sensor_b):

    port_model_transformation_b

    Additionally, to focus on dependencies between components, a Source_Dependency edge C -> C is added for each component C to allow all defined interfaces and other parts of the component to access each other. The result looks like this:

    port_model_architecture_view

  3. An instance of the rule Architecture-PortModelMapping creates a mapping between File (code) and Architecture; by comparing their respective names, directories are mapped to nodes of type UML Component and functions are mapped to nodes of type UML Operation:

    port_model_mapping_view

  4. Finally, an instance of the rule Architecture-ArchitectureCheck performs the actual check:

    port_model_result_view

Customized rules such as Architecture-PortModelTransformation can also issue warnings if, for example, the model is inconsistent (e.g., no interface is provided for a specified provided interface).

Example 3: Architecture-As-Code

The third example does not use a CASE tool; instead, both the architecture model and the mapping are specified using Python files.

The configuration is located within engine_demo/axivion/architecture_as_code in the example archive.

To support modeling using Architecture-As-Code, the Axivion Suite provides the rule Architecture-ScriptedArchitecture and the Python module bauhaus.architecture.scripted_architecture. This module offers abstractions in the form of Python classes for:

  • architecture projects, which combine an architecture and a mapping,

  • architectures,

  • mappings between architecture and code,

  • simple components, and

  • components split into a public interface and a private implementation.

Architecture and mapping information is specified in one or more Python files. In the example project, each top-level component has its own Python file that specifies the component’s outgoing dependencies as well as information about the mapping from source code to architecture. Architecture and mapping are specified by the configuration option Architecture-ScriptedArchitecture/architecture_files of rule Architecture-ScriptedArchitecture. When the rule is executed, it evaluates the files in the given order. When using more than one Python file to specify the model, it is advisable to use dedicated initial and final Python files, such as model/setup_initial.py and model/setup_final.py. In model/setup_initial.py, an ArchitectureProject instance PROJECT and the component instances are created. An architecture project holds the architecture and the code-to-architecture mapping in a single object and operates on the RFG of the running analysis.

# import the basic library for creating architectures and mappings
from bauhaus.architecture.scripted_architecture import *

PROJECT = ArchitectureProject(
        "Architecture",  # name of the architecture view to create
        'File',  # name of the hierarchy view the mapping resolves code paths in
        Component("Engine_Ctrl"),
        Component("Sensor"),
        Component("IO", Component("Display"), Component("File_System")),
        Component("App"),
        ComponentWithInterface("HW"),
        name="My Architecture",
    )

app = PROJECT.App # access of components via dot-notation

The first argument is the name of the architecture view to be created, and the second is the name of the hierarchy view in which the mapping resolves its code paths. All further positional arguments are architecture entities. The name of the mapping view defaults to Mapping and can be provided as the keyword argument mapping_view_name; the keyword argument name sets the name of the project entity itself, which defaults to the name of the architecture view.

For example, a component named Engine_Ctrl is created as part of the project. Components can also be nested by providing additional arguments; for example, the IO component contains two sub-components, Display and File_System. Components can be accessed using dot notation, starting with the project (e.g., PROJECT.IO.File_System).

You can now define dependencies between components and provide mapping information. Refer to model/app.py:

app = PROJECT.App

# outgoing dependencies
app.depends_on(PROJECT.Engine_Ctrl) # app depends on Engine_Ctrl
app.depends_on(PROJECT.IO)
app.depends_on(PROJECT.Sensor)

# mapping
app.add_mapping('src/app')

The depends_on method is used to specify dependencies; for example, App depends on Engine_Ctrl. The mapping is specified using add_mapping, called on the entity to which the code belongs. Its argument is a string denoting the path to the desired code node in the used hierarchy view, with node names separated by slashes. The same mapping can also be defined from the project level as PROJECT.add_mapping('src/app', app), where the entity is the second argument. These two forms are equivalent, including additional options such as is_private. Arbitrary Python syntax can be used to specify a mapping, for example:

for prefix in ('final', 'init'):
    app.add_mapping(f'src/{prefix}_app')

The HW component is a specialized instance of ComponentWithInterface; such components allow the specification of a private (implementation) part and a public part. If another component is permitted to access HW, it may only access the public part. Use the is_private argument of the add_mapping method to specify whether a code entity should be mapped to the private or public part (see model/hw.py):

hw = PROJECT.HW

# mapping
# everything in the component is private...
hw.add_mapping('src/hw', is_private=True)
# except public headers (like hw_public.h)
hw.add_mapping('src/hw/hw_public.h', is_private=False)
hw.add_mapping('src/hw/error_code.h', is_private=False)

After specifying the architecture in this way, model/setup_final.py creates the resulting architecture and mapping views in the RFG:

# At the end: create the actual views.
PROJECT.create_views()

The analysis is performed using the following rules:

  1. The execution of Architecture-ScriptedArchitecture creates the views Architecture and Mapping.

    arch_as_code_arch_view

    arch_as_code_mapping_view

  2. An instance of the rule Architecture-ArchitectureCheck performs the actual architecture check:

    arch_as_code_result_view

Specifying architecture and mapping separately

The Architecture and Mapping classes can also be used independently, as in configurations written before the introduction of ArchitectureProject. In such cases, the RFG must be passed explicitly using the global variable INPUT_RFG provided by Architecture-ScriptedArchitecture, and the two views are created separately:

ARCH = Architecture(
        "My Architecture",
        Component("Engine_Ctrl"),
        ComponentWithInterface("HW"),
    )
MAPPING = Mapping(INPUT_RFG, 'File')

ARCH.Engine_Ctrl.depends_on(ARCH.HW)
MAPPING.add_mapping('src/engine_ctrl', ARCH.Engine_Ctrl)

# At the end: create the actual views.
ARCH.create_view(INPUT_RFG, "Architecture")
MAPPING.create_mapping_view("Mapping")

Both styles remain fully supported; ArchitectureProject is an alternative, not a replacement. The mapping of a project is available via PROJECT.mapping() if it needs to be passed on.

4.1.2.5. Architecture Reengineering

In addition to checking source code conformance to an architecture, the Axivion Suite can be used to reengineer an architecture from scratch using the source code.

This is useful if the architecture model is outdated and no longer reflects the current state of the software system, or if no architecture model exists and one must be created from the source code. Specifically, when modeling a system’s detailed design down to the routine and variable level, manual creation of an architecture model can be very time-consuming. Therefore, it is often more efficient to reengineer the architecture from the source code and then refine it manually.

The reengineering functionality provided by the Axivion Suite offers several configuration options to control the resulting architecture model. For example, you can specify which source code dependencies should be considered for reengineering and how they should be interpreted, or define the appearance of the resulting architecture model (e.g., whether it should contain only components or also details such as structs, classes, and routines/operations, and how these should be modeled).

The generated architecture model represents the current state of the software system, including all existing dependencies. It can then be used as a starting point for architecture modeling and is ready for architecture verification. This reengineered architecture model can also be exported to Enterprise Architect using one of the two exporter rules provided by the Axivion Suite, which can then be used as a base for architecture verification.

The following section illustrates how to reengineer an architecture from scratch for a C-based project. We will then show the workflow for using the resulting architecture model for architecture verification. There are two options for this:

  1. Use Gravis as the base for architecture verification.

  2. Export the resulting architecture model to Enterprise Architect (EA) to use EA for modeling or representing the architecture.

Additional information about modeling further architectural details is provided at the end of this section.

Example Analyses Contained in the Axivion Suite

Similar to the examples in Modeling using CASE tools and Architecture-As-Code, the rules and configurations described below can be found in the archive example/architecture_examples.zip (Windows) or example/architecture_examples.tar.xz (Linux and macOS) in the Axivion Suite installation, together with example source code. More details about running the “base” analysis are provided in the README.txt file within the archive. The corresponding configuration directory is reengineering.

Reengineering an architecture from scratch for a C-based project

We create an architecture from scratch for the example project engine_demo.

First, we define the desired architecture and what should be represented. We begin with the following modeling rules:

  1. Directories should be modeled as packages in the architecture.

  2. Source code modules (i.e., compilation units) should be modeled as components in the architecture.

  3. Dependencies should be modeled as edges between the components.

These modeling decisions are reflected in the configuration options for rule Architecture-Reengineering across the different configurations.

Note that the example uses the RFG hierarchy view Module, in which a header file and its corresponding implementation file are represented by a single Module node; for example, engine.c and engine.h yield one component, engine. With the hierarchy view File (the default for rule Architecture-Reengineering), header and implementation files are represented as separate components that share their name but are distinguished by their linkage names.

This modeling approach is similar to the “Package model” in Modeling using CASE tools and Architecture-As-Code. However, files are now modeled as components, and dependencies are modeled at the component level rather than the package level. The resulting architecture model is shown in the figures below: first the model in Gravis, then the same model in EA after export.

Reengineered architecture in |gravispro|.

Reengineered architecture in Gravis.

Reengineered architecture in Enterprise Architect.

Reengineered architecture in Enterprise Architect. Diagram has been created manually.

Various modeling rules and resulting architecture models are possible.

Two different workflows for architecture reengineering are explained in detail below.

Workflow 1: Export to GXL and verify in Gravis

In this workflow, the reengineered architecture is exported to GXL files that can then be used directly in Gravis for architecture verification.

  1. Initial Reengineering: Extract the architecture from code and export to GXL:

    do_reengineering.bat gravis
    

    This uses reengineering_config_gravis.json and exports the architecture and mapping to architecture.gxl and mapping.gxl. It generates an architecture by instantiating the rule Architecture-Reengineering with configuration options that reflect the modeling decisions described above. This step is typically performed only once to obtain the initial architecture and mapping. These GXL files can then be modified to refine the architecture model or the mapping.

  2. Verification: Verify using the exported GXL files:

    gravis_based_analysis.bat
    

    This uses gravis_based_analysis.json to import the GXL files and run architecture verification (see Architecture Analysis). This mode is intended for day-to-day architecture verification using Gravis.

Workflow 2: Export to Enterprise Architect and verify

In the alternative workflow, the reengineered architecture is exported to an Enterprise Architect file (model.qea) where it can be inspected and refined before being used for architecture verification.

  1. Initial Reengineering: Extract the architecture from code and export to EA:

    do_reengineering.bat ea
    

    or

    do_reengineering.bat ea_native
    

    This uses reengineering_config_ea.json (ea) or reengineering_config_ea_native.json (ea_native) to extract the architecture and export it into model.qea. The ea variant uses an interface to an existing Enterprise Architect installation to generate the model.qea, while the ea_native variant does not require an existing Enterprise Architect installation. Therefore, if you are using a non-Windows system or one without an Enterprise Architect installation, you should use the ea_native variant. The rule used by the ea variant is Architecture-EAExporterCom, while the ea_native variant uses the rule Architecture-QEAExporter. The ea and ea_native variants may not generate identical results.

    Note that any previous content of model.qea is overwritten in this step.

  2. Verification: Verify the code against the exported architecture:

    ea_based_analysis.bat
    

    This uses ea_based_analysis.json to import the architecture from model.qea and run architecture verification. The configuration again instantiates the rule Architecture-Reengineering, but uses a slightly different “mode” for the rule: the option external_architecture_view_name is now set to EA Architecture (the imported EA view name). In this mode, the rule regenerates the architecture by inspecting the source code, compares it to the external architecture view, and reports structural differences as stylecheck findings. This may occur, for example, if new components were not correctly added to the initial model during project evolution. The external architecture view is not “overwritten” by the current state. When comparing the generated architecture with the external architecture view, elements are matched by name and type. If several sibling elements share the same name and type (e.g., separate components for header and implementation files in the File hierarchy view, or overloaded operations in detailed modeling), they are matched using the Axivion.LinkageName tagged value. This value is attached to every generated element by the EA exporters and imported by the EA importers by default (see option imported_tagged_values of rule Architecture-QEAImporter). The tagged value can be edited within Enterprise Architect, for example, to resolve ambiguities for elements that were added to the model manually. To find the linkage name of an element when remodeling, look it up on the corresponding element of the generated architecture: Gravis shows it as the Linkage.Name attribute of the element, and a freshly exported EA model carries it in the Axivion.LinkageName tagged value. The rule generates two additional views:

    • “EA Architecture Mapping”: a mapping view between the current state and the external architecture view.

    • “EA Architecture for check”: an architecture view structurally similar to the external architecture view, but with edge types translated from UML-based dependencies to source dependencies.

    These two views are then used for the actual architecture check.

With this approach, the architect is able to model within EA and use the Architecture Verification feature of the Axivion Suite. To do so, they must follow the modeling rules defined for Architecture-Reengineering to ensure that the resulting architecture can be used for architecture verification (e.g., in our example: modeling directories as packages, etc.). In later versions of the Axivion Suite, we plan to provide more flexibility for modeling within EA, e.g., by allowing an additional logical layer above the reengineered architecture, where the architect can model more freely.

Options for modeling more architectural details

The example model is kept simple by only modeling directories and source modules. However, the Architecture-Reengineering rule offers many options for modeling additional architectural details, e.g., to reengineer the detailed design level of the software project: Types such as classes, structs, unions, routines, methods, and variables can also be reengineered. Therefore, the example includes a variant of (2) that uses a more refined architecture model:

do_reengineering.bat ea_detailed

or

do_reengineering.bat ea_detailed_native
ea_based_detailed_analysis.bat

It also considers classes, structs, unions, routines, methods (for C++), variables, and typedefs as architectural entities. The translation is controlled by the transformation option of the rule Architecture-Reengineering (see reengineering_config_ea_detailed.json):

The resulting architecture in EA is shown in the figure below.

Reengineered detailed architecture in Enterprise Architect.

Reengineered detailed architecture in Enterprise Architect. The diagram was created manually.

4.1.2.6. Qt signal-slot connections

Signal-slot connections are an essential aspect of software systems based on the Qt Framework. The Frameworks-QtSupport rule can add Qt-specific edges to the graph that represent these connections in the RFG. If the rule is enabled, its create_qt_connect_edges option (enabled by default) controls whether these edges are created.

Consider a class SpeedSensor with a signal value_changed(int) and a class SpeedIndicator with a slot update(int). A third class, InstrumentPanel, has a method setup_components() that connects the signal SpeedSensor::value_changed to the slot SpeedIndicator::update.

In the Code Facts view, the following edges are added:

  • A Qt_Connect_Signal edge from setup_components to the SpeedSensor::value_changed signal. Note that this signal node belongs to the generated moc file for the header file defining SpeedSensor because that is where its generated implementation is located.

  • A Qt_Connect_Slot edge from setup_components to the SpeedIndicator::update slot. This slot node belongs to the source file in which the method is implemented.

  • A Qt_MetaObject_Call edge from the signal to the slot, representing the dynamic call made at runtime.

Figure 3 shows the resulting RFG structure.

Note

The source locations of the node representing the signal and the Qt_MetaObject_Call edge representing the dynamic call are both in the generated moc file. Consequently, any violations that would be reported for these entities are excluded, as the Frameworks-QtSupport rule adds a global exclude pattern for generated moc files.

Example for Qt-specific edges.

Figure 3: Edges representing signal-slot connections

The structure in Declaration Facts is similar, except that the method node for setup_components belongs to the header file where the class InstrumentPanel is declared, and the method node for SpeedIndicator::update belongs to the header file where the class SpeedIndicator is declared. The node for the SpeedSensor::value_changed signal still belongs to the generated moc file, as in the Code Facts view.

Note

The Qt_Connect_Signal and Qt_Connect_Slot edges are particularly important when using the legacy connect() mechanism with the SIGNAL and SLOT macros, as signal and slot functions would otherwise be considered dead code. If the newer mechanism using member function pointers is used, Method_Address edges already exist between the routines containing the connect() calls and the referenced signal/slot member functions.

4.1.3. FAQ

Q: How do I configure the checks of a Gravis architecture project?

A: Follow these steps to configure the checks of an architecture project created in Gravis (see Architecture Projects):

  1. Open the project configuration with axivion_config

  2. Select the configuration layer where you want to perform architecture checks

  3. Search for the Architecture-GravisArchitectureProject rule and add it to the Architecture pipeline by selecting Add to active list... from its context menu.

  4. Configure the architecture_project_file option by double-clicking it and selecting the project file (extension .gaproj)

  5. Optionally, restrict the checks to be run using the checks option; by default, all checks of the project are run

  6. Save the configuration and run your analysis using your usual method (e.g., start_analysis.bat)

Q: How do I configure Gravis architecture checks using exported GXL files?

A: Follow these steps to configure Gravis architecture checks using exported GXL files:

  1. Open the project configuration with axivion_config

  2. Select the configuration layer where you want to perform architecture checks

  3. Search for the Architecture-GravisArchitecture rule and add it to the Architecture pipeline by selecting Add to active list... from its context menu.

  4. Configure the architecture_file and mapping_file options by double-clicking them and selecting your exported GXL files

  5. Save the configuration and run your analysis using your usual method (e.g., start_analysis.bat)