# abbychau/gtsdb architecture

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

- Interactive diagram: https://gitdiagram.com/abbychau/gtsdb
- Repository: https://github.com/abbychau/gtsdb

## Overview

##### External Interface Layer
- HTTP Server (port 5556)
- TCP Server

##### Handler Layer
- HTTP Handler
- TCP Handler
- Common Handler Logic

##### Storage Layer
- Write Ahead Log (WAL)
- Index Storage

Specific Design Elements:

##### Component Grouping
- Interface components (blue)
- Processing components (green)
- Storage components (orange)
- Concurrent utilities (purple)

**[Client Applications]**
- ↓
**[HTTP Server] [TCP Server]**
- ↓         ↓
**[Handler Layer (HTTP/TCP/Common)]**
- ↓
**[Core Processing]**
**┌─────────────────────────────┐**
- [Buffer System]  [Fanout]   │
- [Concurrent Map] [LRU]      │
- [Ring Buffer]   [Set]      │
- ┘
- ↓
**[Storage Layer]**
**[WAL Files] ←→ [Indexes]**

##### Scaling aspects
- Concurrent operation handling
- Buffer management
- File handle LRU mechanism

##### Metrics from the README
- Performance benchmarks
- Operation latencies
- Memory allocations

Level of Detail:
- Keep high-level components visible at first glance
- Use expandable/collapsible sections for detailed views
- Configuration parameters
- Interaction patterns between components

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef interface fill:#2374ab,color:white
    classDef handler fill:#48a9a6,color:white
    classDef buffer fill:#4ea5d9,color:white
    classDef concurrent fill:#9c528b,color:white
    classDef fanout fill:#7c98b3,color:white
    classDef storage fill:#e85d04,color:white
    classDef config fill:#606c38,color:white
    classDef docs fill:#bc6c25,color:white

    %% Client Layer
    Client["Client Applications"]

    %% Interface Layer
    subgraph Interfaces
        HTTP["HTTP Server (5556)"]
        TCP["TCP Server"]
    end

    %% Handler Layer
    subgraph Handlers
        HTTPHandler["HTTP Handler"]
        TCPHandler["TCP Handler"]
        CommonHandler["Common Handler"]
    end

    %% Core Components
    subgraph CoreComponents
        subgraph BufferSystem
            ExtBuffer["External Buffer"]
            IntBuffer["Internal Buffer"]
            StateManagement["State Management"]
            RingBuffer["Ring Buffer"]
        end

        subgraph ConcurrentOps
            LRUCache["LRU Cache"]
            ConcMap["Concurrent Map"]
            ConcSet["Concurrent Set"]
        end

        subgraph FanoutSystem
            SubMgmt["Subscription Management"]
            DataBroadcast["Data Broadcasting"]
        end
    end

    %% Storage Layer
    subgraph Storage
        WAL["Write Ahead Log"]
        IndexStorage["Index Storage"]
    end

    %% Configuration and Documentation
    Config["Configuration"]
    APIDoc["API Documentation"]
    Models["Data Models"]

    %% Connections
    Client --> HTTP & TCP
    HTTP --> HTTPHandler
    TCP --> TCPHandler
    HTTPHandler & TCPHandler --> CommonHandler
    CommonHandler --> ExtBuffer
    ExtBuffer --> IntBuffer
    IntBuffer --> StateManagement
    StateManagement --> RingBuffer
    RingBuffer --> WAL
    WAL <--> IndexStorage
    CommonHandler --> SubMgmt
    SubMgmt --> DataBroadcast
    CommonHandler --> ConcMap & ConcSet & LRUCache

    %% Style Applications
    class HTTP,TCP interface
    class HTTPHandler,TCPHandler,CommonHandler handler
    class ExtBuffer,IntBuffer,StateManagement,RingBuffer buffer
    class LRUCache,ConcMap,ConcSet concurrent
    class SubMgmt,DataBroadcast fanout
    class WAL,IndexStorage storage
    class Config,APIDoc docs

    %% Click Events
    click HTTP "https://github.com/abbychau/gtsdb/blob/main/handlers/httpHandler.go"
    click TCP "https://github.com/abbychau/gtsdb/blob/main/handlers/tcpHandler.go"
    click CommonHandler "https://github.com/abbychau/gtsdb/blob/main/handlers/common.go"
    click ExtBuffer "https://github.com/abbychau/gtsdb/blob/main/buffer/external.go"
    click IntBuffer "https://github.com/abbychau/gtsdb/blob/main/buffer/internal.go"
    click StateManagement "https://github.com/abbychau/gtsdb/blob/main/buffer/states.go"
    click LRUCache "https://github.com/abbychau/gtsdb/blob/main/concurrent/lru.go"
    click ConcMap "https://github.com/abbychau/gtsdb/blob/main/concurrent/map.go"
    click ConcSet "https://github.com/abbychau/gtsdb/blob/main/concurrent/set.go"
    click SubMgmt "https://github.com/abbychau/gtsdb/blob/main/fanout/fanout.go"
    click RingBuffer "https://github.com/abbychau/gtsdb/blob/main/synchronous/ringbuffer.go"
    click Models "https://github.com/abbychau/gtsdb/blob/main/models/models.go"
    click Config "https://github.com/abbychau/gtsdb/blob/main/gtsdb.ini"
    click APIDoc "https://github.com/abbychau/gtsdb/blob/main/docs/api.http"
```
