Separates application validation errors from domain business rules

Moves the user settings, user id, scheduler display preference and thumbnail quality validation errors to the application error catalogs, leaves only business-rule errors in the domain catalogs, and records the domain-expert test for error ownership.
This commit is contained in:
BinaryAlley committed 2026-11-22 12:00:00 +03:00
1 parent 6e1253d3d5
commit 7f701ea3cc
30 files changed
+311 -273

No files matched your search

+2 -2
View File
@@ -16,8 +16,8 @@ These rules apply to every agent, on every task, in this repository. For C# code
- DataAccess persistence: repositories persist aggregate graphs only through the closed toolkit in `Lumina.DataAccess\Common\Persistence` (`EditableValuesCopier`, `CollectionReconciler`, `SharedReferenceResolver`). Those primitives must stay generic and entity-agnostic. Never add a per-entity helper to that folder, and never hand-roll an equivalent in a repository: generalize the primitive (generics plus a marker interface such as `ISharedReferenceEntity`) or keep the logic in the repository.
- Presentation layer: immediately decouples API contracts with manual mapping: ToQuery or ToCommand. FastEndpoints adds authentication by default, only `AllowAnonymous` is free access. Errors are always `ProblemDetails`.
- Application layer: mapping classes are extension methods in `Common\Mapping`, and each mapping file should *only* extend the type the name of the mapping file uses, ex: `UserEntityMapping` contains *only* `UserEntity` extension methods to map to other types. The used names are: `ToQuery`, `ToCommand`, `ToRepositoryEntity`, `ToRequest`, `ToResponse`, `ToDto`, `ToDomainEntity`, `ToDomainValueObject`. Any deviation needed is confirmed with the user. Validators validate application concerns: null or empty strings, negative numbers, correct emails, etc, they do not do async work and they do not do business rules validation. They are the first thing invoked in handlers. The next check should be for authentication/authorization.
- Domain layer: no nullable types or exceptions thrown. Use `Optional<T>` and `Result<T>`. Validations resume to *business rules* validations and invariants, not application validation.
- Application layer: mapping classes are extension methods in `Common\Mapping`, and each mapping file should *only* extend the type the name of the mapping file uses, ex: `UserEntityMapping` contains *only* `UserEntity` extension methods to map to other types. The used names are: `ToQuery`, `ToCommand`, `ToRepositoryEntity`, `ToRequest`, `ToResponse`, `ToDto`, `ToDomainEntity`, `ToDomainValueObject`. Any deviation needed is confirmed with the user. Validators validate application concerns: null or empty strings, negative numbers, correct emails, etc, they do not do async work and they do not do business rules validation. They are the first thing invoked in handlers. The next check should be for authentication/authorization. Validation error ownership is decided by the domain-expert test, not by the shape of the check: when a domain expert of that bounded context would state the rule in their own words, it is a business rule and its error belongs in `Domain/Common/Errors`; otherwise its error belongs in `Application/Common/Errors`.
- Domain layer: no nullable types or exceptions thrown. Use `Optional<T>` and `Result<T>`. Validations resume to *business rules* validations and invariants, not application validation. An error belongs in `Domain/Common/Errors` only when a domain expert of that bounded context would state the rule in their own words, whatever its technical shape. A VAT ceiling, a maximum seat count, or a required customer on an invoice is a domain rule; a positive id or a required database column is not (unless the domain of activity is database management).
- If a class or file is located or does things in a way that has no precedent in the code base, VALIDATE WITH THE USER FIRST! DO NOT introduce new patterns, styles and conventions without getting permission first!
## Documentation