Step 2. 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 microservices:

  • 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:

facade architecture diagram

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, create a folder for the project. The directory structure of facade projects differs a bit from the structure we use when developing data microservices.

/bin
/config
/docker
/test
└───/fixture
└───/services
    └───/version1

/src
└───/build
└───/container
└───/operations
    └───/version1
└───/services
    └───/version1
/src
└───/version1
/test
└───/version1
/bin
/config
/docker
/test
└───/fixture
└───/services
    └───/version1

/build
/container
/operations
└───/version1
/services
└───/version1
/bin
/config
/docker
/test
└───/fixture
└───/services
    └───/version1

/lib
└───/build
└───/container
└───/operations
    └───/version1
└───/services
    └───/version1
/bin
/config
/docker
/test
└───/fixture
└───/services
    └───/version1

/src
└───/build
└───/container
└───/operations
    └───/version1
└───/services
    └───/version1
Not available
Create a /package.json file at the root of the project with the following content to configure dependencies and project parameters:

/package.json

{
  "name": "@pip-services/facade-sample-nodex",
  "version": "1.0.0",
  "author": "Conceptual Vision Consulting LLC",
  "description": "Sample Facade Microservice in Node",
  "contributors": [
    "Sergey Seroukhov <seroukhov@entinco.com>"
  ],
  "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/main.js"
  },
  "dependencies": {
    "pip-services3-commons-nodex": "^1.0.1",
    "pip-services3-container-nodex": "^1.0.2",
    "pip-services3-rpc-nodex": "^1.1.1"
  },
  "devDependencies": {
    "@types/chai": "^4.0.0",
    "@types/mocha": "^8.0.0",
    "@types/node": "^10.17.26",
    "chai": "^4.3.4",
    "mocha": "^8.3.2"
  }
}


Create a **Service.csproj**, **Client.csproj** and **Process.csproj** files at the **/src/service**, **/src/client** and **/src/process** folders with the following content to configure dependencies and project parameters:

/src/service/service.csproj

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
        <AssemblyName>Pip.Services.SampleFacade.Service</AssemblyName>
        <RootNamespace>Pip.Services.SampleFacade</RootNamespace>
        <Version>1.0.0</Version>
    </PropertyGroup>

    <ItemGroup>
        <Compile Remove="Data.cs" />
    </ItemGroup>
    <ItemGroup>
      <PackageReference Include="PipServices3.Commons" Version="3.3.0" />
      <PackageReference Include="PipServices3.Container" Version="3.2.0" />
      <PackageReference Include="PipServices3.Rpc" Version="3.5.2" />
    </ItemGroup>
    <ItemGroup>
      <ProjectReference Include="..\Client\Client.csproj" />
    </ItemGroup>
</Project>

/src/client/client.csproj

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
      <TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
        <AssemblyName>Pip.Services.SampleFacade.Client</AssemblyName>
        <RootNamespace>Pip.Services.SampleFacade</RootNamespace>
        <Version>1.0.0</Version>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="PipServices3.Commons" Version="3.3.0" />
    </ItemGroup>

</Project>

/src/process/process.csproj

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
      <TargetFramework>net5.0</TargetFramework>
        <OutputType>Exe</OutputType>
        <AssemblyName>run</AssemblyName>
    </PropertyGroup>

    <ItemGroup>
      <ProjectReference Include="..\Service\Service.csproj" />
    </ItemGroup>

</Project>


Create a /go.mod file at the root of the project with the following content to configure dependencies and project parameters:

/go.mod

module github.com/pip-services-samples/pip-samples-facade-go

go 1.14

require (
	github.com/gorilla/mux v1.8.0
	github.com/pip-services-samples/client-beacons-gox v0.0.0-20211014053826-3c0dad449019
	github.com/pip-services-samples/service-beacons-gox v0.0.0-20211012180859-9b862cf4be13
	github.com/pip-services-users/pip-clients-accounts-go v0.0.0-20211012190608-0275957ed72a
	github.com/pip-services-users/pip-clients-passwords-go v0.0.0-20211012192517-7356fde7658f
	github.com/pip-services-users/pip-clients-roles-go v0.0.0-20211012191010-cc2b4284b1ad
	github.com/pip-services-users/pip-clients-sessions-go v0.0.0-20211012191122-ad67c479e2d2
	github.com/pip-services3-gox/pip-services3-commons-gox v1.1.2
	github.com/pip-services3-gox/pip-services3-components-gox v1.2.0
	github.com/pip-services3-gox/pip-services3-container-gox v1.1.5
	github.com/pip-services3-gox/pip-services3-mongodb-gox v1.1.0
	github.com/pip-services3-gox/pip-services3-rpc-gox v1.5.0-64
	github.com/stretchr/testify v1.7.0
)

Not available

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

/requirements.txt

pytest

pip-services3-commons
pip-services3-components
pip-services3-container
pip-services3-rpc
Not available

Install all necessary modules using the command:

npm install

Create a TypeScript compiler configuration file with the following lines:

/tsconfig.json

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

dotnet restore
go mod download
Not available
pip install -r requirements.txt
Not available

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

Step 3. Designing a Direct Client