Skip to content
Jonatan E. Salas edited this page Aug 17, 2017 · 1 revision

Concepts behind the starter

The typescript-hapi-starter project was built with the intention to simplify the way we develop APIs. Also, it's intended to provide different branches that provides a set of integrations with different data stores, like SQL databases through Sequelize, NoSQL databases like MongoDB through Mongoose, and a last one where we provide a basic GraphQL API.

There's also a set of core concepts that we try to implement in the starter, and here we'll document it. The kit provides a set of abstractions like:

  • Model
  • Repository
  • Resolver
  • Service
  • Controller
  • Route Validator

Model

The model is a description of a shape with its properties. In our case, the model should match the SQL Table or a MongoDB/NeDB Collection specification.

NeDB Model E.G.

class User {
    public name: string;
    public lastName: string; 
}

Repository

The repository wraps the model usage. It's main responsibility is to provide a set of base operations that let you do more complex operations.

Resolver

The resolver is similar to the DAO pattern, It's main responsibility is to use different repositories objects if needed to perform complex queries.

Service

The service provides a top level abstraction over the resolver. It's main responsibility is to use Resolvers to resolve business centric logic.

Controller

The controller takes a request and response object, and perform transformations over the incoming data by the usage of services.

Route Validator

The route validator is a simple module exporting an object that contains Joi definitions to perform checks over the request params/query/payload/headers.

Clone this wiki locally