# p0sxl/parammutex architecture

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

- Interactive diagram: https://gitdiagram.com/p0sxl/parammutex
- Repository: https://github.com/p0sxl/parammutex

## Overview

##### Main Components

a) Core Components:
- Mutex Manager (Main Class)
- Queue System
- Lock Management
- Parameter Handler

b) Key Interfaces:
- ILock Interface
- MutexItem Implementation
- Queue Implementation

**Client Application Layer**
- ↓
- API Layer
- ↓
**Core Implementation Layer**
- ↓
- Storage Layer

##### Specific Elements

a) Components:
- Queue system as a supporting component
- MutexItem as the atomic unit of lock management
- ILock interface

b) Interactions:
- Lock acquisition flow
- Demonstrate parameter handling
- Queue management
- Release mechanism

##### Top Level (Client Interface)
- It to the Mutex public API

##### Middle Layer (Core Implementation)
- ┌─────────────────────────────────────┐
- Mutex Manager            │
- ┌──────────┐        ┌──────────┐  │
- Parameter │        │  Lock    │  │
- Handler  │◄─────►│ Manager  │  │
- ┘        └──────────┘  │
- ┘

##### Bottom Layer (Implementation Details)
- ┌─────────────┐    ┌─────────────┐
- Queue     │    │ MutexItem   │
- Manager    │◄──►│  Handler    │
- ┘    └─────────────┘

##### Flow Representation

- Lock request flow
- Parameter validation path
- Queue management flow
- Lock release path

##### Additional Elements

- Lock states (acquired/released)
- Parameter binding
- Queue priority
- Error handling paths

##### Technical Details

Relationship between:
- src/lib/Mutex.ts (main implementation)
- src/lib/Queue.ts (queue management)
- src/lib/MutexItem.ts (lock items)
- src/lib/interface/ILock.ts (interface definition)

Remember to include a small example showing the lock acquisition and release flow with parameters, similar to the example in the README but in a visual format.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph CL["Client Application Layer"]
        Client["Client Application"]:::client
        Demo["Demo Implementation"]:::client
    end

    %% API Layer
    subgraph AL["API Layer"]
        API["Main Entry Point"]:::api
        ILock["ILock Interface"]:::interface
    end

    %% Core Implementation Layer
    subgraph Core["Core Implementation Layer"]
        MutexManager["Mutex Manager"]:::core
        ParamHandler["Parameter Handler"]:::core
        LockManager["Lock Manager"]:::core
        Queue["Queue System"]:::core
        MutexItem["MutexItem Implementation"]:::core
    end

    %% Storage Layer
    subgraph SL["Storage Layer"]
        CompiledMutex["Compiled Mutex"]:::compiled
        CompiledQueue["Compiled Queue"]:::compiled
        CompiledMutexItem["Compiled MutexItem"]:::compiled
        CompiledILock["Compiled ILock"]:::compiled
    end

    %% Relationships
    Client --> API
    Demo --> API
    API --> ILock
    API --> MutexManager
    MutexManager --> ParamHandler
    MutexManager --> LockManager
    LockManager --> Queue
    Queue --> MutexItem
    MutexManager --> CompiledMutex
    Queue --> CompiledQueue
    MutexItem --> CompiledMutexItem
    ILock --> CompiledILock

    %% Click Events
    click MutexManager "https://github.com/p0sxl/ParamMutex/blob/main/src/lib/Mutex.ts"
    click Queue "https://github.com/p0sxl/ParamMutex/blob/main/src/lib/Queue.ts"
    click MutexItem "https://github.com/p0sxl/ParamMutex/blob/main/src/lib/MutexItem.ts"
    click ILock "https://github.com/p0sxl/ParamMutex/blob/main/src/lib/interface/ILock.ts"
    click API "https://github.com/p0sxl/ParamMutex/blob/main/src/index.ts"
    click Demo "https://github.com/p0sxl/ParamMutex/blob/main/demo/demo.js"
    click CompiledMutex "https://github.com/p0sxl/ParamMutex/blob/main/dist/lib/Mutex.js"
    click CompiledQueue "https://github.com/p0sxl/ParamMutex/blob/main/dist/lib/Queue.js"
    click CompiledMutexItem "https://github.com/p0sxl/ParamMutex/blob/main/dist/lib/MutexItem.js"
    click CompiledILock "https://github.com/p0sxl/ParamMutex/blob/main/dist/lib/interface/ILock.js"

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:2px
    classDef api fill:#aaf,stroke:#333,stroke-width:2px
    classDef interface fill:#ff9,stroke:#333,stroke-width:2px
    classDef core fill:#9f9,stroke:#333,stroke-width:2px
    classDef compiled fill:#ddd,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Client Components"]:::client
        L2["API Components"]:::api
        L3["Interface Components"]:::interface
        L4["Core Components"]:::core
        L5["Compiled Components"]:::compiled
    end
```
