Strategic architecture, tactical design, and testable code principles (SOLID, Clean Architecture, Design Patterns, Testable Design)
97
97%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
A good architecture allows major decisions about frameworks, databases, and delivery mechanisms to be deferred until the last responsible moment. The longer you wait, the more information you have.
Incorrect (early commitment to specifics):
// Day 1: "Let's use Prisma with PostgreSQL and Next.js"
// domain/Order.ts - Coupled to Prisma from the start
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
export async function createOrder(data: OrderInput) {
// Business logic intertwined with Prisma
const order = await prisma.order.create({
data: {
items: {
create: data.items.map(item => ({
productId: item.productId,
quantity: item.quantity,
price: item.price
}))
},
total: data.items.reduce((sum, i) => sum + i.price * i.quantity, 0)
},
include: { items: true }
})
return order
}
// 6 months later: "PostgreSQL doesn't scale for our read patterns,
// we need DynamoDB" - Massive rewrite requiredCorrect (defer database decision):
// Day 1: Focus on business rules, defer database choice
// domain/Order.ts - Pure business logic
export class Order {
private items: OrderItem[] = []
addItem(product: Product, quantity: number): void {
if (quantity <= 0) throw new InvalidQuantityError()
this.items.push(new OrderItem(product, quantity))
}
calculateTotal(): Money {
return this.items.reduce(
(sum, item) => sum.add(item.lineTotal()),
Money.zero()
)
}
}
// application/ports/OrderRepository.ts - Interface only
export interface OrderRepository {
save(order: Order): Promise<void>
findById(id: OrderId): Promise<Order | null>
}
// For now: Simple in-memory implementation for testing
// infrastructure/InMemoryOrderRepository.ts
export class InMemoryOrderRepository implements OrderRepository {
private orders = new Map<string, Order>()
async save(order: Order): Promise<void> {
this.orders.set(order.id.value, order)
}
}
// Later, when you know more: Add real database
// infrastructure/PrismaOrderRepository.ts
// OR
// infrastructure/DynamoOrderRepository.ts
// OR
// infrastructure/MongoOrderRepository.ts
// The domain never changes regardless of database choiceDecisions worth deferring:
Benefits:
clean-architecture
evals
references
design-patterns
solid-principles
testable-design