Strategic architecture, tactical design, and testable code principles (SOLID, Clean Architecture, Design Patterns, Testable Design)
71
89%
Does it follow best practices?
Impact
—
No eval scenarios have been run
Passed
No known issues
The Dependency Rule states that source code dependencies can only point inward toward higher-level policies. Inner circles must never reference outer circles.
Incorrect (inner layer imports from outer layer):
// domain/entities/Order.ts - ENTITY LAYER
import { OrderRepository } from '../../infrastructure/OrderRepository'
import { EmailService } from '../../infrastructure/EmailService'
export class Order {
constructor(
private repo: OrderRepository, // Changes to repo implementation break Order
private email: EmailService
) {}
async complete() {
await this.repo.save(this)
await this.email.notify(this.customerId) // Cannot test without email server
}
}Correct (inner layer defines interface, outer layer implements):
// domain/entities/Order.ts - ENTITY LAYER
export interface OrderPersistence {
save(order: Order): Promise<void>
}
export interface NotificationPort {
notify(customerId: string): Promise<void>
}
export class Order {
constructor(
private repo: OrderPersistence,
private email: NotificationPort
) {}
async complete() {
await this.repo.save(this)
await this.email.notify(this.customerId)
}
}
// infrastructure/OrderRepository.ts - INFRASTRUCTURE LAYER
import { Order, OrderPersistence } from '../domain/entities/Order'
export class OrderRepository implements OrderPersistence {
async save(order: Order): Promise<void> { /* DB implementation */ }
}Benefits:
Reference: The Clean Architecture
.tessl-plugin
clean-architecture
references
design-patterns
references
solid-principles
testable-design