n-tier architecture with node.js - express - mongo and mongoose

Prensetation Layer

  • Controllers

    The code of the routes/endpoints. This layer is dumb and should not have any logic. If needed could orchestrate multiple services.

    knowledge of: payloads

  • Payloads

    It has the structure of the json that we should return on our api calls.

    knowledge of: payloads

Business Layer

  • Services

    All the business logic belongs here

    knowledge of: payloads, models

Data Layer

  • Models

    This is the database layer. We should define here the schemas of our mongo documents

    knowledge of: models

  • Repos

    It has the code that is reponsible to communicate with the database

    knowledge of: models

Common

  • Mappers

    knowledge of: payloads, models

Note: The "knowledge of:" is very important as it points out the knowledge of each layer. This gives us an advantage of having a clear separation of concerns (SoC) which makes the code easier to extend, maintain.

Endpoints

GET /bugs

Get a list of bugs sorted ASC by priority


GET /bugs/:id

Get a bug by id


POST /bugs

Create a bug


PUT /bugs/:id

Update a bug


DELETE /bugs/:id

Delete a bug