# dantee-e/cleytocoin architecture

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

- Interactive diagram: https://gitdiagram.com/dantee-e/cleytocoin
- Repository: https://github.com/dantee-e/cleytocoin

## Overview

##### Project type and purpose
- CleytoCoin is a Rust-based cryptocurrency node project. It provides three command-line binaries:
- CleytoCoin (the main node)
- CleytoCoin-wallet (wallet generation and transactions)
- CleytoCoin-miner (mining operations)
- It implements a Proof of Work consensus, peer-to-peer transaction broadcasting, block creation, and key-pair based wallets.

##### File structure
- Cargo.toml / Cargo.lock: Rust package configuration & dependencies.
- src/lib.rs: core library exposing chain and wallet functionality.
- src/chain/: domain module containing:
- block.rs – block data structure, header, proof fields
- transaction.rs – transaction structure and serialization
- wallet.rs – key generation and address derivation
- utils.rs – hashing, serialization helpers
- src/chain.rs: likely re-exports or top-level glue for chain module.
- src/TODO.txt: development notes.
- tests/: integration/unit tests covering block creation, chain growth, transaction signing, verification.

##### README for additional insights
- Describes CLI usage: start node, generate wallet, send transaction, start miner, stop node.
- Emphasizes PoW, P2P, Rust performance.

a. Main components:
1. CLI Interface Layer
– CleytoCoin (node)
– CleytoCoin-wallet (wallet commands)
– CleytoCoin-miner (mining commands)
2. Core Library Layer (src/lib.rs + src/chain)
– Chain Manager (chain.rs)
– Block struct & validation (block.rs)
– Transaction struct & mempool (transaction.rs)
– Wallet/keypair manager (wallet.rs)
– Utilities (hashing, serialization) (utils.rs)
3. Storage Layer
– On-disk blockchain database/files (e.g., flat files in target/release or custom path)
4. Network Layer
– P2P peer connections for broadcasting blocks & transactions
5. Consensus Engine
– PoW algorithm (nonce search loop inside miner)
6. External Interfaces
– User (CLI)
– Other peer nodes

b. Relationships & data flows
1. User issues CLI command → CLI binary
2. CLI binary calls Core Library API
3. Core Library updates Mempool or initiates mining:
– Transaction path: wallet → transaction struct → sign → mempool → network broadcast
– Mining path: consensus engine → block proposal → PoW → block mined → append to chain → persist to storage → network broadcast
4. Network Layer receives incoming blocks/transactions → Core Library for validation → update local chain/mempool → persist as needed

c. Architectural patterns & design principles
- Layered architecture (CLI → core library → storage/network).
- Modular domain components (chain, transaction, wallet, utils).
- Separation of concerns: CLI presentation vs. domain logic vs. persistence vs. network vs. consensus.
- Test harness validating units in isolation (unit and integration tests under tests/).

d. Relevant technologies
- Rust & Cargo (build, dependency management).
- Hashing: SHA256 or custom (utils.rs).
- Serialization: bincode, serde (inferred from utils).
- File-system or simple DB for block persistence.
- Tokio or std::net for P2P sockets (not shown in code but typical in Rust crypto nodes).

##### Detail
- Sequence: e.g., mining loop → block found → persist → broadcast.
- Versioning notes if needed (Rust version, protocol version in block header).
- Keep labels concise but capture all essential architectural elements.
- Review src/chain utils and wallet code to call out any special hash algorithms or crypto libraries.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Actors
    User["User (CLI)"]:::external
    Peers["Other Peer Nodes"]:::network

    %% CLI Layer
    subgraph "CLI Interface" 
        direction TB
        NodeCLI["CleytoCoin\n(main node)"]:::cli
        WalletCLI["CleytoCoin-wallet"]:::cli
        MinerCLI["CleytoCoin-miner"]:::cli
    end

    %% Core Library
    subgraph "Core Library" 
        direction TB
        Lib["Core Library\n(src/lib.rs)"]:::core
        subgraph "Domain Modules"
            direction TB
            ChainMgr["Chain Manager"]:::core
            BlockComp["Block Struct & Validation"]:::core
            TxComp["Transaction Struct & Mempool"]:::core
            WalletMgr["Wallet Manager"]:::core
            UtilsComp["Utilities\n(Hashing & Serialization)"]:::core
            Consensus["Consensus Engine\n(PoW)"]:::core
        end
    end

    %% Infrastructure Layers
    Storage[("Blockchain Storage")]:::storage
    Net("P2P Network"):::network

    %% Test Harness and Config
    Tests["Integration & Unit Tests"]:::external
    Config["Cargo.toml & Cargo.lock"]:::external

    %% Data Flows
    User -->|issues CLI commands| NodeCLI
    User -->|issues CLI commands| WalletCLI
    User -->|issues CLI commands| MinerCLI

    NodeCLI -->|initialize node| Lib
    WalletCLI -->|wallet operations| Lib
    MinerCLI -->|start mining| Lib

    Lib -->|invoke Chain API| ChainMgr
    ChainMgr -->|validate block| BlockComp
    ChainMgr -->|manage mempool| TxComp
    ChainMgr -->|wallet queries| WalletMgr
    ChainMgr -->|utility calls| UtilsComp

    WalletCLI -->|key generation| WalletMgr
    NodeCLI -->|create tx| TxComp
    TxComp -->|"SignedTransactionJSON"| Net
    Net -->|receive tx/block| ChainMgr

    MinerCLI -->|nonce search| Consensus
    Consensus -->|block proposal| BlockComp
    BlockComp -->|validated block| ChainMgr
    ChainMgr -->|append block| Storage
    ChainMgr -->|persist/read| Storage
    ChainMgr -->|"BlockBinary"| Net
    Net -->|new block| ChainMgr

    %% Test and Config Links
    Tests -.->|tests modules| Lib
    Tests -.->|tests modules| ChainMgr

    %% Click Events
    click ChainMgr "https://github.com/dantee-e/cleytocoin/blob/master/src/chain.rs"
    click BlockComp "https://github.com/dantee-e/cleytocoin/blob/master/src/chain/block.rs"
    click TxComp "https://github.com/dantee-e/cleytocoin/blob/master/src/chain/transaction.rs"
    click WalletMgr "https://github.com/dantee-e/cleytocoin/blob/master/src/chain/wallet.rs"
    click UtilsComp "https://github.com/dantee-e/cleytocoin/blob/master/src/chain/utils.rs"
    click Lib "https://github.com/dantee-e/cleytocoin/blob/master/src/lib.rs"
    click Tests "https://github.com/dantee-e/cleytocoin/tree/master/tests/"
    click Config "https://github.com/dantee-e/cleytocoin/blob/master/Cargo.toml / Cargo.lock"

    %% Styles
    classDef cli fill:#AED6F1,stroke:#1F618D,color:#1B4F72;
    classDef core fill:#A9DFBF,stroke:#196F3D,color:#145A32;
    classDef storage fill:#E5E7E9,stroke:#424949,color:#1B2631,stroke-dasharray: 5 5;
    classDef network fill:#F9E79F,stroke:#B7950B,color:#7D6608;
    classDef external fill:#EBDEF0,stroke:#8E44AD,color:#4A235A,stroke-dasharray: 2 2;
```
