# alous12/practica_3_iot architecture

> Architecture diagram of the GitHub repository alous12/practica_3_iot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alous12/practica_3_iot
- Repository: https://github.com/alous12/practica_3_iot

## Overview

Vigilante Inteligente is an Alexa-controlled ESP32 security device: users link a device by its displayed code, then query or change its door and operating settings. Alexa requests enter the Lambda skill, which resolves the user’s Thing, accesses DynamoDB for links, and reads or updates its AWS IoT Device Shadow. The ESP32 reports PIR and door state and applies Shadow deltas; its local rule and settings logic also support autonomous behavior. The graph follows documented and indexed runtime structure; unsampled modules are included only where README or index evidence supports them.

Main entry points: [`src/main.cpp`](https://github.com/alous12/practica_3_iot/blob/main/src/main.cpp) (ESP32 runtime), [`src/app/SmartObject.cpp`](https://github.com/alous12/practica_3_iot/blob/main/src/app/SmartObject.cpp) (State orchestrator), [`lambda/vigilante/handlers.py`](https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/handlers.py) (Intent handlers), [`lambda/vigilante/device_gateway.py`](https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/device_gateway.py) (Device gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_alexa_cloud["Alexa and cloud"]
  node_interaction_model["Intent model"]
  node_lambda_entry["Lambda entry<br/>[lambda_function.py]"]
  node_skill["Skill setup<br/>[skill.py]"]
  node_handlers["Intent handlers<br/>[handlers.py]"]
  node_speech["Speech responses<br/>[speech.py]"]
  node_link_repo["Link repository<br/>[link_repository.py]"]
  node_device_gateway["Device gateway<br/>[device_gateway.py]"]
  node_device_state["Shadow state<br/>[device_state.py]"]
end

subgraph group_firmware_network["Firmware connectivity"]
  node_firmware_main["ESP32 runtime<br/>[main.cpp]"]
  node_wifi["WiFi connection<br/>[WifiConnection.cpp]"]
  node_time_sync["NTP time sync<br/>[TimeSync.cpp]"]
  node_shadow_client["MQTT Shadow client<br/>[ShadowClient.cpp]"]
end

subgraph group_device_behavior["Device behavior"]
  node_smart_object["State orchestrator<br/>[SmartObject.cpp]"]
  node_pir["PIR sensor<br/>[PirSensor.cpp]"]
  node_door_lock["Servo lock<br/>[DoorLock.cpp]"]
  node_auto_rule["Auto-lock rule<br/>[AutoLockRule.cpp]"]
  node_settings["Operating settings"]
end

subgraph group_aws_services["AWS services"]
  node_dynamodb[("DynamoDB links")]
  node_iot_shadow[("IoT Device Shadow")]
end

node_user(("Alexa user"))

node_user -->|"speaks intents"| node_interaction_model
node_interaction_model -->|"routes requests"| node_lambda_entry
node_lambda_entry -->|"invokes skill"| node_skill
node_skill -->|"registers handlers"| node_handlers
node_handlers -->|"resolves links"| node_link_repo
node_handlers -->|"requests device state"| node_device_gateway
node_handlers -->|"formats responses"| node_speech
node_link_repo -->|"reads and writes"| node_dynamodb
node_device_gateway -->|"reads and updates"| node_iot_shadow
node_device_gateway -->|"parses shadow"| node_device_state
node_firmware_main -->|"maintains connection"| node_wifi
node_firmware_main -->|"starts time sync"| node_time_sync
node_firmware_main -->|"maintains shadow session"| node_shadow_client
node_firmware_main -->|"runs loop"| node_smart_object
node_firmware_main -->|"constructs and registers"| node_pir
node_firmware_main -->|"constructs and registers"| node_door_lock
node_firmware_main -->|"registers rule"| node_auto_rule
node_firmware_main -->|"registers settings"| node_settings
node_smart_object -->|"publishes and receives deltas"| node_shadow_client
node_smart_object -->|"reads and reports"| node_pir
node_smart_object -->|"applies and reports"| node_door_lock
node_smart_object -->|"applies and reports"| node_settings
node_smart_object -->|"evaluates rules"| node_auto_rule
node_auto_rule -->|"checks motion"| node_pir
node_auto_rule -->|"closes door"| node_door_lock
node_shadow_client -->|"exchanges Shadow state"| node_iot_shadow
node_iot_shadow -->|"serves state and deltas"| node_device_gateway

click node_interaction_model "https://github.com/alous12/practica_3_iot/blob/main/alexa/interaction-model.es-US.json"
click node_lambda_entry "https://github.com/alous12/practica_3_iot/blob/main/lambda/lambda_function.py"
click node_skill "https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/skill.py"
click node_handlers "https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/handlers.py"
click node_speech "https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/speech.py"
click node_link_repo "https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/link_repository.py"
click node_device_gateway "https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/device_gateway.py"
click node_device_state "https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/device_state.py"
click node_firmware_main "https://github.com/alous12/practica_3_iot/blob/main/src/main.cpp"
click node_wifi "https://github.com/alous12/practica_3_iot/blob/main/src/net/WifiConnection.cpp"
click node_time_sync "https://github.com/alous12/practica_3_iot/blob/main/src/net/TimeSync.cpp"
click node_shadow_client "https://github.com/alous12/practica_3_iot/blob/main/src/net/ShadowClient.cpp"
click node_smart_object "https://github.com/alous12/practica_3_iot/blob/main/src/app/SmartObject.cpp"
click node_pir "https://github.com/alous12/practica_3_iot/blob/main/src/sensors/PirSensor.cpp"
click node_door_lock "https://github.com/alous12/practica_3_iot/blob/main/src/actuators/DoorLock.cpp"
click node_auto_rule "https://github.com/alous12/practica_3_iot/blob/main/src/rules/AutoLockRule.cpp"
click node_settings "https://github.com/alous12/practica_3_iot/tree/main/src/settings"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_interaction_model,node_lambda_entry,node_skill,node_handlers,node_speech,node_link_repo,node_device_gateway,node_device_state,node_user toneBlue
class node_firmware_main,node_wifi,node_time_sync,node_shadow_client toneAmber
class node_smart_object,node_pir,node_door_lock,node_auto_rule,node_settings toneMint
class node_dynamodb,node_iot_shadow toneRose
```

## Components

### Alexa and cloud

- [Intent model](https://github.com/alous12/practica_3_iot/blob/main/alexa/interaction-model.es-US.json): `alexa/interaction-model.es-US.json`
- [Lambda entry](https://github.com/alous12/practica_3_iot/blob/main/lambda/lambda_function.py): `lambda/lambda_function.py`
- [Skill setup](https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/skill.py): `lambda/vigilante/skill.py`
- [Intent handlers](https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/handlers.py): `lambda/vigilante/handlers.py`
- [Speech responses](https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/speech.py): `lambda/vigilante/speech.py`
- [Link repository](https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/link_repository.py): `lambda/vigilante/link_repository.py`
- [Device gateway](https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/device_gateway.py): `lambda/vigilante/device_gateway.py`
- [Shadow state](https://github.com/alous12/practica_3_iot/blob/main/lambda/vigilante/device_state.py): `lambda/vigilante/device_state.py`

### Firmware connectivity

- [ESP32 runtime](https://github.com/alous12/practica_3_iot/blob/main/src/main.cpp): `src/main.cpp`
- [WiFi connection](https://github.com/alous12/practica_3_iot/blob/main/src/net/WifiConnection.cpp): `src/net/WifiConnection.cpp`
- [NTP time sync](https://github.com/alous12/practica_3_iot/blob/main/src/net/TimeSync.cpp): `src/net/TimeSync.cpp`
- [MQTT Shadow client](https://github.com/alous12/practica_3_iot/blob/main/src/net/ShadowClient.cpp): `src/net/ShadowClient.cpp`

### Device behavior

- [State orchestrator](https://github.com/alous12/practica_3_iot/blob/main/src/app/SmartObject.cpp): `src/app/SmartObject.cpp`
- [PIR sensor](https://github.com/alous12/practica_3_iot/blob/main/src/sensors/PirSensor.cpp): `src/sensors/PirSensor.cpp`
- [Servo lock](https://github.com/alous12/practica_3_iot/blob/main/src/actuators/DoorLock.cpp): `src/actuators/DoorLock.cpp`
- [Auto-lock rule](https://github.com/alous12/practica_3_iot/blob/main/src/rules/AutoLockRule.cpp): `src/rules/AutoLockRule.cpp`
- [Operating settings](https://github.com/alous12/practica_3_iot/tree/main/src/settings): `src/settings`

### AWS services

- **DynamoDB links**
- **IoT Device Shadow**

### Other components

- **Alexa user**

## Connections

- Alexa user → Intent model: speaks intents (evidence: `README.md`)
- Intent model → Lambda entry: routes requests (evidence: `README.md`)
- Lambda entry → Skill setup: invokes skill (evidence: `lambda/lambda_function.py`)
- Skill setup → Intent handlers: registers handlers (evidence: `lambda/vigilante/skill.py`)
- Intent handlers → Link repository: resolves links (evidence: `lambda/vigilante/handlers.py`)
- Intent handlers → Device gateway: requests device state (evidence: `lambda/vigilante/handlers.py`)
- Intent handlers → Speech responses: formats responses (evidence: `lambda/vigilante/handlers.py`)
- Link repository → DynamoDB links: reads and writes (evidence: `lambda/vigilante/link_repository.py`)
- Device gateway → IoT Device Shadow: reads and updates (evidence: `lambda/vigilante/device_gateway.py`)
- Device gateway → Shadow state: parses shadow (evidence: `lambda/vigilante/device_gateway.py`)
- ESP32 runtime → WiFi connection: maintains connection (evidence: `src/main.cpp`)
- ESP32 runtime → NTP time sync: starts time sync (evidence: `src/main.cpp`)
- ESP32 runtime → MQTT Shadow client: maintains shadow session (evidence: `src/main.cpp`)
- ESP32 runtime → State orchestrator: runs loop (evidence: `src/main.cpp`)
- ESP32 runtime → PIR sensor: constructs and registers (evidence: `src/main.cpp`)
- ESP32 runtime → Servo lock: constructs and registers (evidence: `src/main.cpp`)
- ESP32 runtime → Auto-lock rule: registers rule (evidence: `src/main.cpp`)
- ESP32 runtime → Operating settings: registers settings (evidence: `src/main.cpp`)
- State orchestrator → MQTT Shadow client: publishes and receives deltas
- State orchestrator → PIR sensor: reads and reports
- State orchestrator → Servo lock: applies and reports
- State orchestrator → Operating settings: applies and reports
- State orchestrator → Auto-lock rule: evaluates rules
- Auto-lock rule → PIR sensor: checks motion
- Auto-lock rule → Servo lock: closes door
- MQTT Shadow client → IoT Device Shadow: exchanges Shadow state (evidence: `README.md`)
- IoT Device Shadow → Device gateway: serves state and deltas (evidence: `lambda/vigilante/device_gateway.py`)
