# dpedwards/dotnet-core-blockchain architecture

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

- Interactive diagram: https://gitdiagram.com/dpedwards/dotnet-core-blockchain
- Repository: https://github.com/dpedwards/dotnet-core-blockchain

## Overview

##### Main Components
- Web Application/MVC Layer: The “BlockChain” folder contains the ASP.NET Core project with the typical MVC structure (Controllers, Models, Views). The HomeController and BlockChainController (under the Api folder) serve as entry points for browser-based interactions and API endpoints.
- Blockchain Logic: Modules/Models like Block, Transaction, Node, and CryptoCurrency represent the blockchain’s core data and logic. This illustrates the domain model for building and chaining blocks.
- Cryptography Module: The separate “RSA” project shows that RSA cryptography is handled independently. It should be represented as a library or service that the blockchain application calls for key generation and signing.
- Frontend Assets: The wwwroot directory contains CSS, JavaScript, and third-party libraries (e.g., Bootstrap, jQuery) to support the application’s UI.
- Configuration and Deployment: Files like appsettings.json, launchSettings.json, and scripts (dotnet_run.bat, dotnet_restore.bat), along with Visual Studio solution files, indicate the environment and deployment configuration.

##### Relationships and Interactions
- The client (web browser) interacts with the web application’s views. Controllers (HomeController, BlockChainController) process HTTP requests, trigger blockchain operations, and render views.
- The API endpoints exposed by the BlockChainController likely handle blockchain network operations such as mining new blocks or adding nodes.
- The models encapsulate blockchain data. Their interactions include creating new blocks, validating chains, and managing transactions.

##### Architectural Patterns and Technologies
- MVC Pattern: Emphasize clearly that the web application uses the Model-View-Controller paradigm. The models capture domain data (blocks, transactions), controllers manage business logic and requests, and views (cshtml files) manage presentation.
- API Integration: The existence of an “Api” subfolder and endpoints in BlockChainController suggests a RESTful API design that handles external interactions (possibly from miners or other nodes).
- Cryptography: Mark the integration of RSA for cryptographic operations. This is a critical element since secure key management and block signing are essential in blockchain technologies.
- .NET Core Infrastructure: Note the reliance on .NET Core (version 2.2 or above) along with external packages (e.g., NBitcoin for blockchain operations, Newtonsoft.Json for JSON handling).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Client["Client/Browser"]:::client
    External["External Nodes/Miners"]:::external

    %% ASP.NET Core MVC Web Application
    subgraph "ASP.NET Core MVC Web Application"
        %% Controllers Group
        subgraph "Controllers"
            HomeController["HomeController"]:::controller
            BlockChainController["BlockChainController (API)"]:::controller
        end
        %% Blockchain Core Models Group
        subgraph "Blockchain Core (Models)"
            Block["Block"]:::model
            Transaction["Transaction"]:::model
            Node["Node"]:::model
            CryptoCurrency["CryptoCurrency"]:::model
        end
        Views["Views"]:::view
        Assets["Frontend Assets"]:::assets
        Config["Configuration & Deployment"]:::config
    end

    RSA_Module["RSA Cryptographic Service"]:::rsa

    %% Connections between external clients and web application components
    Client -->|"HTTPRequest"| HomeController
    External -->|"Network(43210)"| BlockChainController

    %% Internal ASP.NET Core MVC Flow
    HomeController -->|"TriggersOperation"| Block
    HomeController -->|"RendersView"| Views
    BlockChainController -->|"APIRequest"| Block
    BlockChainController -->|"ReturnsJSON"| Views
    HomeController -->|"ProcessesTxn"| Transaction
    BlockChainController -->|"ValidatesNode"| Node
    Transaction -->|"AssociatesWith"| Block
    Node -->|"ConnectsTo"| CryptoCurrency

    %% Blockchain Core invoking RSA operations
    Block -->|"SignsBlock"| RSA_Module

    %% Frontend Assets serving static files for Views
    Assets -->|"SuppliesAssets"| Views

    %% Configuration flows (supporting settings)
    Config ---|"Uses"| HomeController

    %% Additional Configuration details as separate nodes
    ConfigApp["appsettings.json"]:::config
    ConfigLaunch["launchSettings.json"]:::config
    ConfigRun["dotnet_run.bat"]:::config
    ConfigRestore["dotnet_restore.bat"]:::config

    Config --> ConfigApp
    Config --> ConfigLaunch
    Config --> ConfigRun
    Config --> ConfigRestore

    %% Click Events for Components
    click HomeController "https://github.com/dpedwards/dotnet-core-blockchain/blob/master/BlockChain/BlockChain/Controllers/HomeController.cs"
    click BlockChainController "https://github.com/dpedwards/dotnet-core-blockchain/blob/master/BlockChain/BlockChain/Api/BlockChainController.cs"
    click Views "https://github.com/dpedwards/dotnet-core-blockchain/tree/master/BlockChain/BlockChain/Views"
    click Block "https://github.com/dpedwards/dotnet-core-blockchain/blob/master/BlockChain/BlockChain/Models/Block.cs"
    click Transaction "https://github.com/dpedwards/dotnet-core-blockchain/blob/master/BlockChain/BlockChain/Models/Transaction.cs"
    click Node "https://github.com/dpedwards/dotnet-core-blockchain/blob/master/BlockChain/BlockChain/Models/Node.cs"
    click CryptoCurrency "https://github.com/dpedwards/dotnet-core-blockchain/blob/master/BlockChain/BlockChain/Models/CryptoCurrency.cs"
    click RSA_Module "https://github.com/dpedwards/dotnet-core-blockchain/tree/master/BlockChain/RSA"
    click Assets "https://github.com/dpedwards/dotnet-core-blockchain/tree/master/BlockChain/BlockChain/wwwroot"
    click ConfigApp "https://github.com/dpedwards/dotnet-core-blockchain/blob/master/BlockChain/BlockChain/appsettings.json"
    click ConfigLaunch "https://github.com/dpedwards/dotnet-core-blockchain/blob/master/BlockChain/BlockChain/Properties/launchSettings.json"
    click ConfigRun "https://github.com/dpedwards/dotnet-core-blockchain/blob/master/BlockChain/BlockChain/dotnet_run.bat"
    click ConfigRestore "https://github.com/dpedwards/dotnet-core-blockchain/blob/master/BlockChain/BlockChain/dotnet_restore.bat"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef controller fill:#D1F2EB,stroke:#117864,stroke-width:2px;
    classDef model fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
    classDef view fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef assets fill:#FCF3CF,stroke:#B7950B,stroke-width:2px;
    classDef config fill:#D6EAF8,stroke:#2E86C1,stroke-width:2px;
    classDef rsa fill:#F5CBA7,stroke:#AF601A,stroke-width:2px;
```
