# xam74er1/kadmelia architecture

> Architecture diagram of the GitHub repository xam74er1/kadmelia, 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/xam74er1/kadmelia
- Repository: https://github.com/xam74er1/kadmelia

## Overview

##### Key Components
- Peer Node: This is at the heart of the system. Each node is responsible for joining the network, performing lookups, and handling file transfers. Label it clearly with sub-components such as:
- Command-Line Interface (CLI): Handles arguments like -p, -i, -q, -m, and -s.
- Network Communication Module: Responsible for both TCP and UDP communication (evident in utilitaires/TCP.c and UDP.c, and tests in Test/peerUDP.c, etc.).
- File Transfer Module: Manage sending and receiving files (see Test/filetransfertClient.c, Test/filetransfertServer.c, gestion/envois_fichier.c, and package/SendFileTCP.c).
- DHT/Routing Module: Implements core Kademlia functions such as node lookup, finding values, and pinging neighbors (the package directory contains files like find_node.c, find_value.c, node.c, ping.c, and related tests like kademiliaTest.c).
- Storage/Database Module: Uses SQLite (see lib/sqlite3.c/h) to store metadata about downloaded files and network state.
- Cryptography & Security Module: Integrates OpenSSL (contents in lib/openssl) which is used for encryption/decryption and secure communications.

##### Network Layer & External Interactions
- How nodes send control messages (for network joins and lookups) and data messages (file contents) across the network.
- Input mechanism of command options (from the CLI) that trigger interactions with the networking layers.

##### Architectural Patterns & Design Principles
- Layered Approach: Consider grouping the lower-level libraries (like OpenSSL and SQLite) as underlying service layers supporting higher-level application logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User("User Commands"):::user

    subgraph "Peer Node"
        Core("Peer Node (Core Application)"):::core
        CLI("Command-Line Interface"):::cli
        DHT("DHT/Routing Module"):::dht
        FileTrans("File Transfer Module"):::file
        NetComm("Network Communication Module (TCP/UDP)"):::net
        Storage("Storage/Database Module (SQLite)"):::db
        Security("Cryptography & Security Module (OpenSSL)"):::sec
    end

    subgraph "Other Peer Node"
        Remote("Peer Node"):::peer
    end

    User -->|"triggers"| CLI
    Core -->|"initializes"| CLI
    CLI -->|"calls_DHT"| DHT
    CLI -->|"calls_FileTransfer"| FileTrans
    CLI -->|"calls_NetComm"| NetComm
    DHT -->|"sends_lookup"| NetComm
    FileTrans -->|"sends_file_data"| NetComm
    NetComm -->|"secures"| Security
    DHT -->|"updates_metadata"| Storage
    FileTrans -->|"logs_data"| Storage
    NetComm <-->|"TCP/UDP"| Remote

    classDef user fill:#f9c,stroke:#333,stroke-width:2px;
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef cli fill:#cfc,stroke:#333,stroke-width:2px;
    classDef net fill:#fcf,stroke:#333,stroke-width:2px;
    classDef file fill:#cff,stroke:#333,stroke-width:2px;
    classDef dht fill:#ff9,stroke:#333,stroke-width:2px;
    classDef db fill:#9ff,stroke:#333,stroke-width:2px;
    classDef sec fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef peer fill:#d9d,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mappings
    click Core "https://github.com/xam74er1/kadmelia/blob/master/Main.c"
    click CLI "https://github.com/xam74er1/kadmelia/blob/master/Main.c"
    click NetComm "https://github.com/xam74er1/kadmelia/blob/master/utilitaires/TCP.c"
    click NetComm "https://github.com/xam74er1/kadmelia/blob/master/utilitaires/UDP.c"
    click NetComm "https://github.com/xam74er1/kadmelia/blob/master/Test/peerUDP.c"
    click FileTrans "https://github.com/xam74er1/kadmelia/blob/master/gestion/envois_fichier.c"
    click FileTrans "https://github.com/xam74er1/kadmelia/blob/master/Test/filetransfertClient.c"
    click FileTrans "https://github.com/xam74er1/kadmelia/blob/master/Test/filetransfertServer.c"
    click FileTrans "https://github.com/xam74er1/kadmelia/blob/master/package/SendFileTCP.c"
    click DHT "https://github.com/xam74er1/kadmelia/blob/master/package/find_node.c"
    click DHT "https://github.com/xam74er1/kadmelia/blob/master/package/find_value.c"
    click DHT "https://github.com/xam74er1/kadmelia/blob/master/package/node.c"
    click DHT "https://github.com/xam74er1/kadmelia/blob/master/package/ping.c"
    click DHT "https://github.com/xam74er1/kadmelia/blob/master/Test/kademiliaTest.c"
    click Storage "https://github.com/xam74er1/kadmelia/blob/master/lib/sqlite3.c"
    click Storage "https://github.com/xam74er1/kadmelia/blob/master/lib/sqlite3.h"
    click Storage "https://github.com/xam74er1/kadmelia/blob/master/package/bdd.c"
    click Security "https://github.com/xam74er1/kadmelia/tree/master/lib/openssl"
```
