# karimov/lrucached architecture

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

- Interactive diagram: https://gitdiagram.com/karimov/lrucached
- Repository: https://github.com/karimov/lrucached

## Overview

##### Main Components

A. Core Components:
- LRU Cache Engine (from cache/cache.go)
- HTTP Server Layer (from server/server.go)
- Request Handlers (from server/handlers.go)

B. Data Structures:
- Cache Item Structure
- LRU Queue/List
- Key-Value Store

##### Component Relationships

**[Client Layer]**
- ↓ HTTP
**[HTTP Server Layer]**
- ↓
**[Request Handlers]**
- ↓
**[LRU Cache Engine]**
- ↓
**[In-Memory Storage]**

##### Detailed Component Specifications

A. HTTP Server Layer (Blue Rectangle):
- Incoming endpoints for:
- GET (retrieve)
- SET (store)
- REMOVE (delete)

B. LRU Cache Engine (Green Rectangle):
- Internal components:
- Capacity Management
- Eviction Mechanism
- Cache Invalidation

C. In-Memory Storage (Yellow Rectangle):
- Show:
- Key-Value Pairs
- LRU Queue/List

##### Additional Elements

- Item Expiration
- Cache Stats
- Cleanup Mechanism

##### Technical Details

Annotations for:
- Cache capacity limits
- Default expiration settings
- Eviction policy (LRU)

##### Specific Implementation Notes

Notes for:
- Memory management considerations
- Cache resizing mechanisms
- TTL handling

- Rectangles for main components
- Clear labels for all components

Remember to highlight the separation between the server layer and cache implementation, as these are clearly separated in the project structure (server/ and cache/ directories).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        C1[Client Requests]
    end

    subgraph "HTTP Server Layer"
        HS["HTTP Server"]:::server
        RH["Request Handlers"]:::handlers
    end

    subgraph "Cache Layer"
        CE["LRU Cache Engine"]:::cache
        subgraph "Cache Operations"
            CO1["Capacity Management"]
            CO2["Eviction Mechanism"]
            CO3["Cache Invalidation"]
        end
    end

    subgraph "Storage Layer"
        IMS[("In-Memory Store")]
        LRU["LRU Queue/List"]
    end

    subgraph "Planned Features"
        direction TB
        PF1["Item Expiration"]:::planned
        PF2["Cache Stats"]:::planned
        PF3["Cleanup Mechanism"]:::planned
    end

    C1 -->|HTTP Requests| HS
    HS --> RH
    RH -->|GET/SET/REMOVE| CE
    CE --> CO1
    CE --> CO2
    CE --> CO3
    CO1 --> IMS
    CO2 --> IMS
    CO3 --> IMS
    CE -.->|Future| PF1
    CE -.->|Future| PF2
    CE -.->|Future| PF3
    IMS --- LRU

    subgraph Legend
        L1[Implemented Features]
        L2[Planned Features]:::planned
        L3[Data Flow]
    end

    %% Click events for component mapping
    click CE "https://github.com/karimov/lrucached/blob/develop/cache/cache.go"
    click HS "https://github.com/karimov/lrucached/blob/develop/server/server.go"
    click RH "https://github.com/karimov/lrucached/blob/develop/server/handlers.go"

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef server fill:#b3e0ff,stroke:#333,stroke-width:2px
    classDef handlers fill:#99ccff,stroke:#333,stroke-width:2px
    classDef cache fill:#99ff99,stroke:#333,stroke-width:2px
    classDef planned fill:#f9f9f9,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
    classDef storage fill:#ffeb99,stroke:#333,stroke-width:2px
```
