# mrmalinka/cc-cryptocoin architecture

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

- Interactive diagram: https://gitdiagram.com/mrmalinka/cc-cryptocoin
- Repository: https://github.com/mrmalinka/cc-cryptocoin

## Overview

##### Project type and purpose
- This is a peer‑to‑peer, decentralized cryptocurrency implementation running inside Minecraft’s ComputerCraft (CC: Tweaked).
- It is _not_ a blockchain; instead it relies on periodic _ledger broadcast_ and a “popularity” consensus mechanism.
- Key use case: each CC computer (a “node”) syncs a shared transaction history (ledger), verifies and signs transactions, and stores the ledger and wallet on a floppy disk.

##### File structure
- Top level
- startup.lua – entry point
- TODO.md, README.md, etc. for docs
- src/
- node.lua – core P2P node logic (network, ledger sync, transaction handling)
- wallets.lua – wallet generation, address encoding, signing/verification
- popularity.lua – consensus algorithm (vote counting, distance penalty)
- random.lua – random number generation utility
- ccryptolib/ – pure‑Lua crypto library
– blake3.lua, chacha20.lua, ed25519.lua (public API)
– internal/ – ECC arithmetic, field ops, packing, SHA‑512, util

##### README for additional insights
- Hardware: one ender modem + one disk drive per node
- “startup.lua genesis” to bootstrap first node, “startup.lua wallet” to display address
- Nodes broadcast the ledger periodically; newcomers pick the most popular copy
- No balance file stored; balances computed on‑the‑fly from transaction history

##### Elements
- Clear labels:
- Node Hardware (Modem, Disk)
- Node Software Modules (Startup, Core, Wallet, Consensus, Crypto)
- Local Storage (wallet.dat, ledger.dat)
- P2P Network
- External Pastebin Service
- Transaction broadcast → network → other nodes
- Ledger broadcast/retrieval → network → other nodes
- Crypto Library calls within Node Core / Wallet Module

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% P2P Network
    network["Wireless P2P Network"]:::network

    %% Node Instances
    subgraph "Node Instance A"
        direction TB
        subgraph "Hardware" 
            modem["Ender Modem"]:::hardware
            disk["Disk Drive"]:::hardware
        end
        subgraph "Software Modules"
            startup["Startup Script"]:::software
            NodeCore["Node Core Logic"]:::software
            WalletMod["Wallet Module"]:::software
            Consensus["Consensus Module"]:::software
            RandomMod["Random Utility"]:::software
            subgraph "Crypto Library"
                CryptoAPI["Public API"]:::software
                CryptoInt["Internal Primitives"]:::software
            end
        end
        subgraph "Local Storage"
            walletFile[(wallet.dat)]:::storage
            ledgerFile[(ledger.dat)]:::storage
        end
    end

    subgraph "Node Instance B"
        direction TB
        subgraph "Hardware"
            modem2["Ender Modem"]:::hardware
            disk2["Disk Drive"]:::hardware
        end
        subgraph "Software Modules"
            startup2["Startup Script"]:::software
            NodeCore2["Node Core Logic"]:::software
            WalletMod2["Wallet Module"]:::software
            Consensus2["Consensus Module"]:::software
            RandomMod2["Random Utility"]:::software
            subgraph "Crypto Library"
                CryptoAPI2["Public API"]:::software
                CryptoInt2["Internal Primitives"]:::software
            end
        end
        subgraph "Local Storage"
            walletFile2[(wallet.dat)]:::storage
            ledgerFile2[(ledger.dat)]:::storage
        end
    end

    %% External Service
    pastebin["Pastebin Service"]:::external

    %% Connections
    startup -->|loads| NodeCore
    NodeCore -->|uses| CryptoAPI
    NodeCore -->|uses| CryptoInt
    WalletMod -->|reads/writes| walletFile
    NodeCore -->|reads/writes| ledgerFile
    NodeCore -->|broadcast transaction| network
    NodeCore -->|broadcast ledger snapshot| network
    network -->|receives| NodeCore2
    network -->|receives| Consensus2
    NodeCore2 -->|loads ledger| ledgerFile2
    NodeCore2 -->|broadcast to| network
    startup -->|publish/fetch address| pastebin

    %% Click Events
    click startup "https://github.com/mrmalinka/cc-cryptocoin/blob/main/startup.lua"
    click NodeCore "https://github.com/mrmalinka/cc-cryptocoin/blob/main/src/node.lua"
    click WalletMod "https://github.com/mrmalinka/cc-cryptocoin/blob/main/src/wallets.lua"
    click Consensus "https://github.com/mrmalinka/cc-cryptocoin/blob/main/src/popularity.lua"
    click RandomMod "https://github.com/mrmalinka/cc-cryptocoin/blob/main/src/ccryptolib/random.lua"
    click CryptoAPI "https://github.com/mrmalinka/cc-cryptocoin/tree/main/src/ccryptolib/"
    click CryptoInt "https://github.com/mrmalinka/cc-cryptocoin/tree/main/src/ccryptolib/internal/"
    click pastebin "https://github.com/mrmalinka/cc-cryptocoin/blob/main/TODO.md"
    click pastebin "https://github.com/mrmalinka/cc-cryptocoin/blob/main/README.md"
    click pastebin "https://github.com/mrmalinka/cc-cryptocoin/tree/main/images/"

    %% Styles
    classDef hardware fill:#cccccc,stroke:#333,stroke-width:1px
    classDef software fill:#e0f7fa,stroke:#00796b,stroke-width:1px
    classDef storage fill:#c8e6c9,stroke:#2e7d32,stroke-width:1px
    classDef network fill:#bbdefb,stroke:#0d47a1,stroke-width:1px
    classDef external fill:#fff9c4,stroke:#f57f17,stroke-width:1px,stroke-dasharray: 5 5
```
