mirror of
https://github.com/samiyev/puaros.git
synced 2025-12-28 07:16:53 +05:00
feat: add aggregate boundary validation (v0.7.0)
Implement DDD aggregate boundary validation to detect and prevent direct entity references across aggregate boundaries. Features: - Detect direct entity imports between aggregates - Allow only ID or Value Object references - Support multiple folder structures (domain/aggregates/*, domain/*, domain/entities/*) - Filter allowed imports (value-objects, events, repositories, services) - Critical severity level for violations - 41 comprehensive tests with 92.55% coverage - CLI output with detailed suggestions - Examples of good and bad patterns Breaking changes: None Backwards compatible: Yes
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* ❌ BAD EXAMPLE: Direct Entity Reference Across Aggregates
|
||||
*
|
||||
* Violation: Order aggregate directly imports and uses User entity from User aggregate
|
||||
*
|
||||
* Problems:
|
||||
* 1. Creates tight coupling between aggregates
|
||||
* 2. Changes to User entity affect Order aggregate
|
||||
* 3. Violates aggregate boundary principles in DDD
|
||||
* 4. Makes aggregates not independently modifiable
|
||||
*/
|
||||
|
||||
import { User } from "../user/User"
|
||||
import { Product } from "../product/Product"
|
||||
|
||||
export class Order {
|
||||
private id: string
|
||||
private user: User
|
||||
private product: Product
|
||||
private quantity: number
|
||||
|
||||
constructor(id: string, user: User, product: Product, quantity: number) {
|
||||
this.id = id
|
||||
this.user = user
|
||||
this.product = product
|
||||
this.quantity = quantity
|
||||
}
|
||||
|
||||
getUserEmail(): string {
|
||||
return this.user.email
|
||||
}
|
||||
|
||||
getProductPrice(): number {
|
||||
return this.product.price
|
||||
}
|
||||
|
||||
calculateTotal(): number {
|
||||
return this.product.price * this.quantity
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user