Перейти к основному содержимому

Правила Зависимостей Между Слоями

Назначение

Документ фиксирует допустимые зависимости между проектами и слоями backend-сервисов. Цель — убрать свободную интерпретацию и сделать архитектурные нарушения проверяемыми architecture tests.

Разрешенные Зависимости

ПроектМожет Ссылаться На
Pin.<Service>.DomainTalent.Common.Domain
Pin.<Service>.ApplicationDomain, BuildingBlocks.Application, BuildingBlocks.Domain, contracts нужных external events/API models
Pin.<Service>.InfrastructureApplication, Domain, BuildingBlocks.Infrastructure, Messaging, Search, Analytics, Resilience, provider SDK
Pin.<Service>.ApiApplication, Infrastructure, BuildingBlocks.Identity, Observability
Pin.<Service>.BackgroundApplication, Infrastructure, Contracts, BuildingBlocks.Messaging
Pin.<Service>.MigratorInfrastructure
Pin.<Service>.ContractsPin.Contracts.*, BuildingBlocks.Domain только для primitive ids/value objects

Запрещенные Зависимости

  • Сервис не ссылается на project другого сервиса.
  • Domain не ссылается на Application, Infrastructure, Api, EF Core, ASP.NET Core, MassTransit, Redis, Elasticsearch, ClickHouse.
  • Application не ссылается на Api, Infrastructure, HttpContext, EF Core, provider SDK.
  • Contracts не ссылается на service implementation projects.
  • Api не использует DbContext и repositories напрямую.
  • Infrastructure не принимает бизнес-решения вместо handler/domain.
  • Background не обходит MediatR для business operation.

Namespace Convention

Application feature slices:

Pin.<Service>.Application.<FeatureGroup>.<Feature>

Примеры:

  • Pin.Identity.Application.Users.GetUserRoles
  • Pin.Accounting.Application.Withdrawals.ApproveWithdrawal
  • Pin.PromoPartner.Application.Partners.SearchPartners

Infrastructure implementations:

Pin.<Service>.Infrastructure.Persistence.Repositories
Pin.<Service>.Infrastructure.Integrations.<ProviderName>
Pin.<Service>.Infrastructure.Search.<FeatureGroup>
Pin.<Service>.Infrastructure.ClickHouse.<FeatureGroup>

Tests mirror production namespace:

Pin.<Service>.Application.Tests.<FeatureGroup>.<Feature>

Разрешенные Исключения

Исключение допускается только через ADR или explicit section в service README:

  • причина;
  • временный или постоянный характер;
  • срок пересмотра;
  • компенсирующие тесты;
  • owner.

Architecture Tests

Эти правила должны проверяться в CI. Минимальный набор:

  • Domain не содержит forbidden namespaces;
  • Application не содержит Microsoft.AspNetCore, Microsoft.EntityFrameworkCore, provider SDK namespaces;
  • service projects не ссылаются друг на друга;
  • controllers не имеют constructor dependency на DbContext;
  • handlers не используют HttpContext;
  • repositories не возвращают IQueryable наружу;
  • contracts не содержат object, JsonDocument, Dictionary<string, object> без approved typed model.

Связанный стандарт: Architecture Tests.

Обратные ссылки

Автоссылки: где используется этот документ.