🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

Untitled Lesson

Total XP: 0|💻 backend XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Select an unlocked node to view details root

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

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.

Continue Learning