# ti-framework design

## Motivation

TI-Framework SDK is designed to help anyone that wants to implement a client/customer app for Touchless Interactive solutions, without worrying about complexities of design, and implementation for data models, interfaces etc&#x20;

## Introduction

ti-framework provides APIs that you can use in your application/services to do every operation from creating Flows to running an active communication with TI-server.

### Environment&#x20;

The current implementation has full support for developing your apps(client/customer) in angular. SDK incorporates useful technologies like containers, web sockets, and good design patterns.

## API

Most of the APIs available are listed [here](https://github.com/developerTouchlessInteractive/ti-framework/blob/main/src/ti.ts). For a full reference, please refer to descriptions for each API method.

## Design

![API , key Interfaces and Classes ](https://3983830250-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MPGSdK2hhYm6fgva8dd%2F-MTF7JrtKdkESGzQDVVG%2F-MTIux1K3IEIfuDRD3LU%2FBlank%20diagram%20-%20Page%201.svg?alt=media\&token=09f62c70-c243-4164-bc1d-4fc6bf80ccf2)

### Interfaces

#### CommunicationHandler

This interface controls the mode of exchanging information between SDK and Server independent of the underlying technologies like WebSockets, MQTT, RabbitMQ etc. For the sake of this demo, we implemented a SocketHandler that brings up a WebSocket each for Active Flow/Session and Interaction.&#x20;

#### Listener

`EventListener` interface declares how SDK will process updates from TI-Server. As SDK is used by both client and customer apps, we have `ClientServerEventListener` and `CustomerServerEventListener` implementing this interface&#x20;

#### TaskPathCalculator

After we get updates on whether a Task is completed etc form TI-Server, Customer app needs to determine how to navigate to the next in order Task in the Flow. `TaskPathCalculator` addresses the need hereby declaring utility methods like calculateNextTask.  `RouteHandler` class implements this interface in our SDK.

### CommunicationFactory

As part of `FlowManager` creation for client and customer, `CommunicationFactory` is used to create `CommunicationHandler` with a chosen mode of `Transport`.

### Events

All the data exchanged between either Customer and Server  or Client and Server will have a message Event attached to it. Based on this event, any payload is processed at their respective ends.

`Server Events` are used to acknowledge connections, or any task update requests and to inform client and customer about completion of Task/Stage/Flow.

`Client Events` are used to request initiation of Flow, update Server when Flow is established, and more.

`Customer Events` are used to request connection to Flow, send upadtes when Task has started, or when requesting Server that Task is ready to be completed.

### Flow initiation and closure process

Before SDK can be ready for Flow Orchestration, it needs to configure below.

#### Flow Manager

`FlowManager` is created for Client when Flow is being initiated, and the same is created for Customer when 4 digit invite code is sent to register for that Flow. FlowManager is equipped with a container with all the Session info, a `FlowListener`, `EventListener`, `CommunicationHandler` is created, which is used for all Flow Orchestration related operations. In addition, FlowManager provides useful utility methods to `sendTAskPayloadToServer` and update listeners sent from client/customer app that `flowIsComplete`.

#### Interact Manager

Once a Flow is active, `InteractManager` is created with `InteractionCommunicationHandler` and `InteractionListener`.  This is responsible for sending/receiving interaction data.

### Error handling

TiSdkError and several other error classes extending it are defined to raise exceptions or make better sense of every important step that might fail in Flow Orchestration. Please refer to [error definitions](https://github.com/developerTouchlessInteractive/ti-framework/blob/main/src/errors/ti.errors.ts) for more information.

###
