This document sets the software quality standards, the mandatory tooling protocols and the non-negotiable rules for the Anima project. Every agent working on this codebase must follow them strictly.
- Immediate check: As soon as you take over a project, check whether the folder is a Git repository (
git rev-parse --is-inside-work-tree). - Initialization: If there is no repository:
- Run
git init. - Add the official, complete .NET
.gitignore(bin/,obj/,.vs/,.sonarqube/,TestResults/, logs, caches). - Make a clean initial commit.
- Run
- Commit cycle: Each feature batch, refactoring or fix validated by the tests gets its own atomic Git commit following Conventional Commits (
feat:,fix:,refactor:,test:,style:,chore:).
- SonarQube is not optional: It is the final judge of code quality.
- Provisioning: When the quality harness is installed, make sure the project is registered on the local instance (
http://localhost:9000) with the project keyAnima. - Continuous validation: The
./verify.ps1script runs the SonarScanner analysis. No task is complete until it reports QUALITY GATE STATUS: PASSED.
- Absolutely forbidden: suppression directives and attributes:
#pragma warning disable// NOSONAR[SuppressMessage]- The null-forgiving operator
!(in application and domain code).
- Principle: Always fix the root cause with strict typing (
Nullable<T>, explicit guard clausesArgumentNullException.ThrowIfNull, pattern matching checksis not null).
- Forbidden: silent exception blocks (
catch { }orcatch (Exception ex) { }with no action). - Catch only explicitly expected typed exceptions (e.g.
IOException,UnauthorizedAccessException). - When catching, always:
- Log the problem with structured logging (
ILoggerorRaiseLog), or - State in the block the compelling reason why the exception is tolerated.
- Log the problem with structured logging (
- Forbidden: creating or keeping classes, folders or namespaces with generic suffixes or prefixes:
*Helper**Utils**Manager**Common*
- Each component must be named after its single business responsibility:
*Calculator(metrics, predictive algorithms)*Validator(compliance rules, disk validation)*Parser/*Formatter/*Serializer(format conversion, XML, text)*Provider/*Resolver(identifier resolution, system discovery)*Advisor(hardware recommendations, heuristics)*Dashboard/*Reporter(UI rendering and console display)
- When a method has a high cyclomatic or cognitive complexity, never chop it into meaningless technical fragments (
Part1,Part2,SubMethodA). - Extract coherent domain abstractions instead: a dedicated component, a Value Object, a polymorphic strategy or a clear functional pipeline.
- Guard clauses: Check preconditions at the start of methods (
if (condition) return ...;) to keep indentation to at most 2 levels. - Immutability by default: Prefer immutable structures (
readonly,record,initaccessors, read-only collectionsIReadOnlyList<T>). - Useful comments:
- NEVER paraphrase the code (the code must be expressive and self-documenting).
- Comments explain only the WHY: non-obvious architecture decisions, workarounds for OS/terminal bugs, performance requirements, critical business invariants.
- Forbidden: flattering, vague qualifiers or AI verbal tics in the names of methods, classes, interfaces, variables, commits and comments:
*Robust**Resilient**Seamless**Smart**Advanced**Comprehensive**Ultimate*
- Principle: Name by the factual technical intent, not by a subjective self-assessment of the code quality:
- ❌
DeleteDirectoryRobust➔ ✔️ForceDeleteDirectoryorDeleteDirectoryWithRetries - ❌
RobustCopier➔ ✔️FileCopier - ❌
SeamlessRunner➔ ✔️SequentialTaskRunner
- ❌
- Mandatory naming: Every unit or integration test follows the pattern
TargetMethod_ScenarioOrCondition_ExpectedResult(e.g.Resolve_WhenUncPathHasDoubleBackslash_ReturnsNormalizedDiskId,CopyAsync_WhenTargetIsReadOnly_ThrowsUnauthorizedAccessException). - Principle: A failing test in the CI / SonarQube report must read as a broken business specification, without having to open the test body.
- Forbidden: passing primitive types (
string,int,long) around for business concepts that carry validation rules, invariants or specific formats (e.g. volume identifiers, normalized paths, hashes). - Principle: Wrap these concepts in immutable Value Objects (
readonly record structor sealedrecord class) validated when they are created.
- The domain and application core must never depend directly on concrete infrastructure (direct calls to
Console.*, raw disk access without abstraction, native OS APIs). - Every access to external resources or devices goes through clear injected abstractions (
ILogger,IFileSystem,IVolumeResolver), so that unit tests need no complex workarounds.
- Token propagation: Every asynchronous or I/O method takes a
CancellationToken cancellationToken = defaultparameter and passes it to every method it calls. - Honor cancellation: Never ignore a cancellation token or swallow an
OperationCanceledExceptionwithout rethrowing it, except for an explicitly documented graceful shutdown.
- Idiomatic syntax: Always use primary constructors to declare and inject the dependencies of classes and services (e.g.
public sealed class VolumeSnapshotProvider(ILogger logger, IFileSystem fileSystem) : IVolumeSnapshotProvider). - No boilerplate: Do not declare redundant
private readonlyfields when the primary constructor is enough. Check preconditions at initialization when needed.
- Documented contracts: Every public interface, interface method, public enum and contract property has complete XML documentation (
///) (<summary>,<param>,<returns>,<exception>). - No noise on internal code: Do not clutter private, local or obvious methods with mechanical XML comments. Keep XML documentation for the entry points and abstractions of the system.
- Scope: As soon as a project is a Web project (Blazor, ASP.NET Core MVC / Razor Pages, or a Web UI served by .NET), installing Playwright and setting up a dedicated E2E test suite are mandatory.
- UI coverage:
- Display & structural rendering: Check that containers, tables, forms, navigation bars and visual elements are present, visible and laid out correctly.
- Full interactivity: Trigger and validate 100% of buttons, navigation links, input fields, checkboxes, drop-down menus and modal windows.
- Data accuracy: Assert explicitly on the exact values displayed on screen (computed texts, amounts, counters, dynamic labels, confirmation or error messages).
- Mandatory Page Object Model (POM) architecture:
- Raw CSS or XPath selectors are strictly forbidden in test methods.
- Wrap each page or reusable component in a dedicated Page Object class (e.g.
LoginPage,DashboardPage,NavbarComponent) exposing business action methods and typed accessors.
- Strict test naming: The Rule 7 pattern is mandatory (e.g.
DashboardPage_WhenLoaded_DisplaysAccurateCounterValues,ExportButton_WhenClicked_TriggersDownload). - Automated run: Playwright tests must run on their own in headless mode (no visible UI) during the
./verify.ps1pipeline.
- Inspect first: Before implementing a technical component, a utility, an I/O operation, hashing, an algorithm or terminal rendering that is not business-specific, check the central catalog of shared frameworks (
FRAMEWORKS_INDEX.mdat the root of the shared frameworks folder). - No duplication: Never rewrite locally a building block that already exists in a shared framework. Reference the relevant project (
<ProjectReference>). - Backward-compatible evolution & overloads: When a framework feature must be extended or adapted:
- Change the component directly in the host framework through method overloads or optional parameters.
- Strictly preserve the existing contracts so that no other consumer project gets a breaking change.
- New framework & name approval: When a generic feature fits no existing framework and needs a new one, the agent must not create the project on its own. It must propose 2 or 3 plain, factual names (no AI buzzwords) to the user and wait for explicit approval before initializing the framework.
- Documentation update & mandatory validation:
- Update the
FRAMEWORK.mdfile of the framework as soon as a capability is added or changed. - Run
./verify.ps1at the framework root and make sure the SonarQube Quality Gate is PASSED before using the component in the client application.
- Update the
The project relies on a set of strict automated checks declared at solution level:
-
Global Roslyn analyzers (
Directory.Build.props):Roslynator.Analyzers(modern C# best practices and refactorings).Meziantou.Analyzer(API pitfalls, security and .NET performance).AsyncFixer(asynchronous anti-patterns and deadlocks).<TreatWarningsAsErrors>true</TreatWarningsAsErrors>(any warning breaks the build).
-
Style & formatting (
.editorconfig):UTF-8encoding,CRLFline endings, 4-space indentation.- File-scoped namespaces.
- Automatic sorting of
usingdirectives (System first). dotnet format --verify-no-changesalways run.
-
Single validation pipeline (
verify.ps1): The root./verify.ps1script runs the full chain and is the only acceptance condition for a change:- [1/6] Diagnostics & tool restore.
- [2/6] Formatting compliance (
dotnet format). - [3/6] SonarScanner initialization.
- [4/6] Non-incremental Release build with warnings as errors (
-warnaserror). - [5/6] Run 100% of unit, architecture and Playwright E2E tests (headless) with OpenCover coverage.
- [6/6] SonarQube upload and Quality Gate wait (
PASSED).