Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
What the example case that use all layer pattern?

I try to figure out what the different exactly with Model against Repository and Service. i found sometime Repository code will inside Model. Sometime will need middleman Service between Model and Repository.

View is to present data

// index.ejs
<% users.forEach(user => { %>
    <tr>
        <td>user['id']</td>
        <td>user['username']</td>
        <td>user['password']</td>
    </tr>
<% }) %>

// present data
1 ADMIN ADMINPASS
2 TEST  TESTPASS

Repository layer is a layer that logic action to interact with database.

class UserRepository {
    public selectAll(){
        return DBConnector.execute(query)
    }

    public insert({username, password})
    public update({username, password)
    public delete(id)
}

Controller is a layer that transform data from database, then throw that to view layer.

class UserController {
    public index(req, res){
        // Get all user, then transform to uppercase
        const usersList = new UserRepository.selectAll();
        const usersTransform = usersList[0].map(user => user.toUpperCase());
        res.render('index', {users: usersTransform})
    }
}

Route

app.get('/', new UserController.index)

When u need to use this layer? I see alot discusion when talking about MVC. it explains action logic that interact with database inside Model. sometime Model, Service, Repository interchangeable. so confuse right.

class UserService {

}

class UserModel {

}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!