# mylonasc/pygraphdb architecture

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

- Interactive diagram: https://gitdiagram.com/mylonasc/pygraphdb
- Repository: https://github.com/mylonasc/pygraphdb

## Overview

##### Main components
- Data Storage Layer: In src/kvstores.py you have implementations of key-value store solutions (for example, LMDBStore as shown in the example). This component is responsible for persisting graph components to disk or other storage.
- Serialization Component: The module in src/serializers.py handles (de)serialization of data objects, thereby bridging the gap between Python objects and stored binary formats.
- Domain Entities: Although not separate files, the Node and Edge classes (presumably defined in src/graphdb.py) are essential parts of the domain model.
- Client/Application Layer: This is illustrated by the example usage in the README and further explored in the notebooks and test.py, which show how external users interact with the GraphDB.

##### Relationships and interactions
- The Client/Application Layer (including notebooks and test scripts) interacts directly with the GraphDB Core.
- GraphDB Core relies on two key services – the Key-Value Store and the Serializer:
- When a node or edge is to be stored, GraphDB will use the Serializer to convert it into a storable format, then pass it to the KV Store for persistence.
- On retrieval, the reverse happens; the stored data is fetched via the KV Store and deserialized back into GraphDB entities.
- From the Client/Application Layer to the GraphDB Core to indicate API calls (such as put_node, get_edge, etc.).
- From the GraphDB Core to the KV Store and Serializer to show how data is processed and persisted.

##### Architectural patterns and design principles
- Separation of Concerns: The clear separation between the core graph logic, persistence, and serialization allows for flexibility and easier maintenance.
- Inversion of Control/Dependency Injection: GraphDB is instantiated with a store and a serializer, making it extensible and allowing different storage or serialization mechanisms.
- Modular Design: Each module (graph, store, serializer) acts independently, facilitating testing (as shown by test.py) and future extensions.

##### Relevant technologies
- Pure Python for implementation.
- LMDBStore is specifically noted, so if LMDB or similar libraries are being used, you may indicate that under the storage component.
- The use of Pickle for serialization (via PickleSerializer) is part of the serialization layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client/Application Layer"
        C1["README.md"]:::client
        C2["Notebooks"]:::client
        C3["Test Script"]:::client
    end

    core["GraphDB Core"]:::core
    entities["Domain Entities (Node & Edge)"]:::entity

    subgraph "Supporting Services"
        store["KV Store (LMDBStore)"]:::store
        serializer["Serializer (PickleSerializer)"]:::serializer
    end

    C1 -->|"API_call"| core
    C2 -->|"API_call"| core
    C3 -->|"API_call"| core

    core -->|"serialize"| serializer
    serializer -->|"deserialize"| core

    core -->|"store"| store
    store -->|"retrieve"| core

    core -->|"comprises"| entities

    click core "https://github.com/mylonasc/pygraphdb/blob/main/src/graphdb.py"
    click store "https://github.com/mylonasc/pygraphdb/blob/main/src/kvstores.py"
    click serializer "https://github.com/mylonasc/pygraphdb/blob/main/src/serializers.py"
    click entities "https://github.com/mylonasc/pygraphdb/blob/main/src/graphdb.py"
    click C1 "https://github.com/mylonasc/pygraphdb/blob/main/README.md"
    click C2 "https://github.com/mylonasc/pygraphdb/tree/main/notebooks/"
    click C3 "https://github.com/mylonasc/pygraphdb/blob/main/test.py"

    classDef client fill:#ffc0cb,stroke:#333,stroke-width:2px;
    classDef core fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef store fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef serializer fill:#ffff99,stroke:#333,stroke-width:2px;
    classDef entity fill:#d3d3d3,stroke:#333,stroke-width:2px;
```
