# varshney-yash/credis architecture

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

- Interactive diagram: https://gitdiagram.com/varshney-yash/credis
- Repository: https://github.com/varshney-yash/credis

## Overview

##### Main Components
- Server / Runner Component (app/runner.cpp, app/runner.h):
This is likely the entry point that initializes the server, handles incoming connections (i.e., via telnet), and dispatches commands.
- Command Resolution / Parser (strings/resolve.cpp, strings/resolve.h):
This module is responsible for parsing and resolving the commands (GET, SET, DELETE) from incoming client requests.
- Configuration Management (conf/config.cpp, conf/config.h):
This part manages configuration settings, potentially controlling server settings, and possibly snapshotting intervals or other DB parameters.
- Data Storage & Persistence:
Although there isn’t an explicit “database” directory, the in-memory DB core is implied in the server’s operations, and the persistence mechanism involves snapshotting to a file (snapshot.txt).
- Testing Component (tests/tests.cpp):
This part of the tree is used for unit or integration testing that verifies the DB operations, command parsing, and possibly the snapshotting functionality.

##### Relationships and Interactions
- Clients (telnet users) connect to the Server/Runner which listens for incoming requests.
- The Server passes incoming commands to the Command Resolver, where strings are parsed and translated into DB operations.
- The in-memory data structure (not explicitly shown but implicit in the implementation) handles GET, SET, and DELETE operations.
- There is a Persistence Subsystem that periodically writes the current state of the in-memory DB to snapshot.txt (every minute, as noted in the README).
- The Configuration Module sets up initial parameters (such as port number, snapshot interval, etc.) for the server.
- Unit tests under the tests/ directory ensure that these interactions and operations work as expected.

##### Architectural Patterns and Design Principles
- Layered Architecture: Separate layers for networking, command processing, configuration, in-memory data store, and persistence.
- Modular Design: Each major functionality (server, configuration, command resolution, testing) is encapsulated in its own module.
- Persistence Pattern: The snapshotting mechanism for periodic persistence implies a scheduled task or background thread interaction with the in-memory store.

##### Relevant Technologies, Frameworks, or Libraries
- C++ Standard libraries for networking (possibly external libraries or BSD sockets for telnet connectivity).
- Multi-threading (if snapshotting is run in a separate thread).
- Build System: Makefile for building the project.
- Testing: The tests directory indicates unit tests possibly using a simple test framework.

##### Elements
- “Client (Telnet)” indicating the external users.
- “Server/Runner Module (app/runner)” to show the main server process.
- “Command Resolver (strings/resolve)” to represent the parsing and command dispatch.
- “Configuration Manager (conf/config)” ensuring all settings are loaded.
- “In-Memory Database Core” to represent the data handling (even if not a separate module, conceptually include it).
- “Testing Suite” as a separate component for quality assurance.
- From “Client” to “Server/Runner” (incoming requests).
- From “Server” to “Command Resolver” (command handling).
- From “Command Resolver” to “In-Memory Database Core” (executing operations).
- From “In-Memory Database Core” to “Persistence Component” (for snapshotting).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    client["Client (Telnet)"]:::network

    %% Server Components
    subgraph "Server Components"
        direction TB
        configManager["Configuration Manager"]:::config
        serverModule["Server/Runner Module"]:::server
        resolver["Command Resolver"]:::parser
        inMemDB["In-Memory Database Core"]:::db
    end

    %% Persistence and Testing
    persistence["Persistence Component"]:::snapshot
    testSuite["Testing Suite"]:::test

    %% Connections
    client -->|"sendsCommand"| serverModule
    configManager -->|"loads"| serverModule
    serverModule -->|"dispatches"| resolver
    resolver -->|"executesCommands"| inMemDB
    inMemDB -->|"periodicSnapshot"| persistence
    testSuite -.->|"validates"| serverModule
    testSuite -.->|"validates"| resolver
    testSuite -.->|"validates"| inMemDB

    %% Click Events
    click serverModule "https://github.com/varshney-yash/credis/blob/main/app/runner.cpp"
    click resolver "https://github.com/varshney-yash/credis/blob/main/strings/resolve.cpp"
    click configManager "https://github.com/varshney-yash/credis/blob/main/conf/config.cpp"
    click persistence "https://github.com/varshney-yash/credis/blob/main/snapshot.txt"
    click testSuite "https://github.com/varshney-yash/credis/blob/main/tests/tests.cpp"

    %% Styles
    classDef network fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef server fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef config fill:#FFECB3,stroke:#FFB300,stroke-width:2px;
    classDef parser fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef db fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
    classDef snapshot fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef test fill:#D1C4E9,stroke:#7B1FA2,stroke-width:2px;
```
