Open sandboxFocusImprove this doc

Verifying architecture

Note

This feature requires a Metalama Professional license.

This chapter explains how to verify your source code against architecture, design patterns, and other team conventions.

You can add verification rules to your code in two ways: declaratively by applying custom architecture attributes, or programmatically using a compile-time fluent API. Metalama provides pre-made custom attributes and compile-time methods. You can also create your own attributes or methods for project-specific rules.

Benefits

Verifying code against architecture is particularly important for projects developed by a large team or maintained over a long period.

  • Executable rules instead of paper guidelines: Architectural guidelines are enforced in real time within the code editor, not just written down and stored away.
  • Immediate feedback: Developers receive feedback within seconds without waiting for the CI build to finish.
  • Smoother code reviews: Rule violations are automatically detected, allowing code reviews to focus on flows and concepts.
  • Better team alignment: Automated code validation promotes the team's adherence to consistent patterns and practices.
  • Lower complexity: The resulting codebase is simpler when everyone on the team adheres to consistent patterns and practices.
  • Reduced architecture erosion: The gap between the initial architecture and its implementation in the source code remains smaller.

In this chapter

This chapter includes the following articles:

Article Description
Verifying usage of a class, member, or namespace Validate the usage of namespaces, types, or members by restricting who can access them.
Enforcing naming conventions Enforce naming conventions in your code.
Marking experimental APIs Mark an API as experimental to trigger a warning when it's used.
Restricting who can implement an interface Restrict who can implement an interface.
Creating your own validation rules Create custom attributes or fabric extension methods to validate your own architectural rules.