Правила Зависимостей Между Слоями
Назначение
Документ фиксирует допустимые зависимости между проектами и слоями backend-сервисов. Цель — убрать свободную интерпретацию и сделать архитектурные нарушения проверяемыми architecture tests.
Разрешенные Зависимости
| Проект | Может Ссылаться На |
|---|---|
Pin.<Service>.Domain | Talent.Common.Domain |
Pin.<Service>.Application | Domain, BuildingBlocks.Application, BuildingBlocks.Domain, contracts нужных external events/API models |
Pin.<Service>.Infrastructure | Application, Domain, BuildingBlocks.Infrastructure, Messaging, Search, Analytics, Resilience, provider SDK |
Pin.<Service>.Api | Application, Infrastructure, BuildingBlocks.Identity, Observability |
Pin.<Service>.Background | Application, Infrastructure, Contracts, BuildingBlocks.Messaging |
Pin.<Service>.Migrator | Infrastructure |
Pin.<Service>.Contracts | Pin.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.GetUserRolesPin.Accounting.Application.Withdrawals.ApproveWithdrawalPin.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.
Обратные ссылки
Автоссылки: где используется этот документ.
- implementation-blueprint.md (1): Implementation Blueprint
- adr (1): ADR-0013: Layer Dependencies И Architecture Tests
- backend-shared-standards-index.md (1): Backend Shared Standards Index