# psalant726/go-crypto architecture

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

- Interactive diagram: https://gitdiagram.com/psalant726/go-crypto
- Repository: https://github.com/psalant726/go-crypto

## Overview

##### Main Components

a) Core Blockchain Layer:
- It to a Block component (block.go)
- Proof of Work system (proofofwork.go)
- Merkle Tree component (merkle_tree.go)

b) Transaction Layer:
- Transactions (transaction.go)
- Transaction Inputs (transaction_input.go)
- Transaction Outputs (transaction_output.go)
- UTXO Set (utxo_set.go)

c) Wallet Layer:
- Wallet Management component containing:
- Individual Wallets (wallet.go)
- Wallet Collection (wallets.go)
- Base58 Encoding (base58.go)

d) Network Layer:
- Server component (server.go)
- Node Communication
- P2P Network connections

e) CLI Interface:
- Command processor (cli.go)
- Individual command handlers (cli_*.go files)

##### Relationship Flows

- User → CLI Interface
- CLI Interface → Wallet Layer
- CLI Interface → Blockchain Layer
- Wallet Layer → Transaction Layer
- Transaction Layer → Blockchain Layer
- Network Layer ↔ All Other Layers

##### Specific Implementation Details

Key architectural elements:
- Node Architecture (showing 3000, 3001, 3002 nodes)
- UTXO Set management
- Mining process flow
- P2P communication patterns

##### Component Interactions

Crucial flows:
- Transaction creation → Mining → Block addition
- Wallet creation → Address management
- Node synchronization process
- UTXO set updates

##### Additional Notes

Annotations for:
- Port configurations (3000, 3001, 3002)
- Database files (blockchain_*.db)
- Wallet data storage (wallet.dat)

Keep the abstraction level high enough to show the overall architecture but detailed enough to understand the interaction between components, especially the relationship between nodes, transaction processing, and block mining.

Remember to indicate the asynchronous nature of the P2P network and how nodes maintain consistency through the version and inventory commands shown in the README example.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CLI["CLI Layer"]
        CLI_PROC["Command Processor"]
        CLI_BC["Blockchain Creation"]
        CLI_WC["Wallet Creation"]
        CLI_BAL["Balance Checking"]
        CLI_ADDR["Address Listing"]
        CLI_PRINT["Chain Printing"]
        CLI_UTXO["UTXO Reindexing"]
        CLI_SEND["Transaction Sending"]
        CLI_NODE["Node Starting"]
    end

    subgraph CORE["Core Blockchain Layer"]
        BC["Blockchain Core"]
        BLOCK["Block Component"]
        POW["Proof of Work"]
        MERKLE["Merkle Tree"]
    end

    subgraph TX["Transaction Layer"]
        TXMGR["Transaction Management"]
        TXIN["Transaction Inputs"]
        TXOUT["Transaction Outputs"]
        UTXO["UTXO Set"]
    end

    subgraph WALLET["Wallet Layer"]
        WALL["Individual Wallets"]
        WALLS["Wallet Collection"]
        B58["Base58 Encoding"]
    end

    subgraph NET["Network Layer"]
        SERVER["Server Component"]
        NODES["Node Communication"]
    end

    subgraph UTIL["Utilities"]
        UTILS["Utility Functions"]
    end

    %% Relationships
    CLI --> WALLET
    CLI --> CORE
    WALLET --> TX
    TX --> CORE
    NET <--> CORE
    NET <--> TX
    NET <--> WALLET
    UTILS --> CORE
    UTILS --> TX
    UTILS --> WALLET

    %% Component Mappings
    click BC "https://github.com/PSalant726/go-crypto/blob/master/blockchain.go"
    click BLOCK "https://github.com/PSalant726/go-crypto/blob/master/block.go"
    click POW "https://github.com/PSalant726/go-crypto/blob/master/proofofwork.go"
    click MERKLE "https://github.com/PSalant726/go-crypto/blob/master/merkle_tree.go"
    click TXMGR "https://github.com/PSalant726/go-crypto/blob/master/transaction.go"
    click TXIN "https://github.com/PSalant726/go-crypto/blob/master/transaction_input.go"
    click TXOUT "https://github.com/PSalant726/go-crypto/blob/master/transaction_output.go"
    click UTXO "https://github.com/PSalant726/go-crypto/blob/master/utxo_set.go"
    click WALL "https://github.com/PSalant726/go-crypto/blob/master/wallet.go"
    click WALLS "https://github.com/PSalant726/go-crypto/blob/master/wallets.go"
    click B58 "https://github.com/PSalant726/go-crypto/blob/master/base58.go"
    click SERVER "https://github.com/PSalant726/go-crypto/blob/master/server.go"
    click NODES "https://github.com/PSalant726/go-crypto/blob/master/cli_startnode.go"
    click CLI_PROC "https://github.com/PSalant726/go-crypto/blob/master/cli.go"
    click CLI_BC "https://github.com/PSalant726/go-crypto/blob/master/cli_createblockchain.go"
    click CLI_WC "https://github.com/PSalant726/go-crypto/blob/master/cli_createwallet.go"
    click CLI_BAL "https://github.com/PSalant726/go-crypto/blob/master/cli_getbalance.go"
    click CLI_ADDR "https://github.com/PSalant726/go-crypto/blob/master/cli_listaddress.go"
    click CLI_PRINT "https://github.com/PSalant726/go-crypto/blob/master/cli_printchain.go"
    click CLI_UTXO "https://github.com/PSalant726/go-crypto/blob/master/cli_reindexutxo.go"
    click CLI_SEND "https://github.com/PSalant726/go-crypto/blob/master/cli_send.go"
    click CLI_NODE "https://github.com/PSalant726/go-crypto/blob/master/cli_startnode.go"
    click UTILS "https://github.com/PSalant726/go-crypto/blob/master/utils.go"

    classDef core fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef network fill:#87CEEB,stroke:#333,stroke-width:2px;
    classDef wallet fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef transaction fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef utility fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef cli fill:#DDA0DD,stroke:#333,stroke-width:2px;

    class BC,BLOCK,POW,MERKLE core;
    class SERVER,NODES network;
    class WALL,WALLS,B58 wallet;
    class TXMGR,TXIN,TXOUT,UTXO transaction;
    class UTILS utility;
    class CLI_PROC,CLI_BC,CLI_WC,CLI_BAL,CLI_ADDR,CLI_PRINT,CLI_UTXO,CLI_SEND,CLI_NODE cli;
```
