# soraiabarroso/my_redis_client architecture

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

- Interactive diagram: https://gitdiagram.com/soraiabarroso/my_redis_client
- Repository: https://github.com/soraiabarroso/my_redis_client

## Overview

##### Main Components
- CLI Front-End: This handles the two modes of operation – REPL (interactive) and Shell mode (single command execution). This is the user interface layer.
- Command Parser: Located in files like command_parser.hpp, this component interprets user input to build valid Redis commands.
- Redis Command Builder/Client: The client component (client.hpp and client.cpp) is responsible for establishing the TCP socket connection, sending the serialized commands to the Redis server, and handling the results.
- Redis Parser: With redis_parser.hpp and redis_parser.cpp, this part processes the responses from the Redis server, converting the raw RESP responses into a format that can be easily used or displayed.
- Configuration (if applicable): Look at the config_client.hpp to see if it sets up connection parameters or custom configurations needed to initialize the client correctly.
- Build & Configuration Support: Represent that the Makefile and project structure serve as the build and integration mechanism. Although not a runtime component, they provide context on how everything is assembled.

##### Relationships and Interactions
- The CLI front-end collects user input and passes it to the Command Parser.
- The Command Parser validates and transforms the command input into the appropriate protocol message.
- The Client component then uses this command to create and manage a TCP socket connection to the Redis server.
- After sending out the command, the response received by the Client is handed over to the Redis Parser to decode the RESP-serialized data.
- Processed responses are then sent back to the CLI front-end for display.
- Optionally, configuration settings (from the config component) influence how the client behaves (such as connecting to a specific Redis instance).

##### Architectural Patterns and Design Principles
- Separation of Concerns: Each component (CLI interface, command parsing, network communication, and response parsing) is separated into its own module.
- Layered Structure: Although it’s a simple application, visually separate the user interface layer from the network communication layer.
- Synchronous Request/Response Cycle: The system maintains a direct cycle from command input to command execution and response display.

##### Technologies and Libraries
- C++ Standard Libraries – for input/output operations, networking, and basic processing.
- Custom Parsing Implementations – as indicated by the command_parser and redis_parser files.
- TCP Socket programming – fundamental communication with the Redis server.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        CLI["CLI Front-End"]:::frontend
    end

    %% Processing Layer
    subgraph "Processing Layer"
        CmdParser["Command Parser"]:::processing
        RedisClient["Redis Client"]:::processing
        RedisParser["Redis Parser"]:::processing
        CmdParser -->|"buildsCommand"| RedisClient
        RedisClient -->|"receivesResponse"| RedisParser
    end

    %% Configuration & Build
    subgraph "Configuration & Build"
        Config["Configuration"]:::config
        Build["Build System / Makefile"]:::build
    end

    %% External Service
    RedisServer(["Redis Server"]):::external

    %% Data Flow
    CLI -->|"sendsInput"| CmdParser
    RedisClient -->|"sendsCommand"| RedisServer
    RedisParser -->|"outputsResponse"| CLI
    Config -->|"configures"| RedisClient

    %% Build System assembling components
    Build -->|"builds"| CLI
    Build -->|"builds"| CmdParser
    Build -->|"builds"| RedisClient
    Build -->|"builds"| RedisParser
    Build -->|"applies"| Config

    %% Click Events
    click CLI "https://github.com/soraiabarroso/my_redis_client/blob/main/src/my_redis_cli.cpp"
    click CmdParser "https://github.com/soraiabarroso/my_redis_client/blob/main/include/command_parser.hpp"
    click RedisClient "https://github.com/soraiabarroso/my_redis_client/blob/main/include/client.hpp"
    click RedisParser "https://github.com/soraiabarroso/my_redis_client/blob/main/include/redis_parser.hpp"
    click Config "https://github.com/soraiabarroso/my_redis_client/blob/main/include/config_client.hpp"
    click Build "https://github.com/soraiabarroso/my_redis_client/tree/main/Makefile"

    %% Styles
    classDef frontend fill:#a2d5f2,stroke:#0b3d91,stroke-width:2px;
    classDef processing fill:#f9d6ac,stroke:#d35400,stroke-width:2px;
    classDef config fill:#d5f5e3,stroke:#229954,stroke-width:2px;
    classDef build fill:#fad7a0,stroke:#e67e22,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
```
