smart_message 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/deploy-github-pages.yml +38 -0
- data/.gitignore +5 -0
- data/CHANGELOG.md +30 -0
- data/Gemfile.lock +35 -4
- data/README.md +169 -71
- data/Rakefile +29 -4
- data/docs/assets/images/ddq_architecture.svg +130 -0
- data/docs/assets/images/dlq_architecture.svg +115 -0
- data/docs/assets/images/enhanced-dual-publishing.svg +136 -0
- data/docs/assets/images/enhanced-fluent-api.svg +149 -0
- data/docs/assets/images/enhanced-microservices-routing.svg +115 -0
- data/docs/assets/images/enhanced-pattern-matching.svg +107 -0
- data/docs/assets/images/fluent-api-demo.svg +59 -0
- data/docs/assets/images/performance-comparison.svg +161 -0
- data/docs/assets/images/redis-basic-architecture.svg +53 -0
- data/docs/assets/images/redis-enhanced-architecture.svg +88 -0
- data/docs/assets/images/redis-queue-architecture.svg +101 -0
- data/docs/assets/images/smart_message.jpg +0 -0
- data/docs/assets/images/smart_message_walking.jpg +0 -0
- data/docs/assets/images/smartmessage_architecture_overview.svg +173 -0
- data/docs/assets/images/transport-comparison-matrix.svg +171 -0
- data/docs/assets/javascripts/mathjax.js +17 -0
- data/docs/assets/stylesheets/extra.css +51 -0
- data/docs/{addressing.md → core-concepts/addressing.md} +5 -7
- data/docs/{architecture.md → core-concepts/architecture.md} +78 -138
- data/docs/{dispatcher.md → core-concepts/dispatcher.md} +21 -21
- data/docs/{message_filtering.md → core-concepts/message-filtering.md} +2 -3
- data/docs/{message_processing.md → core-concepts/message-processing.md} +17 -17
- data/docs/{troubleshooting.md → development/troubleshooting.md} +7 -7
- data/docs/{examples.md → getting-started/examples.md} +115 -89
- data/docs/{getting-started.md → getting-started/quick-start.md} +47 -18
- data/docs/guides/redis-queue-getting-started.md +697 -0
- data/docs/guides/redis-queue-patterns.md +889 -0
- data/docs/guides/redis-queue-production.md +1091 -0
- data/docs/index.md +64 -0
- data/docs/{dead_letter_queue.md → reference/dead-letter-queue.md} +2 -3
- data/docs/{logging.md → reference/logging.md} +1 -1
- data/docs/{message_deduplication.md → reference/message-deduplication.md} +1 -0
- data/docs/{proc_handlers_summary.md → reference/proc-handlers.md} +7 -6
- data/docs/{serializers.md → reference/serializers.md} +3 -5
- data/docs/{transports.md → reference/transports.md} +133 -11
- data/docs/transports/memory-transport.md +374 -0
- data/docs/transports/redis-enhanced-transport.md +524 -0
- data/docs/transports/redis-queue-transport.md +1304 -0
- data/docs/transports/redis-transport-comparison.md +496 -0
- data/docs/transports/redis-transport.md +509 -0
- data/examples/README.md +98 -5
- data/examples/city_scenario/911_emergency_call_flow.svg +99 -0
- data/examples/city_scenario/README.md +515 -0
- data/examples/city_scenario/ai_visitor_intelligence_flow.svg +108 -0
- data/examples/city_scenario/citizen.rb +195 -0
- data/examples/city_scenario/city_diagram.svg +125 -0
- data/examples/city_scenario/common/health_monitor.rb +80 -0
- data/examples/city_scenario/common/logger.rb +30 -0
- data/examples/city_scenario/emergency_dispatch_center.rb +270 -0
- data/examples/city_scenario/fire_department.rb +446 -0
- data/examples/city_scenario/fire_emergency_flow.svg +95 -0
- data/examples/city_scenario/health_department.rb +100 -0
- data/examples/city_scenario/health_monitoring_system.svg +130 -0
- data/examples/city_scenario/house.rb +244 -0
- data/examples/city_scenario/local_bank.rb +217 -0
- data/examples/city_scenario/messages/emergency_911_message.rb +81 -0
- data/examples/city_scenario/messages/emergency_resolved_message.rb +43 -0
- data/examples/city_scenario/messages/fire_dispatch_message.rb +43 -0
- data/examples/city_scenario/messages/fire_emergency_message.rb +45 -0
- data/examples/city_scenario/messages/health_check_message.rb +22 -0
- data/examples/city_scenario/messages/health_status_message.rb +35 -0
- data/examples/city_scenario/messages/police_dispatch_message.rb +46 -0
- data/examples/city_scenario/messages/silent_alarm_message.rb +38 -0
- data/examples/city_scenario/police_department.rb +316 -0
- data/examples/city_scenario/redis_monitor.rb +129 -0
- data/examples/city_scenario/redis_stats.rb +743 -0
- data/examples/city_scenario/room_for_improvement.md +240 -0
- data/examples/city_scenario/security_emergency_flow.svg +95 -0
- data/examples/city_scenario/service_internal_architecture.svg +154 -0
- data/examples/city_scenario/smart_message_ai_agent.rb +364 -0
- data/examples/city_scenario/start_demo.sh +236 -0
- data/examples/city_scenario/stop_demo.sh +106 -0
- data/examples/city_scenario/visitor.rb +631 -0
- data/examples/{10_message_deduplication.rb → memory/01_message_deduplication_demo.rb} +1 -1
- data/examples/{09_dead_letter_queue_demo.rb → memory/02_dead_letter_queue_demo.rb} +13 -40
- data/examples/{01_point_to_point_orders.rb → memory/03_point_to_point_orders.rb} +1 -1
- data/examples/{02_publish_subscribe_events.rb → memory/04_publish_subscribe_events.rb} +2 -2
- data/examples/{03_many_to_many_chat.rb → memory/05_many_to_many_chat.rb} +4 -4
- data/examples/{show_me.rb → memory/06_pretty_print_demo.rb} +1 -1
- data/examples/{05_proc_handlers.rb → memory/07_proc_handlers_demo.rb} +2 -2
- data/examples/{06_custom_logger_example.rb → memory/08_custom_logger_demo.rb} +17 -14
- data/examples/{07_error_handling_scenarios.rb → memory/09_error_handling_demo.rb} +4 -4
- data/examples/{08_entity_addressing_basic.rb → memory/10_entity_addressing_basic.rb} +8 -8
- data/examples/{08_entity_addressing_with_filtering.rb → memory/11_entity_addressing_with_filtering.rb} +6 -6
- data/examples/{09_regex_filtering_microservices.rb → memory/12_regex_filtering_microservices.rb} +2 -2
- data/examples/{10_header_block_configuration.rb → memory/13_header_block_configuration.rb} +6 -6
- data/examples/{11_global_configuration_example.rb → memory/14_global_configuration_demo.rb} +19 -8
- data/examples/{show_logger.rb → memory/15_logger_demo.rb} +1 -1
- data/examples/memory/README.md +163 -0
- data/examples/memory/memory_transport_architecture.svg +90 -0
- data/examples/memory/point_to_point_pattern.svg +94 -0
- data/examples/memory/publish_subscribe_pattern.svg +125 -0
- data/examples/{04_redis_smart_home_iot.rb → redis/01_smart_home_iot_demo.rb} +5 -5
- data/examples/redis/README.md +230 -0
- data/examples/redis/alert_system_flow.svg +127 -0
- data/examples/redis/dashboard_status_flow.svg +107 -0
- data/examples/redis/device_command_flow.svg +113 -0
- data/examples/redis/redis_transport_architecture.svg +115 -0
- data/examples/{smart_home_iot_dataflow.md → redis/smart_home_iot_dataflow.md} +4 -116
- data/examples/redis/smart_home_system_architecture.svg +133 -0
- data/examples/redis_enhanced/README.md +319 -0
- data/examples/redis_enhanced/enhanced_01_basic_patterns.rb +233 -0
- data/examples/redis_enhanced/enhanced_02_fluent_api.rb +331 -0
- data/examples/redis_enhanced/enhanced_03_dual_publishing.rb +281 -0
- data/examples/redis_enhanced/enhanced_04_advanced_routing.rb +419 -0
- data/examples/redis_queue/01_basic_messaging.rb +221 -0
- data/examples/redis_queue/01_comprehensive_examples.rb +508 -0
- data/examples/redis_queue/02_pattern_routing.rb +405 -0
- data/examples/redis_queue/03_fluent_api.rb +422 -0
- data/examples/redis_queue/04_load_balancing.rb +486 -0
- data/examples/redis_queue/05_microservices.rb +735 -0
- data/examples/redis_queue/06_emergency_alerts.rb +777 -0
- data/examples/redis_queue/07_queue_management.rb +587 -0
- data/examples/redis_queue/README.md +366 -0
- data/examples/redis_queue/enhanced_01_basic_patterns.rb +233 -0
- data/examples/redis_queue/enhanced_02_fluent_api.rb +331 -0
- data/examples/redis_queue/enhanced_03_dual_publishing.rb +281 -0
- data/examples/redis_queue/enhanced_04_advanced_routing.rb +419 -0
- data/examples/redis_queue/redis_queue_architecture.svg +148 -0
- data/ideas/README.md +41 -0
- data/ideas/agents.md +1001 -0
- data/ideas/database_transport.md +980 -0
- data/ideas/improvement.md +359 -0
- data/ideas/meshage.md +1788 -0
- data/ideas/message_discovery.md +178 -0
- data/ideas/message_schema.md +1381 -0
- data/lib/smart_message/.idea/.gitignore +8 -0
- data/lib/smart_message/.idea/markdown.xml +6 -0
- data/lib/smart_message/.idea/misc.xml +4 -0
- data/lib/smart_message/.idea/modules.xml +8 -0
- data/lib/smart_message/.idea/smart_message.iml +16 -0
- data/lib/smart_message/.idea/vcs.xml +6 -0
- data/lib/smart_message/addressing.rb +15 -0
- data/lib/smart_message/base.rb +0 -2
- data/lib/smart_message/configuration.rb +1 -1
- data/lib/smart_message/logger.rb +15 -4
- data/lib/smart_message/plugins.rb +5 -2
- data/lib/smart_message/serializer.rb +14 -0
- data/lib/smart_message/transport/redis_enhanced_transport.rb +399 -0
- data/lib/smart_message/transport/redis_queue_transport.rb +555 -0
- data/lib/smart_message/transport/registry.rb +1 -0
- data/lib/smart_message/transport.rb +34 -1
- data/lib/smart_message/version.rb +1 -1
- data/lib/smart_message.rb +5 -52
- data/mkdocs.yml +184 -0
- data/p2p_plan.md +326 -0
- data/p2p_roadmap.md +287 -0
- data/smart_message.gemspec +2 -0
- data/smart_message.svg +51 -0
- metadata +170 -44
- data/docs/README.md +0 -57
- data/examples/dead_letters.jsonl +0 -12
- data/examples/temp.txt +0 -94
- data/examples/tmux_chat/README.md +0 -283
- data/examples/tmux_chat/bot_agent.rb +0 -278
- data/examples/tmux_chat/human_agent.rb +0 -199
- data/examples/tmux_chat/room_monitor.rb +0 -160
- data/examples/tmux_chat/shared_chat_system.rb +0 -328
- data/examples/tmux_chat/start_chat_demo.sh +0 -190
- data/examples/tmux_chat/stop_chat_demo.sh +0 -22
- /data/docs/{properties.md → core-concepts/properties.md} +0 -0
- /data/docs/{ideas_to_think_about.md → development/ideas.md} +0 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<svg width="900" height="700" viewBox="0 0 900 700" xmlns="http://www.w3.org/2000/svg">
|
3
|
+
<defs>
|
4
|
+
<style>
|
5
|
+
.bg { fill: transparent; }
|
6
|
+
.process { fill: #2a2a2a; stroke: #4a9eff; stroke-width: 2; rx: 8; }
|
7
|
+
.redis { fill: #3a1a1a; stroke: #ff4a4a; stroke-width: 3; rx: 12; }
|
8
|
+
.channel { fill: #1a2a3a; stroke: #4affff; stroke-width: 2; rx: 6; }
|
9
|
+
.device { fill: #1a3a1a; stroke: #4aff4a; stroke-width: 2; rx: 6; }
|
10
|
+
.arrow { stroke: #ffaa4a; stroke-width: 2; fill: none; marker-end: url(#arrowhead); }
|
11
|
+
.text { fill: #ffffff; font-family: 'Arial', sans-serif; font-size: 12px; }
|
12
|
+
.title { fill: #4a9eff; font-family: 'Arial', sans-serif; font-size: 18px; font-weight: bold; }
|
13
|
+
.subtitle { fill: #ffaa4a; font-family: 'Arial', sans-serif; font-size: 11px; }
|
14
|
+
.redis-text { fill: #ff4a4a; font-family: 'Arial', sans-serif; font-size: 14px; font-weight: bold; }
|
15
|
+
.channel-text { fill: #4affff; font-family: 'Arial', sans-serif; font-size: 10px; }
|
16
|
+
</style>
|
17
|
+
<marker id="arrowhead" markerWidth="8" markerHeight="6"
|
18
|
+
refX="8" refY="3" orient="auto">
|
19
|
+
<polygon points="0 0, 8 3, 0 6" fill="#ffaa4a" />
|
20
|
+
</marker>
|
21
|
+
</defs>
|
22
|
+
|
23
|
+
<!-- Background -->
|
24
|
+
<rect class="bg" width="900" height="700"/>
|
25
|
+
|
26
|
+
<!-- Title -->
|
27
|
+
<text x="450" y="25" text-anchor="middle" class="title">SmartMessage Redis Transport Architecture</text>
|
28
|
+
<text x="450" y="45" text-anchor="middle" class="subtitle">Distributed Smart Home IoT System (01_smart_home_iot_demo.rb)</text>
|
29
|
+
|
30
|
+
<!-- Redis Server (Central Hub) -->
|
31
|
+
<rect x="350" y="300" width="200" height="120" class="redis"/>
|
32
|
+
<text x="450" y="325" text-anchor="middle" class="redis-text">Redis Server</text>
|
33
|
+
<text x="450" y="345" text-anchor="middle" class="text">localhost:6379</text>
|
34
|
+
<text x="450" y="365" text-anchor="middle" class="subtitle">Pub/Sub Channels:</text>
|
35
|
+
<text x="450" y="385" text-anchor="middle" class="channel-text">SensorDataMessage</text>
|
36
|
+
<text x="450" y="400" text-anchor="middle" class="channel-text">DeviceCommandMessage</text>
|
37
|
+
<text x="450" y="415" text-anchor="middle" class="channel-text">SecurityAlertMessage</text>
|
38
|
+
|
39
|
+
<!-- Process 1: Living Room Sensors -->
|
40
|
+
<rect x="50" y="80" width="160" height="120" class="process"/>
|
41
|
+
<text x="130" y="105" text-anchor="middle" class="title">Process 1</text>
|
42
|
+
<text x="130" y="125" text-anchor="middle" class="text">Living Room</text>
|
43
|
+
|
44
|
+
<rect x="70" y="140" width="120" height="50" class="device"/>
|
45
|
+
<text x="130" y="160" text-anchor="middle" class="text">Temperature Sensor</text>
|
46
|
+
<text x="130" y="175" text-anchor="middle" class="subtitle">Publishes every 5s</text>
|
47
|
+
|
48
|
+
<!-- Process 2: Security System -->
|
49
|
+
<rect x="50" y="480" width="160" height="120" class="process"/>
|
50
|
+
<text x="130" y="505" text-anchor="middle" class="title">Process 2</text>
|
51
|
+
<text x="130" y="525" text-anchor="middle" class="text">Security System</text>
|
52
|
+
|
53
|
+
<rect x="70" y="540" width="120" height="50" class="device"/>
|
54
|
+
<text x="130" y="560" text-anchor="middle" class="text">Motion Detector</text>
|
55
|
+
<text x="130" y="575" text-anchor="middle" class="subtitle">Publishes alerts</text>
|
56
|
+
|
57
|
+
<!-- Process 3: Smart Thermostat -->
|
58
|
+
<rect x="690" y="80" width="160" height="120" class="process"/>
|
59
|
+
<text x="770" y="105" text-anchor="middle" class="title">Process 3</text>
|
60
|
+
<text x="770" y="125" text-anchor="middle" class="text">Smart Thermostat</text>
|
61
|
+
|
62
|
+
<rect x="710" y="140" width="120" height="50" class="device"/>
|
63
|
+
<text x="770" y="160" text-anchor="middle" class="text">HVAC Controller</text>
|
64
|
+
<text x="770" y="175" text-anchor="middle" class="subtitle">Subscribes & Controls</text>
|
65
|
+
|
66
|
+
<!-- Process 4: Dashboard -->
|
67
|
+
<rect x="690" y="480" width="160" height="120" class="process"/>
|
68
|
+
<text x="770" y="505" text-anchor="middle" class="title">Process 4</text>
|
69
|
+
<text x="770" y="525" text-anchor="middle" class="text">Home Dashboard</text>
|
70
|
+
|
71
|
+
<rect x="710" y="540" width="120" height="50" class="device"/>
|
72
|
+
<text x="770" y="560" text-anchor="middle" class="text">Web Interface</text>
|
73
|
+
<text x="770" y="575" text-anchor="middle" class="subtitle">Displays all data</text>
|
74
|
+
|
75
|
+
<!-- Process 5: Energy Monitor -->
|
76
|
+
<rect x="370" y="80" width="160" height="120" class="process"/>
|
77
|
+
<text x="450" y="105" text-anchor="middle" class="title">Process 5</text>
|
78
|
+
<text x="450" y="125" text-anchor="middle" class="text">Energy Monitor</text>
|
79
|
+
|
80
|
+
<rect x="390" y="140" width="120" height="50" class="device"/>
|
81
|
+
<text x="450" y="160" text-anchor="middle" class="text">Power Meter</text>
|
82
|
+
<text x="450" y="175" text-anchor="middle" class="subtitle">Tracks usage</text>
|
83
|
+
|
84
|
+
<!-- Message Flow Arrows -->
|
85
|
+
<!-- Publishers to Redis -->
|
86
|
+
<path d="M 210 140 L 350 330" class="arrow"/>
|
87
|
+
<path d="M 210 540 L 350 380" class="arrow"/>
|
88
|
+
<path d="M 450 200 L 450 300" class="arrow"/>
|
89
|
+
|
90
|
+
<!-- Redis to Subscribers -->
|
91
|
+
<path d="M 550 330 L 690 140" class="arrow"/>
|
92
|
+
<path d="M 550 380 L 690 540" class="arrow"/>
|
93
|
+
|
94
|
+
<!-- Network Boundaries -->
|
95
|
+
<rect x="20" y="50" width="860" height="580" fill="none" stroke="#666" stroke-width="2" stroke-dasharray="10,5"/>
|
96
|
+
<text x="30" y="70" class="subtitle">Network: Multiple Ruby Processes • Same Machine or Distributed</text>
|
97
|
+
|
98
|
+
<!-- Channel Details -->
|
99
|
+
<rect x="100" y="230" width="700" height="50" class="channel"/>
|
100
|
+
<text x="450" y="250" text-anchor="middle" class="title">Redis Pub/Sub Channels</text>
|
101
|
+
<text x="150" y="270" class="channel-text">SensorDataMessage: Temperature, Humidity, Light</text>
|
102
|
+
<text x="450" y="270" class="channel-text">SecurityAlertMessage: Motion, Door, Window</text>
|
103
|
+
<text x="750" y="270" class="channel-text">DeviceCommandMessage: HVAC, Lights</text>
|
104
|
+
|
105
|
+
<!-- Key Features -->
|
106
|
+
<rect x="50" y="640" width="800" height="50" class="redis"/>
|
107
|
+
<text x="70" y="660" class="text">✓ Distributed: Processes can run on different machines</text>
|
108
|
+
<text x="70" y="675" class="text">✓ Real-time: Instant message delivery via Redis pub/sub</text>
|
109
|
+
|
110
|
+
<text x="450" y="660" class="text">✓ Scalable: Add/remove publishers and subscribers dynamically</text>
|
111
|
+
<text x="450" y="675" class="text">✓ Reliable: Redis handles connection pooling and fault tolerance</text>
|
112
|
+
|
113
|
+
<text x="650" y="660" class="text">✓ Channel-based: Each message type gets own channel</text>
|
114
|
+
<text x="650" y="675" class="text">✓ Automatic: Message routing handled by Redis</text>
|
115
|
+
</svg>
|
@@ -6,54 +6,7 @@ This document describes the data flow architecture for the Smart Home IoT exampl
|
|
6
6
|
|
7
7
|
The smart home system consists of three types of IoT devices and a central dashboard, all communicating through Redis pub/sub channels. Each message type uses its own Redis channel for efficient routing and scaling.
|
8
8
|
|
9
|
-
|
10
|
-
graph TB
|
11
|
-
%% IoT Devices
|
12
|
-
THERM["🌡️ Smart Thermostat<br/>THERM-001<br/>Living Room"]
|
13
|
-
CAM["📹 Security Camera<br/>CAM-001<br/>Front Door"]
|
14
|
-
LOCK["🚪 Smart Door Lock<br/>LOCK-001<br/>Main Entrance"]
|
15
|
-
DASH["📊 IoT Dashboard<br/>System Monitor"]
|
16
|
-
|
17
|
-
%% Redis Channels
|
18
|
-
subgraph REDIS ["Redis Pub/Sub Channels"]
|
19
|
-
SENSOR["SensorDataMessage<br/>Temperature, Motion, Status<br/>Battery Levels"]
|
20
|
-
COMMAND["DeviceCommandMessage<br/>set_temperature, start_recording<br/>lock/unlock, get_status"]
|
21
|
-
ALERT["AlertMessage<br/>Motion Detected, Battery Low<br/>High Temperature"]
|
22
|
-
STATUS["DashboardStatusMessage<br/>System Status, Device Counts<br/>Alert Summaries"]
|
23
|
-
end
|
24
|
-
|
25
|
-
%% Device Publishing
|
26
|
-
THERM -.->|"Temperature Data"| SENSOR
|
27
|
-
CAM -.->|"Motion Data"| SENSOR
|
28
|
-
LOCK -.->|"Lock Status"| SENSOR
|
29
|
-
CAM -.->|"Motion Alerts"| ALERT
|
30
|
-
THERM -.->|"High Temp Alerts"| ALERT
|
31
|
-
LOCK -.->|"Battery Low Alerts"| ALERT
|
32
|
-
DASH -.->|"System Status"| STATUS
|
33
|
-
DASH -.->|"Device Commands"| COMMAND
|
34
|
-
|
35
|
-
%% Device Subscribing
|
36
|
-
COMMAND -->|"set_temperature"| THERM
|
37
|
-
COMMAND -->|"start/stop recording"| CAM
|
38
|
-
COMMAND -->|"lock/unlock"| LOCK
|
39
|
-
SENSOR -->|"All sensor data"| DASH
|
40
|
-
COMMAND -->|"Command logging"| DASH
|
41
|
-
ALERT -->|"All alerts"| DASH
|
42
|
-
STATUS -->|"Status updates"| DASH
|
43
|
-
|
44
|
-
%% Styling
|
45
|
-
classDef deviceStyle fill:#ff6b6b,stroke:#c0392b,stroke-width:2px,color:#fff
|
46
|
-
classDef cameraStyle fill:#4ecdc4,stroke:#16a085,stroke-width:2px,color:#fff
|
47
|
-
classDef lockStyle fill:#ffe66d,stroke:#f39c12,stroke-width:2px,color:#333
|
48
|
-
classDef dashStyle fill:#a8e6cf,stroke:#27ae60,stroke-width:2px,color:#333
|
49
|
-
classDef redisStyle fill:#dc143c,stroke:#a00,stroke-width:2px,color:#fff
|
50
|
-
|
51
|
-
class THERM deviceStyle
|
52
|
-
class CAM cameraStyle
|
53
|
-
class LOCK lockStyle
|
54
|
-
class DASH dashStyle
|
55
|
-
class SENSOR,COMMAND,ALERT,STATUS redisStyle
|
56
|
-
```
|
9
|
+

|
57
10
|
|
58
11
|
## Message Flow Details
|
59
12
|
|
@@ -81,24 +34,7 @@ All IoT devices continuously publish sensor readings to the `SensorDataMessage`
|
|
81
34
|
### 2. Device Command Flow
|
82
35
|
The dashboard and external systems send commands to specific devices via the `DeviceCommandMessage` channel:
|
83
36
|
|
84
|
-
|
85
|
-
sequenceDiagram
|
86
|
-
participant App as Mobile App
|
87
|
-
participant Redis as Redis Channel
|
88
|
-
participant Therm as Thermostat
|
89
|
-
participant Cam as Camera
|
90
|
-
participant Lock as Door Lock
|
91
|
-
|
92
|
-
App->>Redis: DeviceCommandMessage<br/>device_id THERM-001 set_temperature
|
93
|
-
Redis->>Therm: ✅ Processes THERM prefix match
|
94
|
-
Redis->>Cam: ❌ Ignores not CAM prefix
|
95
|
-
Redis->>Lock: ❌ Ignores not LOCK prefix
|
96
|
-
|
97
|
-
App->>Redis: DeviceCommandMessage<br/>device_id CAM-001 start_recording
|
98
|
-
Redis->>Therm: ❌ Ignores not THERM prefix
|
99
|
-
Redis->>Cam: ✅ Processes CAM prefix match
|
100
|
-
Redis->>Lock: ❌ Ignores not LOCK prefix
|
101
|
-
```
|
37
|
+

|
102
38
|
|
103
39
|
**Device Command Filtering Rules:**
|
104
40
|
- **THERM-*** devices: Accept `set_temperature`, `get_status`
|
@@ -108,60 +44,12 @@ sequenceDiagram
|
|
108
44
|
### 3. Alert System Flow
|
109
45
|
Devices publish critical notifications to the `AlertMessage` channel when conditions are detected:
|
110
46
|
|
111
|
-
|
112
|
-
flowchart LR
|
113
|
-
subgraph Triggers
|
114
|
-
T1[High Temperature > 28°C]
|
115
|
-
T2[Motion Detected]
|
116
|
-
T3[Battery < 20%]
|
117
|
-
T4[Device Offline > 30s]
|
118
|
-
end
|
119
|
-
|
120
|
-
subgraph Devices
|
121
|
-
THERM2[🌡️ Thermostat]
|
122
|
-
CAM2[📹 Camera]
|
123
|
-
LOCK2[🚪 Door Lock]
|
124
|
-
end
|
125
|
-
|
126
|
-
subgraph AlertChannel [AlertMessage Channel]
|
127
|
-
A1[Motion Alert]
|
128
|
-
A2[High Temp Alert]
|
129
|
-
A3[Battery Low Alert]
|
130
|
-
A4[Device Offline Alert]
|
131
|
-
end
|
132
|
-
|
133
|
-
T1 --> THERM2 --> A2
|
134
|
-
T2 --> CAM2 --> A1
|
135
|
-
T3 --> LOCK2 --> A3
|
136
|
-
T4 --> A4
|
137
|
-
|
138
|
-
AlertChannel --> DASH2[📊 Dashboard]
|
139
|
-
```
|
47
|
+

|
140
48
|
|
141
49
|
### 4. Dashboard Status Flow
|
142
50
|
The dashboard aggregates all system data and publishes periodic status updates:
|
143
51
|
|
144
|
-
|
145
|
-
graph LR
|
146
|
-
subgraph DataCollection [Data Collection]
|
147
|
-
D1[Device Last Seen Times]
|
148
|
-
D2[Alert Counts]
|
149
|
-
D3[Battery Levels]
|
150
|
-
D4[System Health]
|
151
|
-
end
|
152
|
-
|
153
|
-
subgraph Processing [Status Processing]
|
154
|
-
P1[Count Active Devices<br/>last_seen < 30s]
|
155
|
-
P2[Count Recent Alerts<br/>last 5 minutes]
|
156
|
-
P3[Calculate Averages]
|
157
|
-
end
|
158
|
-
|
159
|
-
subgraph Output [Status Output]
|
160
|
-
O1[DashboardStatusMessage<br/>Every 10 seconds]
|
161
|
-
end
|
162
|
-
|
163
|
-
DataCollection --> Processing --> Output
|
164
|
-
```
|
52
|
+

|
165
53
|
|
166
54
|
## Channel-Based Architecture Benefits
|
167
55
|
|
@@ -0,0 +1,133 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<svg width="900" height="700" viewBox="0 0 900 700" xmlns="http://www.w3.org/2000/svg">
|
3
|
+
<defs>
|
4
|
+
<style>
|
5
|
+
.bg { fill: transparent; }
|
6
|
+
.thermostat { fill: #4a2a1a; stroke: #ff6b6b; stroke-width: 2; rx: 8; }
|
7
|
+
.camera { fill: #1a3a3a; stroke: #4ecdc4; stroke-width: 2; rx: 8; }
|
8
|
+
.lock { fill: #3a3a1a; stroke: #ffe66d; stroke-width: 2; rx: 8; }
|
9
|
+
.dashboard { fill: #2a3a2a; stroke: #a8e6cf; stroke-width: 2; rx: 8; }
|
10
|
+
.redis-group { fill: #2a1a1a; stroke: #dc143c; stroke-width: 3; rx: 12; }
|
11
|
+
.channel { fill: #1a1a2a; stroke: #dc143c; stroke-width: 2; rx: 6; }
|
12
|
+
.publish-flow { stroke: #ffaa4a; stroke-width: 2; fill: none; stroke-dasharray: 5,5; }
|
13
|
+
.subscribe-flow { stroke: #4aff4a; stroke-width: 2; fill: none; marker-end: url(#arrowhead); }
|
14
|
+
.text { fill: #ffffff; font-family: 'Arial', sans-serif; font-size: 12px; }
|
15
|
+
.title { fill: #4a9eff; font-family: 'Arial', sans-serif; font-size: 18px; font-weight: bold; }
|
16
|
+
.subtitle { fill: #ffaa4a; font-family: 'Arial', sans-serif; font-size: 11px; }
|
17
|
+
.channel-text { fill: #dc143c; font-family: 'Arial', sans-serif; font-size: 10px; }
|
18
|
+
.device-label { fill: #ffffff; font-family: 'Arial', sans-serif; font-size: 10px; }
|
19
|
+
</style>
|
20
|
+
<marker id="arrowhead" markerWidth="8" markerHeight="6"
|
21
|
+
refX="8" refY="3" orient="auto">
|
22
|
+
<polygon points="0 0, 8 3, 0 6" fill="#4aff4a" />
|
23
|
+
</marker>
|
24
|
+
</defs>
|
25
|
+
|
26
|
+
<!-- Background -->
|
27
|
+
<rect class="bg" width="900" height="700"/>
|
28
|
+
|
29
|
+
<!-- Title -->
|
30
|
+
<text x="450" y="25" text-anchor="middle" class="title">Smart Home IoT System Architecture</text>
|
31
|
+
<text x="450" y="45" text-anchor="middle" class="subtitle">Redis Pub/Sub Channels for Device Communication</text>
|
32
|
+
|
33
|
+
<!-- IoT Devices -->
|
34
|
+
<rect x="50" y="100" width="140" height="80" class="thermostat"/>
|
35
|
+
<text x="120" y="125" text-anchor="middle" class="text">🌡️ Smart Thermostat</text>
|
36
|
+
<text x="120" y="145" text-anchor="middle" class="device-label">THERM-001</text>
|
37
|
+
<text x="120" y="160" text-anchor="middle" class="device-label">Living Room</text>
|
38
|
+
|
39
|
+
<rect x="50" y="220" width="140" height="80" class="camera"/>
|
40
|
+
<text x="120" y="245" text-anchor="middle" class="text">📹 Security Camera</text>
|
41
|
+
<text x="120" y="265" text-anchor="middle" class="device-label">CAM-001</text>
|
42
|
+
<text x="120" y="280" text-anchor="middle" class="device-label">Front Door</text>
|
43
|
+
|
44
|
+
<rect x="50" y="340" width="140" height="80" class="lock"/>
|
45
|
+
<text x="120" y="365" text-anchor="middle" class="text">🚪 Smart Door Lock</text>
|
46
|
+
<text x="120" y="385" text-anchor="middle" class="device-label">LOCK-001</text>
|
47
|
+
<text x="120" y="400" text-anchor="middle" class="device-label">Main Entrance</text>
|
48
|
+
|
49
|
+
<rect x="710" y="220" width="140" height="80" class="dashboard"/>
|
50
|
+
<text x="780" y="245" text-anchor="middle" class="text">📊 IoT Dashboard</text>
|
51
|
+
<text x="780" y="265" text-anchor="middle" class="device-label">System Monitor</text>
|
52
|
+
<text x="780" y="280" text-anchor="middle" class="device-label">Central Control</text>
|
53
|
+
|
54
|
+
<!-- Redis Pub/Sub Channels -->
|
55
|
+
<rect x="300" y="80" width="350" height="380" class="redis-group"/>
|
56
|
+
<text x="475" y="105" text-anchor="middle" class="title">Redis Pub/Sub Channels</text>
|
57
|
+
|
58
|
+
<!-- Individual channels -->
|
59
|
+
<rect x="320" y="130" width="310" height="50" class="channel"/>
|
60
|
+
<text x="475" y="150" text-anchor="middle" class="text">SensorDataMessage</text>
|
61
|
+
<text x="475" y="170" text-anchor="middle" class="channel-text">Temperature, Motion, Status, Battery Levels</text>
|
62
|
+
|
63
|
+
<rect x="320" y="200" width="310" height="50" class="channel"/>
|
64
|
+
<text x="475" y="220" text-anchor="middle" class="text">DeviceCommandMessage</text>
|
65
|
+
<text x="475" y="240" text-anchor="middle" class="channel-text">set_temperature, start_recording, lock/unlock, get_status</text>
|
66
|
+
|
67
|
+
<rect x="320" y="270" width="310" height="50" class="channel"/>
|
68
|
+
<text x="475" y="290" text-anchor="middle" class="text">AlertMessage</text>
|
69
|
+
<text x="475" y="310" text-anchor="middle" class="channel-text">Motion Detected, Battery Low, High Temperature</text>
|
70
|
+
|
71
|
+
<rect x="320" y="340" width="310" height="50" class="channel"/>
|
72
|
+
<text x="475" y="360" text-anchor="middle" class="text">DashboardStatusMessage</text>
|
73
|
+
<text x="475" y="380" text-anchor="middle" class="channel-text">System Status, Device Counts, Alert Summaries</text>
|
74
|
+
|
75
|
+
<!-- Device Publishing (dashed lines to channels) -->
|
76
|
+
<path d="M 190 140 L 320 155" class="publish-flow"/>
|
77
|
+
<text x="255" y="135" class="subtitle">Temperature Data</text>
|
78
|
+
|
79
|
+
<path d="M 190 260 L 320 155" class="publish-flow"/>
|
80
|
+
<text x="255" y="208" class="subtitle">Motion Data</text>
|
81
|
+
|
82
|
+
<path d="M 190 380 L 320 155" class="publish-flow"/>
|
83
|
+
<text x="255" y="368" class="subtitle">Lock Status</text>
|
84
|
+
|
85
|
+
<!-- Alert publishing -->
|
86
|
+
<path d="M 190 280 L 320 295" class="publish-flow"/>
|
87
|
+
<path d="M 190 160 L 320 295" class="publish-flow"/>
|
88
|
+
<path d="M 190 400 L 320 295" class="publish-flow"/>
|
89
|
+
|
90
|
+
<!-- Dashboard publishing -->
|
91
|
+
<path d="M 710 240 L 630 365" class="publish-flow"/>
|
92
|
+
<path d="M 710 260 L 630 225" class="publish-flow"/>
|
93
|
+
|
94
|
+
<!-- Device subscribing (solid arrows from channels) -->
|
95
|
+
<path d="M 630 225 L 710 140" class="subscribe-flow"/>
|
96
|
+
<text x="670" y="182" class="subtitle">set_temperature</text>
|
97
|
+
|
98
|
+
<path d="M 630 225 L 710 180" class="subscribe-flow"/>
|
99
|
+
<text x="650" y="202" class="subtitle">start/stop recording</text>
|
100
|
+
|
101
|
+
<path d="M 630 225 L 710 280" class="subscribe-flow"/>
|
102
|
+
<text x="670" y="252" class="subtitle">lock/unlock</text>
|
103
|
+
|
104
|
+
<!-- Dashboard subscribing to all data -->
|
105
|
+
<path d="M 630 155 L 710 220" class="subscribe-flow"/>
|
106
|
+
<path d="M 630 295 L 710 240" class="subscribe-flow"/>
|
107
|
+
<path d="M 630 365 L 710 260" class="subscribe-flow"/>
|
108
|
+
<path d="M 630 225 L 710 280" class="subscribe-flow"/>
|
109
|
+
|
110
|
+
<!-- Channel Benefits -->
|
111
|
+
<rect x="50" y="500" width="800" height="180" fill="#1a1a1a" stroke="#4a9eff" rx="8"/>
|
112
|
+
<text x="70" y="525" class="title">Channel-Based Architecture Benefits</text>
|
113
|
+
|
114
|
+
<text x="70" y="550" class="text">🎯 Efficient Message Routing:</text>
|
115
|
+
<text x="90" y="565" class="subtitle">• Each message type uses dedicated Redis channel</text>
|
116
|
+
<text x="90" y="580" class="subtitle">• Devices only process relevant messages (no unnecessary filtering)</text>
|
117
|
+
<text x="90" y="595" class="subtitle">• Automatic load balancing through Redis pub/sub mechanism</text>
|
118
|
+
|
119
|
+
<text x="450" y="550" class="text">🔧 Device-Specific Processing:</text>
|
120
|
+
<text x="470" y="565" class="subtitle">• THERM-* devices process temperature commands only</text>
|
121
|
+
<text x="470" y="580" class="subtitle">• CAM-* devices handle recording commands only</text>
|
122
|
+
<text x="470" y="595" class="subtitle">• LOCK-* devices respond to lock/unlock commands only</text>
|
123
|
+
|
124
|
+
<text x="70" y="620" class="text">📈 Scalable Architecture:</text>
|
125
|
+
<text x="90" y="635" class="subtitle">• Easy to add new device types with new ID prefixes</text>
|
126
|
+
<text x="90" y="650" class="subtitle">• Multiple instances of same device type supported</text>
|
127
|
+
<text x="90" y="665" class="subtitle">• Dashboard aggregates all data for centralized monitoring</text>
|
128
|
+
|
129
|
+
<text x="450" y="620" class="text">🔄 Event-Driven Communication:</text>
|
130
|
+
<text x="470" y="635" class="subtitle">• Real-time sensor data publishing every 3-5 seconds</text>
|
131
|
+
<text x="470" y="650" class="subtitle">• Immediate alert generation on threshold conditions</text>
|
132
|
+
<text x="470" y="665" class="subtitle">• Bidirectional command and status flow</text>
|
133
|
+
</svg>
|