# javalsai/rs-ezcache architecture

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

- Interactive diagram: https://gitdiagram.com/javalsai/rs-ezcache
- Repository: https://github.com/javalsai/rs-ezcache

## Overview

Key Components to Include:

##### Core Library Components
- Basic Cache Traits (fallible/infallible variants)
- Generative Cache Traits

##### Storage Backends
- Memory Store
- File Store (under 'file-stores' feature)

##### Thread-Safe Layer
- How it wraps around both core traits and storage implementations

##### Feature Flags
- std (default)
- thread-safe (default)
- file-stores (default)
- nightly (optional)

##### Core Layer (Bottom)
**┌─────────────────────────────────────┐**
- Core Traits              │
- ┌──────────┐        ┌──────────┐  │
- Cache   │        │Generative│  │
- Traits  │───────▶│  Cache   │  │
- ┘        └──────────┘  │
- ┘

##### Storage Layer (Middle)
**┌─────────────────────────────────────┐**
- Storage Implementations      │
- ┌──────────┐        ┌──────────┐  │
- Memory   │        │  File    │  │
- Store   │        │  Store   │  │
- ┘        └──────────┘  │
- ┘

**┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐**
- Thread-Safe Variants
- ┌──────────┐        ┌──────────┐  │
- TS Memory │        │TS File   │
- Store   │        │  Store   │  │
- ┘        └──────────┘
- ┘

Important Elements to Include:

- From storage implementations to core traits
- From thread-safe variants to their base implementations

##### Data Flow
- Cache miss/hit paths

##### Interface Points
- Public API entry points
- Where custom implementations can plug in

Recommendations:

## Diagram (Mermaid)

```mermaid
graph TB
    %% Core Layer
    subgraph Core
        CoreTraits["Core Cache Traits"]
        GenTraits["Generative Cache Traits"]
        CoreTraits --> GenTraits
    end

    %% Storage Layer
    subgraph Storage
        StoreImpl["Storage Implementations"]:::store
        MemStore["Memory Store"]:::store
        FileStore["File Store"]:::store
        
        StoreImpl --> MemStore
        StoreImpl --> FileStore
    end

    %% Thread-Safe Layer
    subgraph ThreadSafe
        TSWrapper["Thread-Safe Layer"]:::threadsafe
        TSMemStore["TS Memory Store"]:::threadsafe
        TSFileStore["TS File Store"]:::threadsafe
        TSGenCache["TS Generative Cache"]:::threadsafe
        
        TSWrapper --> TSMemStore
        TSWrapper --> TSFileStore
        TSWrapper --> TSGenCache
    end

    %% Feature Flags
    subgraph Features
        direction TB
        DefaultFeatures["Default Features"]:::default
        OptionalFeatures["Optional Features"]:::optional
        
        DefaultFeatures --> |std|Std:::default
        DefaultFeatures --> |thread-safe|ThreadSafeF:::default
        DefaultFeatures --> |file-stores|FileStoresF:::default
        OptionalFeatures --> |nightly|Nightly:::optional
    end

    %% Relationships
    MemStore --> CoreTraits
    FileStore --> CoreTraits
    TSMemStore --> MemStore
    TSFileStore --> FileStore
    TSGenCache --> GenTraits

    %% Examples
    SingleThread["Single-threaded Example"]:::example
    MultiThread["Multi-threaded Example"]:::example
    
    SingleThread -.-> MemStore
    MultiThread -.-> TSMemStore

    %% Styling
    classDef default fill:#a8d5ba
    classDef optional fill:#f9c6c6
    classDef store fill:#aec6cf
    classDef threadsafe fill:#b39eb5,stroke-dasharray: 5 5
    classDef example fill:#ffe5b4

    %% Click Events
    click CoreTraits "https://github.com/javalsai/rs-ezcache/blob/master/src/lib.rs"
    click GenTraits "https://github.com/javalsai/rs-ezcache/blob/master/src/generative.rs"
    click StoreImpl "https://github.com/javalsai/rs-ezcache/blob/master/src/stores/mod.rs"
    click FileStore "https://github.com/javalsai/rs-ezcache/blob/master/src/stores/file_stores.rs"
    click TSWrapper "https://github.com/javalsai/rs-ezcache/blob/master/src/thread_safe/mod.rs"
    click TSGenCache "https://github.com/javalsai/rs-ezcache/blob/master/src/thread_safe/generative.rs"
    click SingleThread "https://github.com/javalsai/rs-ezcache/blob/master/examples/http.rs"
    click MultiThread "https://github.com/javalsai/rs-ezcache/blob/master/examples/http-multithread.rs"

    %% Legend
    subgraph Legend
        L1["Default Features"]:::default
        L2["Optional Features"]:::optional
        L3["Storage Components"]:::store
        L4["Thread-Safe Components"]:::threadsafe
        L5["Examples"]:::example
    end
```
