# omnitrix4/event_driven architecture

> Architecture diagram of the GitHub repository omnitrix4/event_driven, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/omnitrix4/event_driven
- Repository: https://github.com/omnitrix4/event_driven

## Overview

##### Main Components
- Event Base and Derived Events – Represented by “event.h”. Explain that this is the base class for events (defining event types and priorities) which users extend for their specific business logic.
- Event Queue – “event_queue.h” serves as the data structure to push/pop events. Represent this as a central queue component.
- Event Loop – “event_loop.h” is the independent-thread loop that continuously pulls events from the queue and initiates processing.
- Event Dispatcher – Defined in “event_dispatcher.h”, this component registers and manages event handling routines. Its role is to distribute events to the correct handlers.
- Event Framework – “event_framework.h” is the entry point for users. It wraps the integration of the above components (queue, dispatcher, and loop) and exposes an easy-to-use API.
- Timer Management Components – In “include/timer_manager.cpp” and “include/timer_manager.h” and the TimerEvent/CountTimerEvent in the Event sub-directory, you show that timing-based events are handled.
- (Optional) Message Queue – Although the “msgqueue” folder has “msg_queue.h”, decide if this is part of the event framework or an auxiliary component for inter-thread or inter-process communication. Include it if it interacts with core event components.

##### Relationships and Interactions
- The Event Framework pushes events into the Event Queue.
- The Event Loop (running on a dedicated thread) continuously checks the Event Queue for new events.
- Once an event is dequeued, the Event Dispatcher is notified to route the event to its appropriate handler (which can be user-implemented, leveraging the move semantics mentioned in the README).
- Timer-related events (managed by the Timer Manager) may also be injected into the Event Queue.
- If the msgqueue component is used, illustrate the data flow between components that might depend on messaging for communication.

##### Architectural Patterns and Design Principles
- The framework follows a decoupled design where event producers and consumers are separated by the Event Queue.
- It illustrates an asynchronous, event-driven design pattern.
- The system leverages concepts of single responsibility: each component (queue, loop, dispatcher) is clearly defined.
- Move semantics are highlighted in the README; this suggests optimal resource management and preventing unnecessary copies during event handling.

##### Representation Based on Project's Nature
Since this is not a full-stack application but rather a core framework library:
- Internal interactions rather than external web/API interfaces.
- How users integrate their business logic by extending the Event class and registering their handlers with the Event Dispatcher.
- Document clearly how the central Event Loop ties the components together and ensures asynchronous processing.

##### Additional Diagramming Points
- To visually represent the unified flow starting from user input to final event processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["User/Application"]:::user
    B["Event Framework"]:::framework
    C["Event Queue"]:::queue
    D["Event Loop"]:::loop
    E["Event Dispatcher"]:::dispatcher
    F["Event Base & Derived Events"]:::event
    M["Message Queue"]:::msg

    subgraph "Timer Management"
        TmCore["Timer Manager Core"]:::timer
        TEvent["Timer Event"]:::timer
        CTEvent["Count Timer Event"]:::timer
    end

    A -->|"invokes"| B
    B -->|"pushes_events"| C
    TmCore -->|"injects_timed_events"| C
    C -->|"polls"| D
    D -->|"dispatches"| E
    E -->|"uses_events"| F
    E -->|"communicates_with"| M
    A -.->|"extends"| F

    click F "https://github.com/omnitrix4/event_driven/blob/main/include/event.h"
    click C "https://github.com/omnitrix4/event_driven/blob/main/include/event_queue.h"
    click D "https://github.com/omnitrix4/event_driven/blob/main/include/event_loop.h"
    click E "https://github.com/omnitrix4/event_driven/blob/main/include/event_dispatcher.h"
    click B "https://github.com/omnitrix4/event_driven/blob/main/include/event_framework.h"
    click TmCore "https://github.com/omnitrix4/event_driven/blob/main/include/timer_manager.h"
    click TEvent "https://github.com/omnitrix4/event_driven/blob/main/include/Event/TimerEvent.h"
    click CTEvent "https://github.com/omnitrix4/event_driven/blob/main/include/Event/CountTimerEvent.h"
    click M "https://github.com/omnitrix4/event_driven/blob/main/msgqueue/msg_queue.h"

    classDef user fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef framework fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef queue fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef loop fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef dispatcher fill:#d1ecf1,stroke:#333,stroke-width:2px;
    classDef event fill:#e2e3e5,stroke:#333,stroke-width:2px;
    classDef timer fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef msg fill:#d6d8db,stroke:#333,stroke-width:2px;
```
