1. Presentation layer
The controller is the presentation layer; it accepts the request and delegates downward.
class OrderController {Typorithm · easy
Step 1 of 8 · intro card
Layered & Clean
Layered architecture stacks presentation over application/service over domain over data. Each layer depends only on the layer directly below it, so requests flow top-down and concerns stay separated.
An N-tier app is sliced into horizontal layers: presentation (controllers), application/service (use cases), domain (business rules), and data (persistence).
Dependencies point strictly downward — a controller knows the service, a service knows the repository, but no lower layer ever reaches up to a higher one.
Because each layer talks only to the one beneath it, you can change the database or swap the UI without rewriting the layers in between.
Layers stack: presentation -> service -> domain -> data.
Each layer depends only on the one directly below.
Dependencies and request flow both point downward.
class OrderController {
constructor(private service: OrderService) {}
create(req) {
return this.service.place(req.body);
}
}
class OrderService {
constructor(private repo: OrderRepository) {}
place(order) {
return this.repo.save(order);
}
}Connect each part of the code to the concept before you type.
The controller is the presentation layer; it accepts the request and delegates downward.
class OrderController {The controller holds a service, never the other way round — dependencies point downward.
constructor(private service: OrderService) {}The service layer holds business logic, isolated from HTTP details above it.
class OrderService {The service delegates persistence to the repository — the data layer one tier below.
return this.repo.save(order);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.