Architecture
Components
Structure of the library includes several components, such as:
Request
RequestMap
RequestHandler
Response
Event
EventMap
EventHandler
MessageBroker
EventEmitter
Container
Dispatcher
Middleware
MiddlewareChain
Mediator
Components Dependency
Request-related system side:
classDiagram
Dispatcher <|-- Mediator
MiddlewareChain <|-- Dispatcher
RequestMap <|-- Dispatcher
class RequestMap{
+bind(request_type, handler_type) None
+get(request_type) Type[RequestHandler]
}
class MiddlewareChain{
+set(chain) None
+add(middleware) None
+wrap(handler) WrappedHandler
}
class Dispatcher{
+RequestMap request_map
+Container container
+MiddlewareChain middleware_chain
+dispatch(request) DispatchResult
}
class Mediator{
+RequestMap request_map
+Container container
+MiddlewareChain middleware_chain
+EventEmitter event_emitter
+send(request) Response
}
Event-related system side:
classDiagram
EventEmitter <|-- Mediator
EventMap <|-- EventEmitter
MessageBroker <|-- EventEmitter
class EventMap{
+bind(event_type, handler_type) None
+get(event_type) List[Type[EventHandler]]
}
class MessageBroker{
+send_message(message) None
}
class EventEmitter{
+EventMap event_map
+Container container
+MessageBroker message_broker
+emit(event) None
}
class Mediator{
+RequestMap request_map
+Container container
+MiddlewareChain middleware_chain
+EventEmitter event_emitter
+send(request) Response
}
Components Interaction
Request dispatching:
graph TB
Client-- JoinMeetingCommand -->Mediator-->Dispatcher-- JoinMeetingCommand -->JoinMeetingCommandHandler
Description:
- Client sends JoinMeetingCommand to Mediator.
- Mediator sends this command to Dispatcher.
- Dispatcher gets its handler and builds instance of command handler class via Container.
- Dispatcher handles command using certain method of its handler.
- Dispatcher returns DispatchResult to Mediator, which contains published events and Response.
Event dispatching:
graph TB
Dispatcher-- UserJoinedEvent -->Mediator-->EventEmitter-- UserJoinedEvent -->UserJoinedEventHandler
Description:
- Dispatcher returns DispatchResult to Mediator, which contains published events and Response.
- Mediator sends published event to EventEmitter.
- Event gets its handler and builds instance of event handler class via Container.
- EventEmitter handles command using certain method of its handler.