# lzy107/simuphy2 architecture

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

- Interactive diagram: https://gitdiagram.com/lzy107/simuphy2
- Repository: https://github.com/lzy107/simuphy2

## Overview

##### Main Components
- Device Manager (or Device Instance Management) – Handles device type registration (the device “classes” or templates) and device instance creation.
- Memory Manager – Manages creation and operations on memory regions associated with each device.
- Monitor (Watchpoint) Component – Provides the functionality to add watchpoints to memory regions and triggers upon memory access events.
- Action Manager – Defines and manages actions (callbacks, scripts, command executions) that are executed when monitoring events occur.
- Rule Engine – Binds conditions (watchpoints) to specific actions allowing for complex behavior, such as cross-device interactions.

##### Architectural Layers/Relationships
- Layer 1 – Device Type Layer:
- Represents the device_type_list where available device “templates” are defined.
- That each device type includes a set of operations (create, destroy, reset, etc.).

- Layer 2 – Device Instance Layer:
- How device instances are created (via device_create) based on device types.
- Each instance then holds associations with one or more memory regions.

- Layer 3 – Memory Region Layer:
- Memory_region_list where each memory region is tied to a particular device instance.
- Properties such as base address, size, and access permissions.

- Auxiliary Components:
- Monitors are associated with memory regions; they watch for specific memory operations such as writes or writes of specific values.
- Actions are then attached to monitors. They are designed to execute callbacks, script commands, or cross-device operations when triggers occur.
- The Rule Engine component (or rule_engine module) ties monitoring and action execution together, regulating behavior based on defined rules.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Subgraphs for vertical layering

    subgraph "Startup Layer"
        INIT("phymuti_init() Initialization"):::initialization
    end

    subgraph "Device Type Layer"
        DM("Device Manager\n(device_type_register)"):::device
    end

    subgraph "Device Instance Layer"
        DI("Device Instance Creation\n(device_create)"):::instance
    end

    subgraph "Memory Region Layer"
        MM("Memory Manager\n(memory_region_create etc)"):::memory
    end

    subgraph "Monitoring & Action Layer"
        MON("Monitor Component\n(monitor_add_watchpoint)"):::monitor
        AM("Action Manager\n(action_create_callback)"):::action
    end

    subgraph "Rule Engine Layer"
        RE("Rule Engine\n(rule binding)"):::rule
    end

    %% Connections representing initialization and interactions
    INIT -->|"calls_device_type_register"| DM
    DM -->|"creates_via_device_create"| DI
    DI -->|"allocates_memory_region"| MM
    MM -->|"sets_watchpoint"| MON
    MON -->|"triggers_callback"| AM
    MM -->|"cross_device_trigger"| AM
    MON -->|"binds_condition"| RE
    AM -->|"binds_action"| RE

    %% Click Events for mapped components
    click INIT "https://github.com/lzy107/simuphy2/blob/main/include/phymuti.h"
    click INIT "https://github.com/lzy107/simuphy2/blob/main/src/phymuti.c"
    click DM "https://github.com/lzy107/simuphy2/blob/main/include/device_manager.h"
    click DM "https://github.com/lzy107/simuphy2/blob/main/src/device_manager.c"
    click MM "https://github.com/lzy107/simuphy2/blob/main/include/memory_manager.h"
    click MM "https://github.com/lzy107/simuphy2/blob/main/src/memory_manager.c"
    click MON "https://github.com/lzy107/simuphy2/blob/main/include/monitor.h"
    click MON "https://github.com/lzy107/simuphy2/blob/main/src/monitor.c"
    click AM "https://github.com/lzy107/simuphy2/blob/main/include/action_manager.h"
    click AM "https://github.com/lzy107/simuphy2/blob/main/src/action_manager.c"
    click RE "https://github.com/lzy107/simuphy2/blob/main/include/rule_engine.h"
    click RE "https://github.com/lzy107/simuphy2/blob/main/src/rule_engine.c"

    %% Styles
    classDef initialization fill:#f9c,stroke:#333,stroke-width:2px;
    classDef device fill:#bbf,stroke:#333,stroke-width:2px;
    classDef instance fill:#fda,stroke:#333,stroke-width:2px;
    classDef memory fill:#cfc,stroke:#333,stroke-width:2px;
    classDef monitor fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef action fill:#cff,stroke:#333,stroke-width:2px;
    classDef rule fill:#f99,stroke:#333,stroke-width:2px;
```
