1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-26 13:48:33 +02:00

docs: ADR correct type dependencies (#9749)

This commit is contained in:
Mateusz Kwasniewski 2025-04-11 14:49:51 +02:00 committed by GitHub
parent 3b96bfb4ff
commit e003c10e94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 0 deletions

View File

@ -29,6 +29,7 @@ We are in the process of defining ADRs for the back end. At the time of writing
* [Specificity in database column references](./back-end/specificity-db-columns.md)
* [Write model vs Read models](./back-end/write-model-vs-read-models.md)
* [Frontend API Design](./back-end/frontend-api-design.md)
* [Correct type dependencies](./back-end/correct-type-dependencies.md)
## Front-end ADRs

View File

@ -0,0 +1,38 @@
---
title: "ADR: Domain Code Must Not Depend on Infrastructure Types (e.g., OpenAPI)"
---
## Background
Weve identified an architectural issue in our backend code: domain-layer code (especially store interfaces) sometimes directly references infrastructure-layer types, such as OpenAPI schemas.
This breaks a foundational principle of layered architecture: "Domain code should not depend on infrastructure, but infrastructure can depend on domain."
## Decision
All domain code—including store interfaces and business logic—must operate on domain types, not infrastructure types such as OpenAPI schemas.
Any mapping between API types and domain types must occur at the boundary (e.g., in controllers), not in the core logic.
## Consequences
* Clear architectural boundaries: Domain is isolated from infrastructure concerns like transport and serialization.
* Improved modularity: Domain logic can move between OSS and Enterprise without dragging along OpenAPI types or other infrastructure.
* Greater flexibility: We can evolve domain types rapidly and experimentally without worrying about breaking public API contracts.
* Increased mapping boilerplate: Conversion logic between domain and infrastructure types must be written explicitly at the boundaries.
## Example
Before
```typescript
store.createUser(user: CreateUserSchema): Promise<void>;
```
After
```typescript
// Domain-layer store uses a domain type
store.createUser(user: DomainUser): Promise<void>;
// API-layer controller maps OpenAPI to domain
const domainUser = mapFromApiType(apiUser);
await store.createUser(domainUser);
```