1. A use case
PlaceOrder is a use case — an application-specific operation that orchestrates the entities.
class PlaceOrder {Typorithm · hard
Step 1 of 8 · intro card
Layered & Clean
Clean architecture nests rings — entities, use cases, interface adapters, frameworks — and enforces the dependency rule: source dependencies point only inward. Use cases form the application core and depend on interfaces (dependency inversion), never on the database or framework.
Clean architecture draws concentric rings: enterprise entities at the center, application use cases around them, interface adapters next, and frameworks on the outer edge.
The dependency rule is the heart of it: source code dependencies may point only inward, so an inner ring never names anything in an outer ring.
Use cases like PlaceOrder are the application core; they depend on interfaces such as OrderRepo (dependency inversion), and the outer rings provide the concrete implementations.
Rings: entities -> use cases -> adapters -> frameworks.
The dependency rule: source dependencies point inward only.
Use cases depend on interfaces, not concrete databases.
// use case — the application core
class PlaceOrder {
constructor(private orders: OrderRepo) {}
exec(cmd) {
const order = new Order(cmd.items);
return this.orders.save(order);
}
}
// the boundary the use case depends on (inward)
interface OrderRepo {
save(order: Order): Order;
}Connect each part of the code to the concept before you type.
PlaceOrder is a use case — an application-specific operation that orchestrates the entities.
class PlaceOrder {The use case depends on the OrderRepo interface, not a concrete database — dependency inversion.
constructor(private orders: OrderRepo) {}The use case builds an Order entity; entities sit at the innermost ring.
new Order(cmd.items)OrderRepo is a boundary the use case owns; outer rings implement it so dependencies point inward.
interface OrderRepo {Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.