# simonlast/node-persist architecture

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

- Interactive diagram: https://gitdiagram.com/simonlast/node-persist
- Repository: https://github.com/simonlast/node-persist

## Overview

##### Main Components

a) Core Components:
- Storage Manager (Main Interface)
- File System Interface
- Queue Manager (for write operations)
- TTL (Time-To-Live) Manager
- Data Parser/Serializer

b) External Interfaces:
- Node.js File System (fs)
- Client Application

**[Client Application Layer]**
- ↕
**[Node-Persist API Layer]**
- ↕
**[Internal Services Layer]**
- ↕
**[File System Layer]**

##### Component Details

a) Storage Manager (Rectangle, Blue):
- Entry point for all operations
- Shows connections to: getItem, setItem, updateItem, removeItem, clear methods

b) Queue Manager (Rectangle, Green):
- Handles write operations queue
- Shows connection to Storage Manager
- Indicates interval-based processing

c) TTL Manager (Rectangle, Yellow):
- Manages expiration of items
- Shows connection to Storage Manager
- Indicates cleanup interval process

d) File System Interface (Rectangle, Orange):
- Handles all file operations
- Shows SHA256 hashing for filenames
- Indicates JSON storage format

##### Technical Details to Note

Annotations for:
- Node.js 7.6+ requirement
- JSON document storage
- SHA256 hashing for filenames
- Write queue intervals
- TTL cleanup intervals

##### Implementation Notes

A notes section indicating:
- Not designed for large datasets
- All operations are asynchronous
- No RAM caching (requires external solution)
- File-system based persistence

##### The TTL management system

Remember to indicate that this is a lightweight, file-system-based storage solution, not a full database system, and highlight its primary use case for small to medium-sized datasets requiring persistence.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        APP[Client Application]
    end

    subgraph "Node-Persist API Layer"
        SM[Storage Manager]:::main
        LSI["localStorage-like Interface"]:::interface
        EX["Example Implementation"]:::example
    end

    subgraph "Internal Services Layer"
        QM[Queue Manager]:::service
        TTL[TTL Manager]:::service
        FSI[File System Interface]:::service
        DP[Data Parser/Serializer]:::service
    end

    subgraph "File System Layer"
        FS[Node.js File System]:::system
        PS[Persistent Storage]:::storage
    end

    %% Client Layer Connections
    APP --> SM
    APP --> LSI

    %% API Layer Connections
    SM --> QM
    SM --> TTL
    SM --> FSI
    LSI --> SM

    %% Internal Layer Connections
    QM -.-> FSI
    TTL -.-> FSI
    FSI --> DP
    DP --> FSI

    %% File System Layer Connections
    FSI --> FS
    FS --> PS

    %% Notes
    classDef main fill:#3498db,stroke:#2980b9,color:white
    classDef interface fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#e74c3c,stroke:#c0392b,color:white
    classDef system fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef storage fill:#f1c40f,stroke:#f39c12,color:black
    classDef example fill:#9b59b6,stroke:#8e44ad,color:white

    %% Click Events
    click SM "https://github.com/simonlast/node-persist/blob/master/src/node-persist.js"
    click LSI "https://github.com/simonlast/node-persist/blob/master/src/local-storage.js"
    click EX "https://github.com/simonlast/node-persist/blob/master/examples/counter/counter.js"

    %% Legend
    subgraph Legend
        L1[Main Component]:::main
        L2[Interface]:::interface
        L3[Service]:::service
        L4[System]:::system
        L5[Storage]:::storage
    end
```
