Data source is a low-level layer that directly define how our app interact with Database. This layer handles how does our app can get or mutate data on DB.
Repository Layer is a layer to abstract the data access. This logic layer doesn’t need to know about DB and it’s implementation. By that, our logic doesnt care whether we use mongodb/mongoose, they only care about the returning result.
Example:
import UserDataSource from "../user/user.datasource"
Usecase layer is a layer to implement the business logics or workflows. In terms of clean architecture, we shouldn’t place all business logic in a controller. Instead, we wrapped up all related logic into a usecase layer by it’s context (e.g GetUserUsecase)
The implementation of this layer is to keep controllers clean and neat. The controllers should be focus to handle request and response.
❌ Example of controller without usecase layer
import UserModel from "../models/user.model"
export const getUser = async () => {
const user = await UserModel.findOne({ email: req.body.email });
if (!user) return res.status(404).json({ message: "Not found" });