# jgrecu/redis-clone architecture

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

- Interactive diagram: https://gitdiagram.com/jgrecu/redis-clone
- Repository: https://github.com/jgrecu/redis-clone

## Overview

##### Main Components

a) Client Interface Layer
- TCP Server (from pkg/server/server.go)
- RESP Protocol Handler (from pkg/resp/protocol.go)

b) Command Processing Layer
- Command Handler (from pkg/server/command.go)

c) Storage Layer
- In-memory Storage (from pkg/storage/persistence.go)
- RDB File Parser (from pkg/rdb/parser.go)
- Persistence Manager (from pkg/rdb/persistence.go)

d) Configuration Management
- Config Handler (from pkg/config/config.go)

**[Client Applications]**
- ↓
**[TCP Server Layer]**
- ↓
**[RESP Protocol Handler]**
- ↓
**[Command Processor]**
- ↙         ↘
**[Storage]    [RDB Handler]**

##### Detailed Component Relationships

a) Client Interface Layer:
- RESP protocol encoding/decoding flow

b) Command Processing:
- Command flow from protocol handler to command processor
- Branching between storage operations and RDB operations

c) Storage Layer:
- RDB file interaction with persistence manager

##### Additional Elements

- Version or build information
- Notes about key interfaces between components

##### Technical Details to Highlight

- TCP server implementation
- RESP (Redis Serialization Protocol) handling
- In-memory data structure storage
- RDB file parsing and persistence
- Command processing pipeline

##### Implementation-Specific Notes

- Separation between the cmd/ and pkg/ directories
- Test coverage presence with small indicators near tested components
- Entry point (cmd/main.go)

Remember to:
- Use consistent spacing and alignment
- Clear labels for all components
- Brief descriptions for key interactions
- Both synchronous and asynchronous operations where applicable
- Error handling flows

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    client[Client Applications]
    
    %% Server Layer
    subgraph Server
        tcp["TCP Server"]:::network
        resp["RESP Protocol Handler"]:::network
    end
    
    %% Processing Layer
    subgraph Processing
        cmd["Command Handler"]:::processing
        config["Configuration Management"]:::config
    end
    
    %% Storage Layer
    subgraph Storage
        store["In-memory Storage"]:::storage
        rdb_parser["RDB File Parser"]:::storage
        persist["Persistence Manager"]:::storage
    end
    
    %% Main Entry Point
    entry["Main Entry Point"]:::entry
    
    %% Relationships
    client --> tcp
    tcp --> resp
    resp --> cmd
    cmd --> store
    cmd --> rdb_parser
    rdb_parser --> persist
    persist --> store
    config --> tcp
    config --> store
    entry --> tcp
    
    %% Click Events
    click tcp "https://github.com/jgrecu/redis-clone/blob/main/pkg/server/server.go"
    click resp "https://github.com/jgrecu/redis-clone/blob/main/pkg/resp/protocol.go"
    click cmd "https://github.com/jgrecu/redis-clone/blob/main/pkg/server/command.go"
    click store "https://github.com/jgrecu/redis-clone/blob/main/pkg/storage/persistence.go"
    click rdb_parser "https://github.com/jgrecu/redis-clone/blob/main/pkg/rdb/parser.go"
    click persist "https://github.com/jgrecu/redis-clone/blob/main/pkg/rdb/persistence.go"
    click config "https://github.com/jgrecu/redis-clone/blob/main/pkg/config/config.go"
    click entry "https://github.com/jgrecu/redis-clone/blob/main/cmd/main.go"
    
    %% Styles
    classDef network fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef processing fill:#90EE90,stroke:#333,stroke-width:2px
    classDef storage fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef config fill:#E6E6E6,stroke:#333,stroke-width:2px
    classDef entry fill:#FFC0CB,stroke:#333,stroke-width:2px
    
    %% Legend
    subgraph Legend
        n1["Network Component"]:::network
        p1["Processing Component"]:::processing
        s1["Storage Component"]:::storage
        c1["Configuration Component"]:::config
        e1["Entry Point"]:::entry
    end
```
