PricingDownload
Product

Platform

All features48 capabilities, from IDE to CICompliance KitsISO 26262, DO-178C, IEC 62304...AI GovernanceControl AI-generated C/C++ codeWhat’s new in 2027Latest version highlightsScreenshotsSee the product in action

Analyze & improve

Coding standardsMISRA, CERT, CWE, AUTOSARArchitecture & dependenciesGraphs, matrix, cyclesSBOM & dependenciesIs our C++ code affected? Minutes, not weeksTechnical debtMeasured in hours and dollarsQuality gatesStop regressions in CISmart Code CityYour codebase in 3D

Integrations

IDE pluginsVisual Studio, VS Code, CLion...CI/CD pipelinesJenkins, Azure DevOps, GitHub, GitLabSonarQube pluginC/C++ results in SonarQubeExternal analyzersClang-Tidy, Cppcheck, coverageFeature on Demand
Solutions

By need

Functional safetyCompliance kits per standardCoding standardsMISRA, CERT, AUTOSAR, ISO...Legacy modernizationRefactor large C/C++ safelyCode auditExpert review of your codebaseM&A due diligenceAssess technical health fast

By role

DevelopersSoftware architectsTech leadsDevOps engineersEngineering managersProject managers

CTOsCIOs / IT leadersQA engineersSecurity leadersComplianceConsultantsRequest a guided PoC
Industries

Safety-critical

AutomotiveISO 26262, MISRA, AUTOSARAerospace & DefenseDO-178C programsMedical DevicesIEC 62304 softwareEnergy & UtilitiesIEC 61508 systemsEmbedded SystemsFirmware and devices

Enterprise

Financial ServicesTrading and paymentsGame DevelopmentEngines and large C++Software VendorsCommercial C/C++ productsGovernmentAgencies and contractorsAll industries & case studies
Resources

Learn

DocumentationGuides, rules and CI setupKnowledge baseFrequently asked questionsBlogC and C++ code quality articlesRelease notesEvery version since 2009

Customers

Case studiesSuccess storiesTestimonialsWhat users sayOur customersCompanies using CppDependGold Code QualityOpen source projects we rate

Programs & company

Feature on DemandMissing features built for freeFree for open sourceLicenses for OSS and studentsContact usSales and supportEULALicense agreement
Docs
Documentation

Design and Architecture

Design enforcement

Define what must use what and what must not, generate the CQLinq rules, and follow their status.

7 min readDesign and ArchitectureCppDepend 2027

Overview

Design enforcement turns architecture decisions into rules the analysis checks every time. You write them as sentences in a GUI (“UI must not use Data”, “Services may only use Core”, “this function must not call that one”), the tool generates the CQLinq rules, puts them in the query group Design Checkers of the project, and the page Design Enforcement Rules shows every rule with its status and violations.

Two pages work together:

  • Settings > Design Checkers: where you define layers and rules.
  • Design & Architecture > Design Enforcement Rules: where you see the results.

Quick start

  1. Open Settings > Design Checkers.
  2. In Layers and matrix press New layer, name it and add what belongs to it with Find in code (for example the namespaces of your UI).
  3. Create the other layers, then click the matrix cells: ✓ allowed, ✕ forbidden.
  4. Or in Rules press New rule and complete the sentence.
  5. Press Save. The queries are written into the group Design Checkers and the project is saved.
  6. Run the analysis, then open Design Enforcement Rules.

The Design Checkers editor

Three tabs:

TabPurpose
RulesList of rules on the left. On the right a rule is a sentence: Source, must / must not, Target, then name, severity, active, reason and how to fix. The panel at the bottom shows the checks of the rule.
Layers and matrixDefine layers (named groups of code) and fill the dependency matrix, which generates rules for you.
Generated queriesRead-only preview of the CQLinq of each active rule, as it will be written. A copy button is provided.

The bottom of the page sets the group name (default Design Checkers) and whether the group is written each time the project is saved. The status line counts rules, layers, errors and warnings.

Layers and patterns

A source or target is either a layer (@UI, chosen with the @ layer button) or a list of patterns separated by ;. A layer is a list of patterns, one per line. A leading ! excludes.

PatternMatches
ns:App.Ui.*The namespace of the element (a type is matched through its namespace). * and ? are wildcards.
type:*ControllerThe name of the type.
full:Foo::BarThe full name of a type.
method:Foo::Bar(int)The full name of a method or function (only in must not use).
name:strcpyA function by its simple name, for example a forbidden API.
!ns:App.Ui.Tests*Excludes what matches.

Without a prefix, a pattern is a namespace pattern. Patterns are written as typed: if your code model separates levels with ::, write them that way.

Rule kinds

KindReads asReported
must not useA must not use BTypes of A that use a type of B. If B (or A) holds methods or function names: the methods of A that call those functions or use those types.
may only useA may only use BTypes of A that use project code other than themselves and B. Third-party code is ignored by default (option).
must useA must use BTypes of A that use nothing of B.
must derive fromClasses of A must derive from BClasses of A with no base class in B.
must not derive fromClasses of A must not derive from BClasses of A that derive from B.
must be named likeClasses of A must be named like RClasses of A whose name does not match the regular expression R.
“Must not call” and “must not use” are one kind: pick types or namespaces and the check is on types; pick methods or a function name and it is on calls. Projects saved with the older “must not call” open as “must not use”.

