---
url: /howto/viewing-data-for-parts-of-code.md
---

# How to See Aggregated Data for Arbitrary Code Areas

Teamscale allows you to view data like metrics or findings for specific parts of your code.
There are two possible cases here:

\[\[toc]]

## Case 1: The relevant code parts are located inside a fixed **sub-directory** in your version control system.

In this (simple) case, all relevant pages in Teamscale (*Widgets*, *Findings*, *Metrics* and *Test Gaps* perspective) can be configured to only show the data for the sub path you are interested in.
Here is an example of the Metrics perspective showing information for a sub-path:

![Metrics Perspective Sub-Path](./metrics-subpath.png)

## Case 2: The relevant code parts are spread in arbitrary folders inside your version control system

Using Teamscale's **architectures**, you can divide your code base into arbitrary parts, for example

* **application** vs **test** code
* **server** vs **client** code
* (potentially overlapping) **team-specific** code areas within one big project
* etc.

This works in addition to the regular file-based paths, and you can specify any number of architectures.

Once an architecture was configured, Teamscale will calculate all of its metrics for each of its parts (so-called "components").

:::tip Architecture Paths
As rule of thumb, you can select "architecture paths" wherever you can select regular paths in Teamscale.
:::

### Creating an Architecture

To create a new architecture in Teamscale, the following steps are needed:

1. Go to the Architecture perspective

   ![Architecture Perspective](./architecture-1.png)

2. Create a new architecture. While these are usually used for our architecture conformance analysis, they can also be used to generate arbitrary views of your code.

   In our case, we will create an architecture that **separates test and application code**.

   ![New Architecture](./architecture-2.png)

3. Create a new **component** for the **application code** by selecting the component tool and clicking on the white drawing area.
   A component groups code from your code base under a logical name.
   You can resize and move the component with your mouse and rename it later if you wish.

   We'll choose "Application Code" for this example.

   ![Application Component](./architecture-3.png)

4. Click on the component.

   In the lower half of the screen, create two new **mappings** as shown below.
   These mappings define which code to assign to the component.

   ![Application Code Mappings](./architecture-4.png)

   In our example, we include all code (`.*`) and then exclude the test code (`.*/test/.*`).
   Adjust these patterns to the conventions used in your code base.
   You can add any number of exclude patterns.

   :::tip Pattern Format for Mappings
   The syntax used for the component patterns is regular expressions, which offers flexibility.
   :::

5. Next, create a component for your **test** code, the same way as described above, then click on it.

   ![Test Component](./architecture-5.png)

6. Add one or more include patterns that describe your test code.
   These should be the opposite of the patterns you used for the "Application Code" component.

   ![Test Code Mappings](./architecture-6.png)

7. Finally, change the settings in the lower left.
   As you don't want Teamscale to create findings for unmatched code ("orphans"), disable finding creation for the architecture.

   ![Findings Settings](./architecture-7.png)

   Save the architecture and give it a speaking name.

   :::warning Architecture Name
   The architecture name cannot be (easily) changed later.
   :::

   ![Save Architecture](./architecture-8.png)

On the main page of the Architecture perspective, you will see your new architecture.
Refresh the page until it has finished analyzing.

![Architecture List](./architecture-9.png)

### Viewing Data for a Specific Architecture

Once your architecture was stored and analyzed, you can view component-specific data by selecting the corresponding architecture path.

#### Example: Architecture Data in Metrics Perspective

In this example, we navigate to the Metrics perspective:

![Metrics Perspective in Sidebar](./metrics-in-sidebar.png)

On the main page of the Metrics perspective, scroll down to the **Architecture** section:

![Architecture Mappings](./architecture-metrics-root.png)

You will find your architecture there. Click on it.
This will list all the components you created for that architecture.
For each component, you will see the aggregated metrics for the code you added to that component.

![Component-based Metrics](./architecture-metrics-inside.png)

Clicking on a metric, e.g., Line Coverage, will give you more details.
Clicking on a component's name will show you all the code that is included in it.

#### Example: In Dashboard Widgets

You can also view component-specific data in most dashboard widgets.

In this example, we would like to see the test coverage percentage for just your application code.
To do this, we do the following:

1. we create a **Numeric Metric Value** widget, edit it and open the **Path** selection dialog.

   ![Widget Options](./widget-edit.png)

2. Select the artificial `-architectures-` path.

   ![Architecture Path](./architecture-path.png)

3. Select your architecture file.

   ![Architecture File Path](./architecture-file-path.png)

4. Select the component for which you'd like to view the metric value (e.g., your application code).

   ![Architecture Component Path](./component-path.png)

5. Click **OK** and save your changes to the widget.
   This is the result:

   ![Widget Showing Line Coverage](./final-widget.png)
