# To build these, you need DiTAA
# java -jar ditaa0_8.jar architecture_diagrams.txt

Moksha middleware stack

/----------------------------------------------\
| Optional middleware                          |
| +------------------------------------------+ |
| | repoze.profile                           | |
| | Profiling                                | |
| +------------------------------------------| |
| | repoze.squeeze                           | |
| | Resource compression                     | |
| +------------------------------------------+ |
+----------------------------------------------+
| TurboGears2 Middleware                       |
| +------------------------------------------+ |
| | Routes                                   | |
| | Application routing/dispatching          | |
| +------------------------------------------+ |
| | Beaker                                   | |
| | Session management                       | |
| | Caching layer                            | |
| +------------------------------------------+ |
| | ToscaWidgets                             | |
| | Widget resource injection                | |
| +------------------------------------------+ |
| | repoze.who                               | |
| | Authentication                           | |
| +------------------------------------------+ |
| | repoze.what                              | |
| | Authorization                            | |
| +------------------------------------------+ |
| | repoze.tm2                               | |
| | Transaction management                   | |
| +------------------------------------------+ |
| | Paste                                    | |
| | Registry manager                         | |
| +------------------------------------------+ |
| | WebError                                 | |
| | Error handling & Debugging               | |
| +------------------------------------------+ |
+----------------------------------------------|
| Moksha Middleware                            |
| +--------------+ +---------+                 |
| | Applications | | Widgets |                 |
| +--------------+ +---------+                 |
+----------------------------------------------|
|              Your Application                |
\----------------------------------------------/

Moksha Hub

/---------------------------\
| Plugin loader             |
+---------------------------+
| Event loop reactor        |
+---------------------------+
| Plugins                   |
| +-----------+-----------+ |
| | Consumers | Producers | |
| +-----------+-----------+ |
+---------------------------+
| Protocol Translator       |
| +-----+-------+  +-----+  |
| |AMQP | STOMP |  | 0mq |  |
| +-------------+  +-----+  |
\---------------------------/
        ^              ^
        |              |
        v              v
 /----------------\ /-----\
 | Message Broker | | 0mq |
 \----------------/ \-----/


Rapid development deployment

/-----------------\                           /------------------------------\
| Orbited         |                           | Moksha Hub                   |
|                 |                           |                              |
|       +---------+      +------------+       |                              |
|       | MorbidQ | <--- | STOMP {io} | --->  | +-----------+  +-----------+ |
|       +---------+      +------------+       | | Producers |  | Consumers | |
\-----------------/                           | +-----------+  +-----------+ |
                                              \------------------------------/

Bringing an AMQP broker into the mix

/-----------------\                           /------------------------------\
| Orbited         |                           | Moksha Hub                   |
|                 |                           |                              |
|       +---------+      +------------+       |                              |      +-----------+          /----------------\
|       | MorbidQ | <--- | STOMP {io} | --->  | +-----------+  +-----------+ | <--- | AMQP {io} | -------> | Qpid           |
|       +---------+      +------------+       | | Producers |  | Consumers | |      +-----------+          | {s}            |
\-----------------/                           | +-----------+  +-----------+ |                             \----------------/
                                              \------------------------------/


100% AMQP

               /------------------------------\
               | Moksha Hub                   |
/---------\    |                              |      +-----------+          /----------------\
| Orbited |    | +-----------+  +-----------+ | <--- | AMQP {io} | -------> | Qpid           |
\---------/    | | Producers |  | Consumers | |      +-----------+          | {s}            |
               | +-----------+  +-----------+ |                             \----------------/
               |                              |
               \------------------------------/

0mq with Websockets

                                    +-------------+
/------------------------------\    | 0mq service |
| Moksha Hub                   |    | {s}         |
|                              |    +-------------+
+------------------+           |         ^
| WebSocket Server |           |         |
+------------------+           |         |
|                              |      +----------+      /-------------\
| +-----------+  +-----------+ | <--- | 0mq {io} | ---> | 0mq service |
| | Producers |  | Consumers | |      +----------+      | {s}         |
| +-----------+  +-----------+ |                        \-------------/
|                              |
\------------------------------/



Moksha Live Widgets
-------------------

Speaking AMQP (kamaloka.js) or STOMP through Orbited to a broker.

/-----------------------------------\
| Browser                           |
|                                   |
| /-------------\     +-------------+    +---------------+    +---------+     +----------------+
| | Live Widget |<--->| Live Socket |<---|{io}AMQP/STOMP |--->| Orbited |<--->| Message broker |
| \-------------/     +-------------+    +---------------+    +---------+     +----------------+
|                                   |
\-----------------------------------/

*or* WebSockets connect directly to the moksha hub.

/-----------------------------------\
| Browser                           |                         /---------------------\
|                                   |                         | Moksha Hub          |
| /-------------\     +-------------+    +---------------+    +------------------+  |
| | Live Widget |<--->| WebSocket   |<---|{io}WebSocket  |--->| WebSocket Server |  |
| \-------------/     +-------------+    +---------------+    +------------------+  |
|                                   |                         |               +-----+
\-----------------------------------/                         |               | 0mq |
                                                              |               +-----+
                                                              \---------------------/

Anatomy of a Live Widget

/-----------------------------------------------------------------------\
|                       +--------------------+ +----------------------+ |
| Live Widget           |      Topic(s)      | | On message callback  | |
|                       +--------------------+ +----------------------+ |
|                                                                       |
| +-------------------+ +--------------------+ +----------------------+ |
| | Server side logic | | JS & CSS resources | |   Widget template    | |
| +-------------------+ +--------------------+ +----------------------+ |
\-----------------------------------------------------------------------/

