# dbfromzero/dbf0java architecture

> Architecture diagram of the GitHub repository dbfromzero/dbf0java, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dbfromzero/dbf0java
- Repository: https://github.com/dbfromzero/dbf0java

## Overview

##### Main Components

a) Storage Engines Layer:
- Memory Key-Value Store
- Disk Key-Value Store with multiple implementations:
- LSM Tree (Log-Structured Merge Tree)
- B-Tree
- Read-only Storage
- Read-Write Storage

b) Core Components:
- I/O Operations Layer
- Serialization Framework
- Document Storage System
- Write-Ahead Logging (WAL)
- Background Job Coordinator

c) Client/Server Architecture:
- Socket Server Implementation
- Base Client/Server Components
- Connection Management

##### Architectural Relationships

**┌─ Client Layer ─────────────────────────┐**
- BaseClient, SleepingClient             │
- ┬────────────────────┘

**┌─ Server Layer ───▼────────────────────┐**
- Socket Server, Connection Management   │
- ┬────────────────────┘

**┌─ Storage Layer ──▼────────────────────┐**
- Memory Store    ├─ Disk Store        │
- HashMap-based   │ ├─ LSM Tree        │
- B-Tree          │
- Read-Only       │
- Read-Write      │
- ┬────────────────────┘

**┌─ Core Services ──▼────────────────────┐**
- Write-Ahead Log │ ├─ Serialization   │
- I/O Operations  │ ├─ Background Jobs │
- ┴────────────────────┘

##### Important Details to Highlight

a) Storage Engine Specifics:
- LSM Tree components (MemTable, SSTables)
- B-Tree structure
- Read/write paths
- Vacuum and maintenance processes

b) Data Flow:
- Client request flow
- Write path with WAL
- Read path optimization
- Background merge operations

##### Additional Elements

- Benchmark components
- Document serialization framework
- Multi-value vs. single-value implementations
- Background job coordination

##### Implementation Notes

- Callouts for critical components like the WriteAheadLog

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef client fill:#6495ED,stroke:#333,stroke-width:2px
    classDef server fill:#4169E1,stroke:#333,stroke-width:2px
    classDef storage fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#FFD700,stroke:#333,stroke-width:2px
    classDef critical fill:#FF6347,stroke:#333,stroke-width:2px
    classDef background fill:#DDA0DD,stroke:#333,stroke-width:2px

    %% Client Layer
    subgraph ClientLayer
        BaseClient["Base Client"]
        SleepingClient["Sleeping Client"]
    end

    %% Server Layer
    subgraph ServerLayer
        SocketServer["Socket Server"]
        ConnMgmt["Connection Management"]
    end

    %% Storage Layer
    subgraph StorageLayer
        MemStore["Memory Key-Value Store"]
        
        subgraph DiskStore["Disk Storage"]
            LSMTree["LSM Tree Storage"]
            BTree["B-Tree Storage"]
            ReadOnly["Read-only Storage"]
            ReadWrite["Read-write Storage"]
        end
    end

    %% Core Services Layer
    subgraph CoreServices
        WAL["Write-Ahead Log"]
        IOOps["I/O Operations"]
        Serial["Serialization Framework"]
        DocStorage["Document Storage"]
        BGJobs["Background Job Coordinator"]
    end

    %% Relationships
    BaseClient --> SocketServer
    SleepingClient --> SocketServer
    SocketServer --> ConnMgmt
    ConnMgmt --> MemStore
    ConnMgmt --> DiskStore
    
    LSMTree --> WAL
    BTree --> WAL
    ReadWrite --> WAL
    
    WAL --> IOOps
    LSMTree --> BGJobs
    BTree --> BGJobs
    
    MemStore --> DocStorage
    DiskStore --> DocStorage
    DocStorage --> Serial

    %% Click Events
    click MemStore "https://github.com/dbfromzero/dbf0java/tree/master/src/main/java/dbf0/mem_key_value/"
    click LSMTree "https://github.com/dbfromzero/dbf0java/tree/master/src/main/java/dbf0/disk_key_value/readwrite/lsmtree/"
    click BTree "https://github.com/dbfromzero/dbf0java/tree/master/src/main/java/dbf0/disk_key_value/readwrite/btree/"
    click ReadOnly "https://github.com/dbfromzero/dbf0java/tree/master/src/main/java/dbf0/disk_key_value/readonly/"
    click ReadWrite "https://github.com/dbfromzero/dbf0java/tree/master/src/main/java/dbf0/disk_key_value/readwrite/"
    click IOOps "https://github.com/dbfromzero/dbf0java/tree/master/src/main/java/dbf0/common/io/"
    click Serial "https://github.com/dbfromzero/dbf0java/tree/master/src/main/java/dbf0/document/serialization/"
    click DocStorage "https://github.com/dbfromzero/dbf0java/tree/master/src/main/java/dbf0/document/"
    click WAL "https://github.com/dbfromzero/dbf0java/tree/master/src/main/java/dbf0/disk_key_value/readwrite/log/"
    click BGJobs "https://github.com/dbfromzero/dbf0java/blob/master/src/main/java/dbf0/common/FixedSizeBackgroundJobCoordinator.java"
    click SocketServer "https://github.com/dbfromzero/dbf0java/tree/master/src/main/java/dbf0/socketer_server/"
    click BaseClient "https://github.com/dbfromzero/dbf0java/tree/master/src/main/java/dbf0/base/"

    %% Styling
    class BaseClient,SleepingClient client
    class SocketServer,ConnMgmt server
    class MemStore,LSMTree,BTree,ReadOnly,ReadWrite storage
    class IOOps,Serial,DocStorage core
    class WAL critical
    class BGJobs background
```
