athena-test/docs/Dipal/Backend/Kaiser/Database explanation.md

4.9 KiB

Database explanation

You can see the full database diagram here.

Profiles

The main subject in our system is the user. The user account is stored in Keycloak. There are 3 types of user profiles: user profile, company profile and operator profile. The difference between an account and a profile is that an account consists only of technical information about the user, especially secrets, while a profile consists of personal information about the user and information about his contracts.

A user profile is the profile of a simple user of the Dipal smartphone application. He only has access to Iguana and Pyrador. The user can have multiple places (his flats) and if he is the owner of the flat, he can give access to other users with a QR code or by invitation.

A company profile is an third-party provider company profile. It is assumed that third-party companies may contract with Dipal to use our app. They may have their own services and their own customer base (this base may be hidden from us). They may change the logo, color and some elements of the user interface of our application for their services.

An operator is someone who is responsible for the object. It can be a security guy or concierge, so he has minimal technical education requirements. He is responsible for fault tolerance of his fox (or foxes). The operator has access to all operations on the fox.

Every profile has their own contacts (phone number or email). We store in the database all information about the contact verification: last verification code, sent, verified, expired, next try.

Place

The place collection stores all places available in our system. The place storage is represented as a tree: all places, except the root one, have a parent. For example, root has a parent apartment, which in turn has a parent bulding.

User place

A user place is represented as a separate collection. One user can be in multiple user places. Every user place document has members subcollection with following fields:

  • title (user's custom place title)
  • status (user place confirmation status for this user)
  • privileges (different priveleges to add new members, services, etc.)
  • services (subcollection with permited services and devices)
  • qr code id (if access was given by qr code)

There is only one user place owner. He can send a QR code or an invitation by phone number to the user he wants to add to his place. When the user scans the QR code or accepts the invitation, the owner can select the privileges and services he wants to share.

Service

A service is a basic functionality of Dipal service. It can be any service provided by the company: intercom, camera, internet, utilities, etc. First you need to create a base service and describe in it all the necessary information and settings that apply to this group of services. We can create several services of the same group (based on one base service). This makes the implementation of the service fully dynamic. The service document also stores common information about some services: banners, videos, etc. Each company can have its own services.

Service info and configuration are stored as key-value pairs. For example:

{
 "settings": [
   {
     "key": "protocol",
     "value": "rtsp"
   },
   {
     "key": "username",
     "value": "comfortech"
   },
   {
     "key": "password",
     "value": "mypass"
   },
   {
     "key": "ip",
     "value": "10.1.0.6"
   },
   {
     "key": "port",
     "value": "8554"
   },
   {
     "key": "rouths",
     "value": "camera4"
   }
 ],
 "necessary_info": [
   {
     "key": "caption",
     "value": "entrance 1"
   },
   {
     "key": "model",
     "value": "model1"
   },
   {
     "key": "resolution",
     "value": "Full HD"
   }
 ]
}

Contract

The are two types of contracts in the Dipal system: between user and company and between companies. They both are stored inside one collection. The contract document contains:

  • provided services
  • provided info and docs
  • source company id
  • counter part (user or company profile id)
  • contract content
  • contract status
  • contract start and end

Plan

A plan gives you access to a particular service for a fee. One service can have multiple plans with different fees. For each plan, you can set up different time intervals, pricing, discounts, and support for automatic payments.

Fox

The fox collection contains all existing foxes. All foxes are bound to a specific place (usually a house or building). Information about IP and MAC addresses and connected akitas and devices is also stored there.

We used to use the MQTT broker to connect to foxes, but now we connect foxes to Kaiser using an HTTP server.