PAN Bus Communication Patterns
Pub/Sub Architecture
%%{init: {'theme':'base', 'themeVariables': { 'primaryColor':'#667eea','secondaryColor':'#764ba2','tertiaryColor':'#48bb78'}}}%%
graph TB
subgraph Publishers["๐ค Publishers"]
P1["๐ Login Button"]
P2["๐ Cart Component"]
P3["๐ API Service"]
end
subgraph PAN["๐ PAN Bus"]
Router["๐ก Topic Router"]
subgraph Topics["๐ Topics"]
T1["๐ user.login"]
T2["โ cart.item.added"]
T3["๐ฆ data.loaded"]
end
end
subgraph Subscribers["๐ฅ Subscribers"]
S1["๐ค User Menu"]
S2["๐ Sidebar"]
S3["๐ Notification"]
S4["๐ Analytics"]
end
P1 -->|๐ข publish| T1
P2 -->|๐ข publish| T2
P3 -->|๐ข publish| T3
T1 --> Router
T2 --> Router
T3 --> Router
Router -->|๐ฌ notify| S1
Router -->|๐ฌ notify| S2
Router -->|๐ฌ notify| S3
Router -->|๐ฌ notify| S4
classDef publisher fill:#667eea,stroke:#5568d3,stroke-width:3px,color:#fff,font-weight:bold
classDef pan fill:#764ba2,stroke:#6a3f99,stroke-width:3px,color:#fff,font-weight:bold
classDef subscriber fill:#48bb78,stroke:#38a169,stroke-width:3px,color:#fff,font-weight:bold
classDef topic fill:#4299e1,stroke:#3182ce,stroke-width:2px,color:#fff
class P1,P2,P3 publisher
class Router pan
class S1,S2,S3,S4 subscriber
class T1,T2,T3 topic
Message Flow Sequence
%%{init: {'theme':'base', 'themeVariables': { 'actorBkg':'#667eea','actorBorder':'#5568d3','actorTextColor':'#fff','signalColor':'#764ba2','signalTextColor':'#2d3748'}}}%%
sequenceDiagram
participant LoginBtn as ๐ Login Button
participant PAN as ๐ PAN Bus
participant UserMenu as ๐ค User Menu
participant Sidebar as ๐ Sidebar
participant Analytics as ๐ Analytics
participant API as ๐ Backend
Note over LoginBtn,Analytics: ๐ฑ๏ธ User clicks login button
LoginBtn->>+PAN: ๐ข publish('user.login.started')
PAN-->>UserMenu: ๐ฌ notify
PAN-->>Sidebar: ๐ฌ notify
Note over UserMenu: โณ Show loading state
UserMenu->>UserMenu: ๐จ Update UI
LoginBtn->>+API: ๐ POST /api/login
API-->>-LoginBtn: โ
{token, user}
LoginBtn->>PAN: ๐ข publish('user.login.success', {user})
PAN-->>UserMenu: ๐ฌ notify
PAN-->>Sidebar: ๐ฌ notify
PAN-->>-Analytics: ๐ฌ notify
Note over UserMenu,Sidebar: ๐จ Update with user data
UserMenu->>UserMenu: ๐ค Update with user data
Sidebar->>Sidebar: ๐ฑ Show user panel
Analytics->>API: ๐ Track event
Topic Namespace Structure
%%{init: {'theme':'base', 'themeVariables': { 'primaryColor':'#667eea','secondaryColor':'#48bb78','tertiaryColor':'#4299e1'}}}%%
graph TB
Root["๐ *<br/>All Events"]
Root --> User["๐ค user.*"]
Root --> Cart["๐ cart.*"]
Root --> App["๐ฑ app.*"]
User --> UserAuth["๐ user.auth.*"]
User --> UserProfile["๐ user.profile.*"]
UserAuth --> Login["๐ user.auth.login"]
UserAuth --> Logout["๐ช user.auth.logout"]
UserAuth --> Refresh["๐ user.auth.refresh"]
UserProfile --> ProfileUpdate["โ๏ธ user.profile.update"]
UserProfile --> ProfileFetch["๐ฅ user.profile.fetch"]
Cart --> CartItem["๐ฆ cart.item.*"]
Cart --> CartCheckout["๐ณ cart.checkout"]
CartItem --> ItemAdd["โ cart.item.add"]
CartItem --> ItemRemove["โ cart.item.remove"]
CartItem --> ItemUpdate["๐ cart.item.update"]
App --> AppTheme["๐จ app.theme.change"]
App --> AppRoute["๐งญ app.route.change"]
App --> AppError["โ ๏ธ app.error"]
classDef root fill:#764ba2,stroke:#6a3f99,stroke-width:4px,color:#fff,font-weight:bold
classDef namespace fill:#667eea,stroke:#5568d3,stroke-width:3px,color:#fff,font-weight:bold
classDef event fill:#48bb78,stroke:#38a169,stroke-width:2px,color:#fff
class Root root
class User,Cart,App,UserAuth,UserProfile,CartItem namespace
class Login,Logout,Refresh,ProfileUpdate,ProfileFetch,ItemAdd,ItemRemove,ItemUpdate,AppTheme,AppRoute,AppError,CartCheckout event
Wildcard Subscription Matching
%%{init: {'theme':'base', 'themeVariables': { 'primaryColor':'#667eea','secondaryColor':'#48bb78','tertiaryColor':'#f56565'}}}%%
graph LR
subgraph Events["๐ก Published Events"]
E1["๐ user.login"]
E2["๐ช user.logout"]
E3["โ๏ธ user.profile.update"]
E4["โ cart.item.add"]
end
subgraph Subs["๐ฅ Subscriptions"]
S1["๐ฏ subscribe('user.login')"]
S2["๐ค subscribe('user.*')"]
S3["๐ subscribe('*.update')"]
S4["๐ subscribe('*')"]
end
E1 -.โ
matches.-> S1
E1 -.โ
matches.-> S2
E1 -.โ
matches.-> S4
E2 -.โ
matches.-> S2
E2 -.โ
matches.-> S4
E3 -.โ
matches.-> S2
E3 -.โ
matches.-> S3
E3 -.โ
matches.-> S4
E4 -.โ
matches.-> S4
classDef event fill:#667eea,stroke:#5568d3,stroke-width:3px,color:#fff,font-weight:bold
classDef specific fill:#48bb78,stroke:#38a169,stroke-width:3px,color:#fff,font-weight:bold
classDef catchall fill:#f56565,stroke:#e53e3e,stroke-width:3px,color:#fff,font-weight:bold
class E1,E2,E3,E4 event
class S1,S2,S3 specific
class S4 catchall
Request/Response Pattern
%%{init: {'theme':'base', 'themeVariables': { 'actorBkg':'#667eea','actorBorder':'#5568d3','actorTextColor':'#fff','signalColor':'#764ba2'}}}%%
sequenceDiagram
participant Requester as โ๏ธ Component A
participant PAN as ๐ PAN Bus
participant Responder as ๐ Auth Service
Note over Responder: ๐ Registers responder
Responder->>PAN: ๐ฏ respond('auth.token.get', handler)
Note over Requester: ๐ Needs auth token
Requester->>+PAN: โ request('auth.token.get')
PAN->>PAN: ๐ Generate response ID
PAN->>+Responder: โถ๏ธ Trigger handler
Note over Responder: ๐พ Get token from storage
Responder->>Responder: ๐ Get token from storage
Responder->>-PAN: ๐ค publish response
PAN->>-Requester: โ
Return token
Note over Requester: ๐ Uses token for API call
Requester->>API: ๐ GET /api/data<br/>Authorization: Bearer {token}
Event Patterns Comparison
%%{init: {'theme':'base', 'themeVariables': { 'primaryColor':'#667eea','secondaryColor':'#764ba2','tertiaryColor':'#48bb78'}}}%%
graph TB
subgraph FF["๐ข Fire and Forget"]
FF1["๐ค Publisher"]
FF2["๐ PAN Bus"]
FF3["๐ฅ Subscribers"]
FF1 -->|๐ข publish| FF2
FF2 -->|๐ฌ notify all| FF3
FF1 -.-x|โก no wait| FF3
end
subgraph RR["โ Request/Response"]
RR1["โ Requester"]
RR2["๐ PAN Bus"]
RR3["๐ฌ Responder"]
RR1 -->|โ request| RR2
RR2 -->|โถ๏ธ invoke| RR3
RR3 -->|โ
respond| RR2
RR2 -->|๐ฆ return| RR1
end
subgraph CMD["โ๏ธ Command"]
C1["๐จโ๐ผ Commander"]
C2["๐ PAN Bus"]
C3["โ๏ธ Handler"]
C1 -->|๐ command| C2
C2 -->|โถ๏ธ execute| C3
C3 -->|โ
acknowledge| C2
C2 -.๐ฌ optional.-> C1
end
classDef bus1 fill:#667eea,stroke:#5568d3,stroke-width:3px,color:#fff,font-weight:bold
classDef bus2 fill:#764ba2,stroke:#6a3f99,stroke-width:3px,color:#fff,font-weight:bold
classDef bus3 fill:#48bb78,stroke:#38a169,stroke-width:3px,color:#fff,font-weight:bold
class FF2 bus1
class RR2 bus2
class C2 bus3
PAN Bus Internal Architecture
%%{init: {'theme':'base', 'themeVariables': { 'primaryColor':'#764ba2','secondaryColor':'#667eea','tertiaryColor':'#48bb78'}}}%%
graph TB
subgraph Core["โ๏ธ PAN Bus Core"]
Router["๐ก Topic Router"]
subgraph Registry["๐ Subscription Registry"]
Exact["๐ฏ Exact Matches<br/>Mapโนtopic, Setโนhandlerโบโบ"]
Wildcard["๐ Wildcard Patterns<br/>Array of patterns and handlers"]
end
subgraph Queue["๐ฎ Message Queue"]
EventQueue["๐ฅ Event Queue"]
Batch["๐ฆ Batch Processor"]
end
Router --> Exact
Router --> Wildcard
Router --> EventQueue
EventQueue --> Batch
end
subgraph API["๐ง API Methods"]
Publish["๐ข publish"]
Subscribe["๐ฅ subscribe"]
Request["โ request"]
Respond["๐ฌ respond"]
end
Publish --> Router
Subscribe --> Exact & Wildcard
Request --> Router
Respond --> Router
classDef router fill:#764ba2,stroke:#6a3f99,stroke-width:4px,color:#fff,font-weight:bold
classDef registry fill:#667eea,stroke:#5568d3,stroke-width:3px,color:#fff,font-weight:bold
classDef queue fill:#48bb78,stroke:#38a169,stroke-width:3px,color:#fff,font-weight:bold
classDef api fill:#4299e1,stroke:#3182ce,stroke-width:2px,color:#fff
class Router router
class Exact,Wildcard registry
class EventQueue,Batch queue
class Publish,Subscribe,Request,Respond api
Debugging with Event Inspector
%%{init: {'theme':'base', 'themeVariables': { 'primaryColor':'#667eea','secondaryColor':'#ed8936','tertiaryColor':'#48bb78'}}}%%
graph TB
subgraph Application["๐ฑ Application"]
C1["โ๏ธ Component 1"]
C2["โ๏ธ Component 2"]
C3["โ๏ธ Component 3"]
end
subgraph PAN["๐ PAN Bus"]
Router["๐ก Message Router"]
end
subgraph Inspector["๐ Inspector"]
Monitor["๐ subscribe('*')"]
Log["๐ Event Log"]
Filter["๐ Filter Panel"]
Viz["๐ Visualization"]
end
C1 -->|๐ข publish| Router
C2 -->|๐ข publish| Router
C3 -->|๐ข publish| Router
Router -->|๐ฌ notify| C1
Router -->|๐ฌ notify| C2
Router -->|๐ฌ notify| C3
Router -.๐ all events.-> Monitor
Monitor --> Log
Log --> Filter
Log --> Viz
classDef component fill:#667eea,stroke:#5568d3,stroke-width:3px,color:#fff,font-weight:bold
classDef pan fill:#764ba2,stroke:#6a3f99,stroke-width:3px,color:#fff,font-weight:bold
classDef inspector fill:#ed8936,stroke:#dd6b20,stroke-width:3px,color:#fff,font-weight:bold
classDef viz fill:#48bb78,stroke:#38a169,stroke-width:3px,color:#fff,font-weight:bold
class C1,C2,C3 component
class Router pan
class Monitor,Log,Filter inspector
class Viz viz
Event Lifecycle
%%{init: {'theme':'base', 'themeVariables': { 'primaryColor':'#667eea','primaryTextColor':'#fff','primaryBorderColor':'#5568d3'}}}%%
stateDiagram-v2
[*] --> Published: ๐ข publish(topic, data)
Published --> Routing: ๐งญ Route to subscribers
Routing --> MatchExact: ๐ฏ Check exact matches
Routing --> MatchWildcard: ๐ Check wildcards
MatchExact --> Notify: โ
Found subscribers
MatchWildcard --> Notify: โ
Found subscribers
MatchExact --> Complete: โ No matches
MatchWildcard --> Complete: โ No matches
Notify --> HandleAsync: โก Async handlers
Notify --> HandleSync: ๐ Sync handlers
HandleAsync --> Complete: โ
HandleSync --> Complete: โ
Complete --> [*]
note right of Routing
๐ Look up topic in registry
๐ Match wildcards
๐ฅ Collect all handlers
end note
note right of Notify
๐ Call each handler
๐ฆ Pass message data
โ ๏ธ Handle errors
end note
Error Handling in PAN Bus
%%{init: {'theme':'base', 'themeVariables': { 'primaryColor':'#667eea','secondaryColor':'#f56565','tertiaryColor':'#48bb78'}}}%%
graph TB
Publisher["๐ค Publisher"]
PAN["๐ PAN Bus"]
Publisher -->|๐ข publish| PAN
PAN --> S1["๐ฅ Subscriber 1"]
PAN --> S2["๐ฅ Subscriber 2"]
PAN --> S3["๐ฅ Subscriber 3"]
S1 -->|โ
success| End1["โ
"]
S2 -->|๐ฅ throws error| Error["โ ๏ธ Error Handler"]
S3 -->|โ
success| End3["โ
"]
Error -->|๐ log error| Console["๐ฅ๏ธ Console"]
Error -->|๐ข publish| ErrorTopic["โ app.error"]
ErrorTopic --> ErrorHandler["โ ๏ธ Error Component"]
Error -.๐ doesn't stop.-> S3
classDef success fill:#48bb78,stroke:#38a169,stroke-width:3px,color:#fff,font-weight:bold
classDef error fill:#f56565,stroke:#e53e3e,stroke-width:3px,color:#fff,font-weight:bold
classDef pan fill:#764ba2,stroke:#6a3f99,stroke-width:3px,color:#fff,font-weight:bold
classDef neutral fill:#667eea,stroke:#5568d3,stroke-width:2px,color:#fff
class End1,End3 success
class Error,ErrorTopic,ErrorHandler error
class PAN pan
class Publisher,S1,S2,S3 neutral