diff --git a/src/sa/model/index.md b/src/sa/model/index.md index f9e04ea..62d4000 100644 --- a/src/sa/model/index.md +++ b/src/sa/model/index.md @@ -1943,4 +1943,261 @@ Good: 1, two out of 2-5. Exceed: 1-5. -} \ No newline at end of file +} + +1. As a user case scenario, I choose to require supporting the Amazon Alexa voice assistant to allow its users to alter smart device states by voice command. To achieve this functionality, I define new logical, process and deployment view to show how the Alexa API is integrated in the architecture. + +## Logical View + +```puml +@startuml +skinparam componentStyle rectangle + +!include + +title Smarthut.sm Logical View + +interface " " as DIF +interface " " as TF +interface " " as SCF + +component "IoT Devices" as IOT { + interface " " as HDF + interface " " as HSF + interface " " as ZDF + interface " " as ZSF + + [HomeKit smart device] as HD <> + [HomeKit smart sensor] as HS <> + [MQTT smart device] as ZD <> + [MQTT smart sensor] as ZS <> + + HD--HDF + HS--HSF + ZD--ZDF + ZS--ZSF +} + +component "Alexa" as ALEXA { + interface " " as ALF + + [Alexa Skill Definition] as AS <> + [Alexa Smart Home Skill API] as AL <> + + AS-(ALF + ALF-AL +} + +component "User Interface" as UIC { + interface " " as WSCF + + [User Interface] as UI + [WebSockets API (JavaScript)] <> as WSC + + WSCF)--UI + WSC--WSCF +} + +component "Users and Devices" as DEV { + interface " " as DIDBF + interface " " as HAPF + interface " " as ZIGF + interface " " as WSSF + + [HAP-java] as HAP <> + [paho.mqtt.java] as ZIG <> + [Device Engine] as DI + + note left of DI: Already implemented using Spring Boot + + [javax.websocket API] as WSS <> + [User and Device DB <$database{scale=0.33}> (PostgreSQL)] <> as DIDB + + HDF )-- HAP + HSF )-- HAP + ZDF )-- ZIG + ZSF )-- ZIG + + DI--(WSSF + WSSF--WSS + HAP--HAPF + ZIG--ZIGF + HAPF )-- DI + ZIGF )-- DI + DIDBF-DIDB + DI -( DIDBF +} + +AL--(DIF + +component "Triggers and Automations" as TRIG { + interface " " as TDBF + + [Trigger and Automation Engine] as T + [Trigger and Automation DB <$database{scale=0.33}> (PostgreSQL)] <> as TDB + + TDBF-TDB + T -( TDBF +} + +component "Scenes" as SCENE { + interface " " as SCDBF + + [Scene Engine] as SC + [Scene DB <$database{scale=0.33}> (PostgreSQL)] <> as SCDB + + SCDBF-SCDB + SC -( SCDBF +} + +DI--DIF +TF--T +SCF--SC +WSS <..> WSC: WebSocket protocol (RFC 6455) +DI --( TF +T --( SCF +DIF )-- SC +DIF )-- UI +UI --( SCF +UI --( TF + +skinparam monochrome true +skinparam shadowing false +skinparam defaultFontName Courier +@enduml +``` + +## Process View + +Use case: a user alters manually the state of device 'D' via Alexa voice command, +and the device updates accordingly. Device 'D' is not part of any defined trigger. + +```puml +@startuml +title Process View: UI updates state of device + +box "IoT Devices" + participant "MQTT device 'D'" as ZD +end box + +box "User Interface" + participant "UI" as UI + participant "WebSockets API (JS)" as WSC +end box + +box "Alexa" + participant "Alexa Skill Definition" as AS + participant "Alexa Smart Home Skill API" as AL +end box + +box "Users and Devices" + participant "javax.websocket" as WSS + participant "HAP-java" as HAP + participant "paho.mqtt.java" as ZIG + participant "Engine" as DI + participant "DB" as DIDB +end box + +box "Triggers and Automations" + participant "Engine" as T + participant "DB" as TDB +end box + +box "Scenes" + participant "Engine" as SC + participant "DB" as SCDB +end box + +AS -> AL: interprets "Turn on device D" command +AL -> DI: HTTP 1.1 PUT /devices/{id}/state\n(update state) +DI -> ZIG: client.publish(\n TOPIC,\n new MqttMessage(...)\n);\n(request state update) +ZIG -> ZD: MQTT PUBLISH\n(state update request) +ZD -> ZIG: MQTT PUBLISH\n(new state) +ZIG -> DI: subscriber.subscribe(...) observer called \n(successful application) +DI -> DIDB: JDBC transaction (UPDATE)\n(store new state) +DI -> WSS: s.getBasicRemote().sendText(...)\n(send new device state) +WSS <--> WSC: WebSocket protocol +WSC -> UI: connection.onmessage called\n(new device state received, updates UI) +DI -> T: report latest device state + +skinparam monochrome true +skinparam shadowing false +skinparam defaultFontName Courier +@enduml +``` + +### Deployment View + +```puml +@startuml +title SmartHut Deployment View + +node "Users and Devices" { + [Engine] as UW +} + +node "Triggers and Automations" { + [Engine] as TW +} + +node "Scenes" { + [Engine] as SW +} + +database "Users and Devices Database" { + [DB] as UDB + UW - UDB: JDBC +} + +database "Triggers and Automations Database" { + [DB] as TDB + TW -- TDB: JDBC +} + +database "Scenes Database" { + [DB] as SDB + SW - SDB: JDBC +} + +UW -- TW: HTTPS +TW -- SW: HTTPS +UW -- SW: HTTPS + +node "Device" { + [Web Based User Interface] as UI +} + +cloud "User owned smart devices" { + [Homekit Smart Device] as HD + [Homekit Smart Sensor] as HS + [MQTT Smart Device] as MD + [MQTT Smart Sensor] as MS +} + +cloud "User Interface CDN" { + [User Interface Web Server] as CDN +} + +cloud "Alexa" { + [Alexa Skill Definition] as AS + [Alexa Smart Home Skill API] as AL +} + +UW -- HD: Homekit protocol +UW -- HS: Homekit protocol +UW -- MD: MQTT +UW -- MS: MQTT + +UI -- CDN: HTTPS +UI -- UW: HTTPS +UI -- TW: HTTPS +UI -- SW: HTTPS + +AS -- AL: RPC (JavaScript) +AL -- UW: HTTPS + +skinparam monochrome true +skinparam shadowing false +skinparam defaultFontName Courier +@enduml +```