# ikanshgoyal/chorddht architecture

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

- Interactive diagram: https://gitdiagram.com/ikanshgoyal/chorddht
- Repository: https://github.com/ikanshgoyal/chorddht

## Overview

##### Project’s Main Components
- Application Entry Point: Highlight “App.java” as the starting point which bootstraps the application.
- Core DHT Implementation:
- Node: Manages individual node functions and the core logic of a network node.
- FingerTable: Represents the routing/finger table enabling efficient key lookups.
- ChordNetwork: Manages network operations such as node joins, leaves, and pointer updates.
- HashUtils: Implements SHA-1 hashing logic that is central to consistent hashing.
- User Interface:
- ChordUI: A Swing-based UI for visual interaction and command issuing.
- Supporting Infrastructure:
- Build/Configuration Files: The “build.gradle”, .gitignore, and Eclipse IDE-specific files.
- README: Provides comprehensive documentation and usage examples.

##### Relationships and Interactions
- A clear separation between the backend (core DHT logic) and the frontend (Swing-based UI).
- Flow from user commands (either via command-line through App.java or via ChordUI) to operations in ChordNetwork.
- Demonstrate that the “printstate” command pulls the network information from the Node instances and displays it via the UI or console.

##### Architectural Patterns and Design Principles
- Modular Design: Each class encapsulates a specific aspect of the DHT (e.g., routing, network management, UI), which should be clearly depicted.
- Decoupling: Highlight the separation between logic (e.g., Node, FingerTable) and its presentation (i.e., ChordUI) suggesting a loosely coupled design.
- Consistent Hashing: Detail the role of the HashUtils in the overall architecture indicating its importance in distributing keys across nodes.
- Dynamic Network Reconfiguration: Include notes on how nodes join or leave – with updates reflected in the FingerTable, successor, and predecessor pointers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    subgraph "Application Layer"
        APP["App.java"]:::core
    end

    %% Distributed Hash Table (Core)
    subgraph "Distributed Hash Table (Core)"
        CN["ChordNetwork"]:::core
        NODE["Node"]:::core
        FT["FingerTable"]:::core
        HU["HashUtils"]:::utility
    end

    %% User Interface Layer
    subgraph "User Interface Layer"
        UI["ChordUI"]:::ui
    end

    %% Connections from Application Entry Point
    APP -->|"initCmds"| UI
    APP -->|"initNetwork"| CN

    %% Connections from UI to Core
    UI -->|"userCmds"| CN

    %% Core DHT interactions
    CN -->|"join/leave update"| NODE
    CN -->|"updateFingerTable"| FT
    CN -->|"lookupKey (via)"| HU
    HU -->|"hashResult"| CN
    CN -->|"store/retrieve"| NODE

    %% Command execution feedback loop
    NODE -->|"printState"| UI

    %% Click Events
    click APP "https://github.com/ikanshgoyal/chorddht/blob/main/src/chord/App.java"
    click CN "https://github.com/ikanshgoyal/chorddht/blob/main/src/chord/ChordNetwork.java"
    click NODE "https://github.com/ikanshgoyal/chorddht/blob/main/src/chord/Node.java"
    click FT "https://github.com/ikanshgoyal/chorddht/blob/main/src/chord/FingerTable.java"
    click HU "https://github.com/ikanshgoyal/chorddht/blob/main/src/chord/HashUtils.java"
    click UI "https://github.com/ikanshgoyal/chorddht/blob/main/src/chord/ui/ChordUI.java"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef ui fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef utility fill:#FFA500,stroke:#000,stroke-width:1px;
```
