# p4zaa/sessionhandler architecture

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

- Interactive diagram: https://gitdiagram.com/p4zaa/sessionhandler
- Repository: https://github.com/p4zaa/sessionhandler

## Overview

##### Project type and purpose
- This is a lightweight Python session‐management library (an open-source tool) providing an in-memory versioned key/value store with undo and custom hashing.
- There is no frontend or external service—just a single Python package (SessionHandler) plus example tests and a CLI import interface.

##### File structure
- Top level:
- setup.py, requirements.txt → packaging and dependencies
- SessionHandler/ → the core library
– SessionHandler.py → the Session class and internal logic
– test.py, test.ipynb → example usages/tests
- LICENSE, README.md → documentation
- No separate “backend” or “database” directories; persistence is in-memory.

##### README for additional insights
- Core features: set, get, undo, custom hash-func registry
- External dependencies: pandas, polars (optional, only when you register hash functions)

a. Main components
1. User Application
– User code that imports and calls Session API
2. Session API (Session class)
– Public methods: set(), get(), undo(), set_hash_func()
3. Version Store
– Internal data structure (dictionary of key → list of (hash, value) tuples)
4. Hash Function Registry
– Maps data type → hash function
5. External Dependencies (optional)
– pandas, polars modules when custom hash functions are provided

b. Relationships and interactions
- User Application → invokes Session.set/get/undo
- Session methods → consult Hash Function Registry to compute hash
- Session.set → if new hash, append to Version Store
- Session.get → return latest value from Version Store
- Session.undo → pop the latest version for a key in Version Store
- set_hash_func → updates the Hash Function Registry

c. Architectural patterns/design principles
- Single‐responsibility: Session class encapsulates API, version store, hash registry
- Dependency injection: users can inject custom hash functions
- In-memory store: no external database; optimized to avoid duplicates by hash comparison

d. Key technologies / libraries
- Core: Python 3.x
- Optional: pandas, polars for DataFrame hashing
- Packaging: setuptools (setup.py), requirements.txt

##### Details to capture
- That Version Store holds a list of versions per key (e.g., key → [v1, v2, …])
- That duplicate values (same hash) are not stored
- How undo pops the last version but preserves prior history
- Set_hash_func API as the mechanism for extensibility

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Applications"
        TestScript["User Application\n(test.py)"]:::external
        Notebook["User Application\n(Notebook test.ipynb)"]:::external
    end

    subgraph "Core Engine"
        Init["Package Initialization\n(__init__.py)"]:::core
        Session["Session API\n(Session class)"]:::core
        VersionStore["Version Store\n(in-memory key→versions)"]:::core
        HashRegistry["Hash Function Registry"]:::extension
    end

    subgraph "External Dependencies"
        Pandas["pandas"]:::external
        Polars["polars"]:::external
    end

    subgraph "Documentation & Packaging"
        Setup["setup.py"]:::docs
        Reqs["requirements.txt"]:::docs
        Readme["README.md"]:::docs
        License["LICENSE"]:::docs
    end

    TestScript -->|"imports calls"| Session
    Notebook -->|"imports calls"| Session
    Session -->|"compute hash"| HashRegistry
    Session -->|"store version"| VersionStore
    Session -->|"retrieve/undo"| VersionStore
    HashRegistry -->|"optional use"| Pandas
    HashRegistry -->|"optional use"| Polars

    click Init "https://github.com/p4zaa/sessionhandler/blob/main/SessionHandler/__init__.py"
    click Session "https://github.com/p4zaa/sessionhandler/blob/main/SessionHandler/SessionHandler.py"
    click VersionStore "https://github.com/p4zaa/sessionhandler/blob/main/SessionHandler/SessionHandler.py"
    click HashRegistry "https://github.com/p4zaa/sessionhandler/blob/main/SessionHandler/SessionHandler.py"
    click TestScript "https://github.com/p4zaa/sessionhandler/blob/main/SessionHandler/test.py"
    click Notebook "https://github.com/p4zaa/sessionhandler/blob/main/SessionHandler/test.ipynb"
    click Setup "https://github.com/p4zaa/sessionhandler/blob/main/setup.py"
    click Reqs "https://github.com/p4zaa/sessionhandler/blob/main/requirements.txt"
    click Readme "https://github.com/p4zaa/sessionhandler/blob/main/README.md"
    click License "https://github.com/p4zaa/sessionhandler/tree/main/LICENSE"

    classDef core fill:#ffe0b2,stroke:#e65100,color:#e65100;
    classDef extension fill:#d1c4e9,stroke:#512da8,color:#512da8;
    classDef external fill:#c8e6c9,stroke:#2e7d32,color:#2e7d32;
    classDef docs fill:#b3e5fc,stroke:#0277bd,color:#0277bd;
```
