Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
In Clean Architecture, what is the core "Dependency Rule" that governs how layers relate to each other?
💻 Code Challenge | +75 XP
Refactor an Express route handler that directly creates a database record into three layers: a pure Order entity, a CreateOrder use case depending on an abstract repository interface, and an Express adapter wiring them together.
A team wants to unit test a core business rule (order approval threshold) without spinning up a database or an Express server. Reorder the steps to make this possible.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Placing business logic directly inside an Express route handler
// Wrong: business rule trapped inside Express
app.post("/orders", (req, res) => {
const status = req.body.total > 10000 ? "needs_review" : "approved";
});
// Correct: extracted, testable independent of Express
class Order {
constructor(total) { this.status = total > 10000 ? "needs_review" : "approved"; }
}The Solution //
Business logic coupled to req/res objects can only be tested by simulating an entire HTTP request, and can't be reused if the same logic is later needed from a CLI tool or a message queue consumer. Extract it into a framework-independent entity or use case that the route handler simply calls.
The Error //
Having a use case import a concrete database client directly instead of depending on an abstract interface
// Wrong: use case tightly coupled to a specific ORM
import { Order } from "./sequelize-models";
class CreateOrder { async execute(data) { return Order.create(data); } }
// Correct: depends on an abstraction, injected from outside
class CreateOrder {
constructor(orderRepository) { this.orderRepository = orderRepository; }
}The Solution //
This couples the use case to one specific database technology, defeating the purpose of the layering — swapping databases later requires rewriting the use case itself, not just its adapter. Depend on an abstract repository interface and inject a concrete implementation from the outer layer.