To Introduction

Microservice Facade

Step 1. Creating the Project’s Structure

In this tutorial, we will be using a demo project to develop a small facade for a system that consists of a few microservice:

  • Beacons - business logic microservice that performs the main operations of the system.
  • Accounts - microservice for managing user accounts
  • Passwords - microservice for managing user passwords
  • Roles - microservice for managing user roles
  • Sessions - microservice for processing user sessions

The Beacons microservice was demonstrated in the Data Microservice tutorial. The rest of the microservices are from our free Pip.Services Library.

The architecture of the system looks like this:

The facade microservice will be responsible for:

  • registering new users;
  • authorizing users and creating sessions for them;
  • checking whether or not a session has expired when an authorized user makes another request (session restoration);
  • providing access to the functionality of the Beacons microservice for authorized users.

Before starting, be sure to set up your environment and create a folder for the project. The directory structure of facade projects differs a bit from the structure we use when developing data microservices.


Create a package.json file at the root of the project with the following content to configure dependencies and project parameters:


  "name": "pip-facades-sample-node",
  "version": "1.0.0",
  "author": "Enterprise Innovation Consulting LLC.",
  "description": "Public facade for sample",
  "contributors": [
    "Sergey Seroukhov <>"
  "main": "./obj/src/index.js",
  "typings": "./obj/src/index.d.ts",
  "noAnalyze": true,
  "private": false,
  "scripts": {
    "start": "node app",
    "test": "mocha -t 10000 -R spec -u tdd --recursive ./obj/test",
    "benchmark": "matcha -R clean -I tdd ./benchmark/run.js"
  "dependencies": {
    "busboy": "^0.3.1",
    "pip-services3-commons-node": "^3.0.0",
    "pip-services3-components-node": "^3.0.0",
    "pip-services3-rpc-node": "^3.1.8",
    "pip-services3-container-node": "^3.0.0",
    "pip-services3-data-node": "^3.0.0",
    "pip-services3-mongodb-node": "^3.0.0",
    "pip-services-roles-node": "^1.1.0", 
    "pip-clients-roles-node": "^1.1.1",
    "pip-services-accounts-node": "^1.2.0",
    "pip-clients-accounts-node": "^1.1.2",
    "pip-services-sessions-node": "^1.1.0",
    "pip-clients-sessions-node": "^1.1.1",
    "pip-services-passwords-node": "^1.1.0",
    "pip-clients-passwords-node": "^1.0.1",
    "pip-services-beacons-node": "^1.0.0",
    "pip-clients-beacons-node": "^1.0.0"
  "devDependencies": {
    "@types/node": "*",
    "@types/lodash": "^4.0.0",
    "@types/async": "^2.0.0",
    "@types/mocha": "*",
    "@types/chai": "*",
    "mocha": "*",
    "chai": "*"
  "directories": {
    "test": "test"

Install all necessary modules using the command:

npm install

Create a TypeScript compiler configuration file with the following lines:


   "compilerOptions": {
"declaration": true,
       "module": "commonjs",
       "target": "es6",
       "noImplicitAny": false,
       "outDir": "obj",
       "rootDir": ".",
       "sourceMap": true,
"types": ["node", "mocha", "chai"]
   "exclude": [

Now our project is ready for development. Continue on to Step 2 - Business operations to start implementing the facade itself.