# dbaazzz/custom-hooks-plus architecture

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

- Interactive diagram: https://gitdiagram.com/dbaazzz/custom-hooks-plus
- Repository: https://github.com/dbaazzz/custom-hooks-plus

## Overview

##### Main Components
- API/Library Interface – This is the public contract that developers work with and includes the exported functions such as:
- createProxy – for monitoring and reacting to state changes.
- init – for initializing watchers based on a set of configurations.
- Various custom hook functions (onCustomLaunch, onCustomLoad, onCustomCreated, onCustomShow, onCustomMounted, onCustomReady).
- Core Engine – Found in the core directory (files like hooks.ts, init.ts, rewrite.ts, index.ts):
- It centralizes the logic for setting up the reactive hooks.
- Manages the internal flow of custom hook triggers, proxying state changes, and linking lifecycle events.
- Supporting Modules – These include:
- Utils (in utils/) – Helper methods.
- Types (in types/) – Type declarations that ensure type safety.
- Build & Configuration (e.g., rollup.config.mjs, vite.config.ts, tsconfig.json) – Manage bundling and build settings.
- Tests (in test/) – Validate functionality and ensure regression protection.
- Example Integration – The example directory demonstrates how to use the library (e.g., integrating with Vue components and Pinia store usage), which signifies typical usage and integration flows.

##### Relationships and Interactions
- The “API/Library Interface” acts as the entry point for users. Developers call functions like createProxy and init from their projects.
- These calls are routed into the “Core Engine,” where the logic on custom hook triggering, proxy management, and event rewriting is handled.
- The “Core Engine” interacts with state management (such as stores from Pinia, as seen in the example) and Vue/uniapp lifecycle events.
- The “Supporting Modules” (utils and types) provide auxiliary functionality (helper functions and types for ensuring correctness) and are used internally by the core engine.
- The “Tests” module validates that the core functionalities (hooks listening, state monitoring) work as expected.
- The “Build & Configuration” layer ensures that the library is bundled correctly, with tools like Rollup and Vite managing module compilation.
- The “Example” is used to simulate real-world usage, demonstrating how changes in global state (using createProxy) combined with lifecycle events (triggered custom hooks) interact with the library.

##### Architectural Patterns and Design Principles
- Modularity – Separation between core logic, utility functions, and type definitions makes the system easy to maintain and extend.
- Reactive Design – Using a proxy-based mechanism to watch for state changes and trigger hook events.
- Configurability – The use of an initialization function (init) to let developers specify what state or store changes should trigger which hooks.
- Integration with Existing Frameworks – Seamless incorporation with Vue3/uniapp lifecycles and store patterns (e.g., Pinia).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & Configuration Layer
    subgraph "Build & Configuration"
        BC1["rollup.config.mjs"]:::build
        BC2["vite.config.ts"]:::build
        BC3["tsconfig.json"]:::build
        BC4["tsconfig.types.json"]:::build
    end

    %% API/Library Interface Layer
    API_Interface["API/Library Interface (createProxy, init, custom hooks)"]:::api

    %% Core Engine Layer
    subgraph "Core Engine"
        CORE1["hooks.ts"]:::core
        CORE2["init.ts"]:::core
        CORE3["rewrite.ts"]:::core
    end

    %% Supporting Modules Layer
    subgraph "Supporting Modules"
        UTIL["Utils (utils/index.ts)"]:::support
        TYPE["Types (types/index.ts)"]:::support
    end

    %% Tests Layer
    TESTS["Tests (test/index.test.ts)"]:::test

    %% Example Integration Layer
    subgraph "Example Integration"
        EX1["example/index.vue"]:::example
        EX2["example/global.ts"]:::example
        EX3["example/stores/"]:::example
    end

    %% Connections between layers
    BC1 -->|"bundles"| API_Interface
    BC2 -->|"bundles"| API_Interface
    BC3 -->|"bundles"| API_Interface
    BC4 -->|"bundles"| API_Interface

    API_Interface -->|"calls"| CORE1
    API_Interface -->|"calls"| CORE2
    API_Interface -->|"calls"| CORE3

    CORE1 -->|"uses"| UTIL
    CORE1 -->|"uses"| TYPE
    CORE2 -->|"uses"| UTIL
    CORE2 -->|"uses"| TYPE
    CORE3 -->|"uses"| UTIL
    CORE3 -->|"uses"| TYPE

    CORE1 -->|"validatedBy"| TESTS
    CORE2 -->|"validatedBy"| TESTS
    CORE3 -->|"validatedBy"| TESTS

    EX1 -->|"integrates"| API_Interface
    EX2 -->|"integrates"| API_Interface
    EX3 -->|"integrates"| API_Interface

    %% Click Events for Component Mapping
    click API_Interface "https://github.com/dbaazzz/custom-hooks-plus/blob/main/core/index.ts"
    click CORE1 "https://github.com/dbaazzz/custom-hooks-plus/blob/main/core/hooks.ts"
    click CORE2 "https://github.com/dbaazzz/custom-hooks-plus/blob/main/core/init.ts"
    click CORE3 "https://github.com/dbaazzz/custom-hooks-plus/blob/main/core/rewrite.ts"
    click UTIL "https://github.com/dbaazzz/custom-hooks-plus/blob/main/utils/index.ts"
    click TYPE "https://github.com/dbaazzz/custom-hooks-plus/blob/main/types/index.ts"
    click BC1 "https://github.com/dbaazzz/custom-hooks-plus/blob/main/rollup.config.mjs"
    click BC2 "https://github.com/dbaazzz/custom-hooks-plus/blob/main/vite.config.ts"
    click BC3 "https://github.com/dbaazzz/custom-hooks-plus/blob/main/tsconfig.json"
    click BC4 "https://github.com/dbaazzz/custom-hooks-plus/blob/main/tsconfig.types.json"
    click TESTS "https://github.com/dbaazzz/custom-hooks-plus/blob/main/test/index.test.ts"
    click EX1 "https://github.com/dbaazzz/custom-hooks-plus/blob/main/example/index.vue"
    click EX2 "https://github.com/dbaazzz/custom-hooks-plus/blob/main/example/global.ts"
    click EX3 "https://github.com/dbaazzz/custom-hooks-plus/tree/main/example/stores/"

    %% Style Classes
    classDef api fill:#dff0d8,stroke:#3c763d,stroke-width:2px;
    classDef core fill:#d9edf7,stroke:#31708f,stroke-width:2px;
    classDef support fill:#fcf8e3,stroke:#8a6d3b,stroke-width:2px;
    classDef build fill:#f5f5f5,stroke:#999,stroke-width:2px;
    classDef test fill:#f2dede,stroke:#a94442,stroke-width:2px;
    classDef example fill:#d9f7be,stroke:#609c46,stroke-width:2px;
    
    class API_Interface api;
    class CORE1,CORE2,CORE3 core;
    class UTIL,TYPE support;
    class BC1,BC2,BC3,BC4 build;
    class TESTS test;
    class EX1,EX2,EX3 example;
```
