.github

Design

Mockups (scenarios)

(This frame cannot be rendered on GitHub so click the link to view it on Figma)

Additional details that are not shown in the mockups:

Domain modeling

In every upcoming diagram:

Users management

Users management domain model diagram

This bounded context exposes a UsersService which offers all the methods to implement the use cases.

UsersService service also includes methods for authentication (login, verifyToken, validateToken). The idea is that every other service will use this one to validate authentication tokens received by the client.

UsersService

UsersService is responsible for managing the system’s users. Essentially, its purpose is to centralize all logic related to authentication, authorization, and user lifecycle management.

Main Responsibilities

Security Rules

Devices management

Devices management domain model diagram

This bounded context exposes:

More complex stuff explanation:

TypeConstraints

Since devices will define their own action and properties they must also define what datatypes they are.

Types are defined in the Type enum which is generic on T which reprents the actual datatype that will be used internally.

A TypeConstraint is a constraint over a type which can also have additional constraints over the values, for example: An input which requires an integer from 0 to 100 can be modeled as a subclass of TypeConstraint with Type “IntType” which overrides the validate method implementing that logic (in the diagram we called this IntRange).

DevicePropertys which have a setter will use its TypeConstraint, otherwise they will have their own TypeConstraint.

A setter is a DeviceAction whose execution is expected to set a property with the given input. This allows to create richer user interfaces where properies and actions are bound.

DeviceActions have just one TypeConstraint which constraints the input they can take. Actions that require no input can be implemented by an input of Type “VoidType”.

Notifications

Notifications domain model diagram

This bounded context exposes a NotificationsService which offers all the methods to implement the use cases.

The service subscribes itself to the DeviceStatusesService to be informed when a device goes offline.

To achieve eventual consistency in case of the removal of a user from the system, the next time a device offline notification would be sent to that user the service will remove that subscription from the repository.

Regarding device removal from the system, it is not a bad idea to keep the subscription. Let’s say that the DeviceId is actually a hardware identifier, in case that device will be added again to the system, subscription would be valid again.

Permissions

Permissions domain model diagram

This bounded context exposes a PermissionsService which offers all the methods to implement the use cases.

A more detailed explanation of PermissionsService:

Scripts

Scripts domain model diagram

This bounded context exposes a ScriptsService which offers all the methods to implement the use cases.

A Script can be either a Task or an Automation the main difference is that automations have a Trigger.

Each script has a sequence of Instructions that has the following behaviour when executed based on the concrete implementation:

Conditions must operate on homogeneous types and for each type a fixed set of operators are given.

When a script is executed it creates internally an ExecutionEnvironment which is responsible for storing constant values. Tasks need a token to be executed manually by a user, while Automations do not (because they are executed automatically given a period of time or a device event firing). Tasks can also be executed without a token if executed through a Start Task Instruction inside a script.

Builders

Script builders domain model diagram

Builders can check whether a script syntax is correct, but they cannot do the same with regard to semantics (because they would need to access devices data in the repository).

Scripts semantic correctness is checked by the ScriptsService

Other doc

Distribuited doc