Each rule also has a severity (Low, Medium, High, Critical; it sets the severity and the debt of its violations), a reason (shown in the rule description) and an optional how to fix text.

Layer matrix

Rows are the layer that uses, columns the layer that is used. Click a cell to cycle free → allowed → forbidden.

  • A row with at least one allowed cell becomes “A may only use…” with those layers.
  • A row with only forbidden cells becomes “A must not use…”.
  • Free cells say nothing.

Rules generated from the matrix are not listed in the Rules tab: they follow the matrix. Renaming a layer updates the matrix and the rules that refer to it.

Find in code

The Find in code button next to Source, Target and the layer patterns opens the product’s Code Search. Search by name, then double-click a namespace, type or method (or select it and press Add selected element). The tool asks the code model for its full name and writes it into the box as ns:…, full:… or method:…, then closes the search. A tick box adds * to include nested namespaces. Methods can only be picked when the rule kind is must not use.

The generated queries

Each rule becomes a CQLinq rule with the same layout as the rules shipped with the product, so it shows in the rule lists, the report and Coding Skills like any other rule. For example, UI must not use Data:

// <Name>UI must not use Data</Name>
//<RuleID>DC-001</RuleID>
warnif count > 0
from t in Types where t.ParentNamespace.NameLike(@"^.*\.Ui.*$")
let bad = t.TypesUsed.Where(u => u != t && u.ParentNamespace.NameLike(@"^.*\.Data.*$"))
where bad.Any()
select new { t, Uses = bad, Count = bad.Count(),
     Debt = 20.ToMinutes().ToDebt(),
     Severity = Severity.High
}
//<Description>
// UI must not use Data.
// Layered design: UI must not depend on these layers.
//</Description>
//<HowToFix>
// Remove the dependency or the call, or go through an abstraction owned by an allowed layer.
//</HowToFix>

Rule names are unique in the project (a suffix is added if needed). A read-only tab shows the exact text, with a bracket and quote check.

Saving and the cdproj

Two things are saved in the project file (.cdproj):

  1. Your definitions, element DesignCheckers: layers, rules and matrix cells. They are what you edit.
  2. The generated queries, as the group Design Checkers, Active and ShownInReport, in the project’s query groups. They are what the analysis runs.
<DesignCheckers GroupName="Design Checkers" AutoApply="true">
  <Layer Name="UI" Color="#4C8BF5"><Pattern>ns:*.Ui*</Pattern></Layer>
  <Layer Name="Data" Color="#E8A33D"><Pattern>ns:*.Data*</Pattern></Layer>
  <Rule Id="DC-001" Name="UI must not use Data" Kind="MustNotUse" Severity="High" Source="@UI" Target="@Data" />
  <Cell From="UI" To="Data" State="Forbidden" />
</DesignCheckers>

The group is rewritten completely on every save: do not edit its queries by hand, edit the rules here. Errors block the save; warnings do not.

Design Enforcement Rules page

Section Design & Architecture, same design as the Hotspots pages.

AreaContent
Tree (left)Rules grouped as Dependencies and calls, Inheritance, Naming, with violated/total per group. Each rule shows a status icon and its count.
TilesRules, Violated, Passing, Violations. A click selects the first matching rule.
Result (right)The sentence, the status and your reason, then the generated CQLinq in the editor and the grid of violating elements. You can edit the query and run it again to explore.
ButtonsEdit the rules opens the Design Checkers editor; Open DSM opens the dependency matrix.
StatusMeaning
✓Respected: no violation.
numberViolations. The colour follows the rule severity: red (Critical, High), orange (Medium), yellow (Low).
offThe rule is switched off.
not appliedSaved in the editor but the group was not written yet: save the rules.
not runThe query exists but there is no result yet: run the analysis.

Results come from the analysis, exactly like other rules: the group is active and shown in the report, so counts and statuses appear in the report and can feed quality gates in the same way.

Checks before saving

  • Rule name empty or used twice; source or target empty; unknown layer; invalid regular expression (naming rules).
  • A method used in a kind that does not accept methods.
  • Contradictions: the same source must use and must not use the same target.
  • Warnings: a layer without patterns matches nothing; a source equal to its target; a spec with only exclusions.

Limits

  • The queries use members of the code model (TypesUsed, BaseClasses, MethodsCalled, ParentNamespace, NameLike, FullNameLike). Their availability depends on the language model; check the first generated query by running it.
  • Rules are checked on the code of the analysed projects; third-party code is ignored where noted.
  • Matching is by name patterns: a renamed namespace needs a new pattern (Find in code gives exact full names).
  • The editor does not run queries itself; run the analysis to get results.

Questions

A rule shows “not applied”.

Press Save in the editor, and check that Write the group each time the project is saved is on.

Can I add my own CQLinq rule to the group?

It would be removed at the next save. Put your own rules in another group.

Where do I see a violation in the code?

Select the rule on the Design Enforcement Rules page and double-click a row of the grid, like in any query result.

Was this page helpful?
Evaluating CppDepend on a production codebase?Get a guided proof of concept with our static analysis architects.
Request a PoC