# openharmony/hiviewdfx_hiview architecture

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

- Interactive diagram: https://gitdiagram.com/openharmony/hiviewdfx_hiview
- Repository: https://github.com/openharmony/hiviewdfx_hiview

## Overview

##### Main Components
- Adapter Layer – This is the operating system adaptation layer (seen under “adapter” and “adapter/service”). It contains code that adapts the system service APIs (e.g., HiSysEvent API) to Hiview’s internal interfaces.
- Base Module – Under “base”, this provides core definitions, utility classes, and common declarations. It includes event definitions, logging, basic event processing utilities, and helper functions.
- Core Module – Found under “core”, “interfaces”, and parts of “framework” directories, this module manages plug‐in configurations and is responsible for event dispatch, collection, and coordination.
- Service – Under “service”, it provides platform services, for example, the run-information exporting functions.
- Plugins – The “plugins” directory is extensive and consists of independent service modules (for example, eventlogger, faultlogger, freeze_detector, performance, unified_collector, etc.). These plug-ins extend the functionality, handling specific types of events, performing logging, analysis, or providing specialized monitoring capabilities.
- Utility and Testing Components – There are various directories (like “utility”, “test”, and “build”) that show support for testing, configuration, and build automation.

##### Representing Interactions and Data Flow
- HiSysEventSource (a part of the event source subsystem/code in base or plugins) which reads and logs these events.
- The Adapter layer then translates these events into the internal format consumed by the Base module.
- From there, the Core module picks up the formatted events and dispatches them to the appropriate Plug-in modules.
- The Service layer then aggregates or formats output data (for example, exporting run-information) that could be reported back to other OpenHarmony subsystems.

##### Architectural Patterns
- Event-Driven Architecture: Emphasize that the system uses a centralized event bus (or stubs) to capture and process events.
- Plug-in Management and Dynamic Loading: Note that plugins are modular and can be independently developed, tested, and loaded based on configuration.
- OS Adaptation Layer: The Adapter wraps differences between operating system APIs and the Hiview internal APIs, making the module portable across different hardware platforms.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["System Services & App Frameworks"]:::green
    B["HiSysEvent API"]:::green
    C["Adapter Layer"]:::blue
    D["Base Module/Utilities"]:::blue
    E["Core Module – Plug-in Management"]:::green
    F["Service Layer"]:::green
    subgraph "Plugins"
        F1["Event Logger"]:::orange
        F2["Fault Logger"]:::orange
        F3["Freeze Detector"]:::orange
        F4["Performance Monitor"]:::orange
        F5["Unified Collector"]:::orange
    end
    G["Utility & Testing Components"]:::gray

    A -->|"sendsEvent"| B
    B -->|"calls"| C
    C -->|"adapts"| D
    D -->|"formatsEvent"| E
    E -->|"dispatches"| F1
    E -->|"dispatches"| F2
    E -->|"dispatches"| F3
    E -->|"dispatches"| F4
    E -->|"dispatches"| F5
    E -->|"aggregates"| F
    F -->|"exports"| A
    G -->|"supports"| E

    click C "https://github.com/openharmony/hiviewdfx_hiview/tree/master/adapter/"
    click C "https://github.com/openharmony/hiviewdfx_hiview/tree/master/adapter/service"
    click D "https://github.com/openharmony/hiviewdfx_hiview/tree/master/base/"
    click E "https://github.com/openharmony/hiviewdfx_hiview/tree/master/core/"
    click F "https://github.com/openharmony/hiviewdfx_hiview/tree/master/service/"
    click F1 "https://github.com/openharmony/hiviewdfx_hiview/tree/master/plugins/eventlogger"
    click F2 "https://github.com/openharmony/hiviewdfx_hiview/tree/master/plugins/faultlogger"
    click F3 "https://github.com/openharmony/hiviewdfx_hiview/tree/master/plugins/freeze_detector"
    click F4 "https://github.com/openharmony/hiviewdfx_hiview/tree/master/plugins/performance"
    click F5 "https://github.com/openharmony/hiviewdfx_hiview/tree/master/plugins/unified_collector"
    click G "https://github.com/openharmony/hiviewdfx_hiview/tree/master/utility/"
    click G "https://github.com/openharmony/hiviewdfx_hiview/tree/master/test/"

    classDef blue fill:#add8e6,stroke:#0000ff,stroke-width:2px;
    classDef green fill:#ccffcc,stroke:#008000,stroke-width:2px;
    classDef orange fill:#ffcc99,stroke:#ff8c00,stroke-width:2px;
    classDef gray fill:#e6e6e6,stroke:#808080,stroke-width:2px;
```
