---
# System prepended metadata

title: VIVOCloud Recording System

---

# VIVOCloud Recording System

## Overview

### Parts list
1. Camera side
1. Server side
    * S3
    * EC2
        * Account Server
        * Playback Server
    * lambda
        * Recording server
    * Redis
    * DynamoDB
    * AWS IOT STS endpoint
1. Client side
    * APP
    * Web 

### Actions between parts
```mermaid
graph LR
  C[Camera]
  F[Web/APP]-->|login|A[Account]
  F -->|play| P[Playback]
  subgraph SERVER
  AS(AWS-STS)
  D[(DynamoDB)]
  R(Redis)
  P --> |get media|S((S3))
  S --> |event call|RS{{Recording}}
  A--> |query owner| D
  A -->|query session, put credential| R
  A --> |create credential|AS
  P --> |query intervals| D
  P --> |query session, query credential| R
  RS--> |insert interval| D
  RS-->|get media|S
  I(IOT-STS)
  end
  C -->|put media|S
  C -->|create credential|I
```

## Parts

1. S3
    * Store all recording media files
    * Store all archived media files
    * Support upload HTTPS request
2. DynamoDB
    * Store all interval information of medias
        * S3 filename
        * Begin time and end time in local time and UTC
        * Timezone and DST inforamtion
    * Store all information of archives
        * S3 filename
        * Begin time, end time and create time
        * Create from whitch camera
4. Redis
    * Cache Storage credentials for each user
5. AWS IOT STS endpoint
    * Support camera get a temporary credential by HTTPS request with cerificate
7. Camera
    * Get frame and compose 3gp type media files
    * Refresh Storage credential form IOT certificate
    * Put 3gp files to Storage by HTTPS request with credential
    * Varify AWS server with AWS root CA
8. Recording server
    * A AWS managed lambad
    * Support Storage new file event
    * Parse file to get interval information and insert to Database
9. Client
    * User login Account server
    * Send query API to Playback server, then show timeline and video
    * Send archives API to keep media avoid be recycled
10. Account server
    * Create a user session for client when login
    * Create a credential of Storage in cache when user login
11. Playback server
    * Check API with user session
    * Get crendtial of Storage form Cache
    * Support HTTPS requests:
        * Query recorded days in a month
        * Query recording intervals in a day
        * Play recording files in a time
        * Create archive with a interval
        * Query all archives
        * Play/Download/Delete archive with a archive ID

## Flow of Actions

### Camera Recording
```mermaid
sequenceDiagram
	Camera->>+IOT STS: HTTPS request + cetificate
	IOT STS->>-Camera: temporary credential
    Camera->>+S3:upload 3gp file + credential
    S3->>-Camera:ok
    S3->>+Recording:trigger event with obj key
    Recording->>+S3:HTTPS request
    S3->>-Recording:download 3gp
    Note over Recording:parse 3gp
    Recording->>+DynamoDB:insert new file interval
    DynamoDB->>-Recording:ok
    Recording->>-S3:ok
```

### Client login
```mermaid
sequenceDiagram
	Client->>+Account: HTTPS request + username + password
    Account->>Account: create session
    Account->>+AWS STS: create temporary credential
    AWS STS->>-Account: downlaod credential
    Account->>+Redis: Add session and credential
    Redis->>-Account: ok
    Account->>-Client: user session
```

### Client Playback - get intervals and calendar
```mermaid
sequenceDiagram
	Client->>+Playback: HTTPS request + user session
    Playback->>+Redis: verify user session
    Redis->>-Playback: ok
	Playback->>+DynamoDB: query camera owner
    DynamoDB->>-Playback: owner ID
    Playback->>+DynamoDB: query interval of files
    DynamoDB->>-Playback: interval list in JSON
    Playback->>-Client: JSON response
```

### Client Playback - play media
```mermaid
sequenceDiagram
	Client->>+Playback: HTTPS request + user session
    Playback->>+Redis: verify user session
    Redis->>-Playback: ok
    Playback->>+Redis: get credential
    Redis->>-Playback:downlaod credential
	Playback->>+DynamoDB: query camera owner
    DynamoDB->>-Playback: owner ID
    Playback->>+DynamoDB: find the file
    DynamoDB->>-Playback: return a s3 obj key
    Playback->>+S3: GetObj HTTPS request with credential
    S3->>-Playback: dowwnload 3gp
    Playback->>-Client: downlaod 3gp
    Note over Client: render the 3gp
```

### Client Archive - Create
```mermaid
sequenceDiagram
	Client->>+Playback: HTTPS request + user session
    Playback->>+Redis: verify user session
    Redis->>-Playback: ok
    Playback->>+Redis: get credential
    Redis->>-Playback:downlaod credential
	Playback->>+DynamoDB: query camera owner
    DynamoDB->>-Playback: owner ID
    Playback->>+DynamoDB: query files in the range
    DynamoDB->>-Playback: file list in JSON
    loop all files
        Playback->>+S3: GetObj HTTPS request with credential
        S3->>-Playback: dowwnload all 3gp files
    end
    Note over Playback: Merge files
    Playback->>+S3: Upload archived 3gp
    S3->>-Playback: ok
    Playback->>+DynamoDB: insert archive information
    DynamoDB->>-Playback: ok
    Playback->>-Client: JSON response
```

### Client Archive - Query, Deelte
```mermaid
sequenceDiagram
	Client->>+Playback: HTTPS request + user session
    Playback->>+Redis: verify user session
    Redis->>-Playback: ok
    Playback->>+Redis: get credential
    Redis->>-Playback:downlaod credential
	Playback->>+DynamoDB: query camera owner
    DynamoDB->>-Playback: owner ID
    Playback->>+DynamoDB: query command
    DynamoDB->>-Playback: result in JSON
    Playback->>-Client: JSON response
```

### Client Archive - Download, Play
```mermaid
sequenceDiagram
	Client->>+Playback: HTTPS request + user session
    Playback->>+Redis: verify user session
    Redis->>-Playback: ok
    Playback->>+Redis: get credential
    Redis->>-Playback:downlaod credential
	Playback->>+DynamoDB: query camera owner
    DynamoDB->>-Playback: owner ID
    Playback->>+DynamoDB: query archive s3 obj key
    DynamoDB->>-Playback: return a s3 obj key
    Playback->>+S3: create pre-signed URL
    S3->>-Playback:string in JSON
    Playback->>-Client: JSON response
```
