# taiguz/react-blockchain architecture

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

## Overview

##### Project type and purpose
- This is a single‐page web application built with React and TypeScript.

##### File structure
- Top‐level files:
- package.json, tsconfig.json → build & dependency configuration
- public/ → static assets (index.html, manifest, robots.txt)
- src/ → application source
- src/class/ → pure domain logic classes
- Block/index.ts & types.ts → Block model, hash generation, attributes (index, timestamp, previousHash, nonce, someData)
- BlockChain/index.ts & types.ts → Blockchain model, integrity check, chain array, addBlock, mineBlock
- src/components/ → React UI components
- Main → container for the whole app, holds state of chain & difficulty
- Block → renders a single block’s properties
- Miner → UI for entering “someData,” selecting difficulty, running mining, displaying real‐time hash trials/time elapsed
- src/index.tsx → application entry point, renders <Main />

##### README for additional insights
- Confirms use of crypto-js for SHA-256 hashing
- Describes core features: dynamic difficulty, proof‐of‐work mining routine, chain integrity validation, UI demo with hash sampling

a. Main components:
- Browser/User Interface (React SPA)
- React Components: Main, Block, Miner
- Blockchain Engine: Block class, BlockChain class
- External Library: crypto-js (SHA-256)
b. Relationships and data flows:
1. User interacts with Miner component (inputs data & difficulty)
2. Miner invokes BlockChain.mineBlock(someData, difficulty)
3. BlockChain uses Block.generateHash() (crypto-js SHA-256) in a loop, emits hash samples/events
4. Miner component subscribes to hash‐trial events to update the UI (hash stream + timer)
5. On finding a valid nonce, Miner calls BlockChain.addBlock(newBlock)
6. Main component updates its state (list of blocks) and re‐renders Block list
c. Architectural patterns / principles:
- Component‐based UI with unidirectional data flow (React state lifting)
- Separation of concerns: Presentation (React) vs Domain Logic (TypeScript classes)
- Event‐driven updates (callbacks or observables for hash sampling)
- No backend – fully client‐side, in‐memory blockchain simulation
d. Relevant technologies:
- React + ReactDOM
- TypeScript
- crypto-js (SHA-256)
- Webpack (via create-react-app implied)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External actor
    User((User)):::external

    subgraph "Browser (Client-Side)"
        subgraph "Presentation Layer"
            Entry["Entry Point<br/>&lt;src/index.tsx&gt;"]:::ui
            MainComp["Main"]:::ui
            MainStyles["Main Styles"]:::ui
            MinerComp["Miner"]:::ui
            MinerStyles["Miner Styles"]:::ui
            BlockComp["Block"]:::ui
            BlockStyles["Block Styles"]:::ui
        end
        subgraph "Domain Layer"
            BlockClass["Block"]:::domain
            BlockTypes["Block Types"]:::domain
            BlockchainClass["BlockChain"]:::domain
            BlockchainTypes["BlockChain Types"]:::domain
        end
        subgraph "External Library"
            Crypto["crypto-js (SHA-256)"]:::external
        end
    end

    %% Data and control flows
    User -->|"interacts"| MinerComp
    MinerComp -->|"mineBlock(someData,difficulty)"| BlockchainClass
    BlockchainClass -->|"generateHash() call"| Crypto
    Crypto -->|"hash result"| BlockchainClass
    BlockchainClass -->|"onHashSample() event"| MinerComp
    MinerComp -->|"addBlock(newBlock)"| BlockchainClass
    BlockchainClass -->|"setState(blocks)"| MainComp
    MainComp -->|"renders"| BlockComp

    %% Click events
    click Entry "https://github.com/taiguz/react-blockchain/blob/main/src/index.tsx"
    click MainComp "https://github.com/taiguz/react-blockchain/blob/main/src/components/Main/index.tsx"
    click MainStyles "https://github.com/taiguz/react-blockchain/blob/main/src/components/Main/style.tsx"
    click BlockComp "https://github.com/taiguz/react-blockchain/blob/main/src/components/Block/index.tsx"
    click BlockStyles "https://github.com/taiguz/react-blockchain/blob/main/src/components/Block/style.tsx"
    click MinerComp "https://github.com/taiguz/react-blockchain/blob/main/src/components/Miner/index.tsx"
    click MinerStyles "https://github.com/taiguz/react-blockchain/blob/main/src/components/Miner/style.tsx"
    click BlockClass "https://github.com/taiguz/react-blockchain/blob/main/src/class/Block/index.ts"
    click BlockTypes "https://github.com/taiguz/react-blockchain/blob/main/src/class/Block/types.ts"
    click BlockchainClass "https://github.com/taiguz/react-blockchain/blob/main/src/class/BlockChain/index.ts"
    click BlockchainTypes "https://github.com/taiguz/react-blockchain/blob/main/src/class/BlockChain/types.ts"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366d6,color:#000000
    classDef domain fill:#DFFFD6,stroke:#228B22,color:#000000
    classDef external fill:#E0E0E0,stroke:#808080,color:#000000
```
