# akhilsharma90/go-proof-of-work-blockchain architecture

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

- Interactive diagram: https://gitdiagram.com/akhilsharma90/go-proof-of-work-blockchain
- Repository: https://github.com/akhilsharma90/go-proof-of-work-blockchain

## Overview

##### Main Components
- Application Entry Point: Represented by main.go, which initializes the server and blockchain.
- HTTP Server: This component listens on port 8080 for incoming GET and POST requests. It handles routing requests:
- GET requests display the current blocks.
- POST requests accept a JSON payload (e.g., {"BPM":75}) to trigger block creation.
- Blockchain Engine: The core logic that manages the blockchain. This includes:
- The blockchain data structure (an ordered list of blocks).
- The Proof-of-Work (PoW) consensus algorithm that validates mining work.
- Configuration/Environment: Although minimal, the .env file can be noted as the place to store any runtime settings (if used).

##### Relationships and Interactions
- User Interaction (via Browser or CURL) → HTTP Server:
- GET Request: Fetches and displays the current blockchain.
- POST Request: Sends new data (BPM value) to initiate block creation.
- HTTP Server → Blockchain Engine:
- On receiving a POST request, the server passes the BPM data to the blockchain engine.
- The blockchain engine performs the PoW algorithm to mine a new block.
- Blockchain Engine → Blockchain Data:
- The new block (once validated by PoW) is securely added to the chain.
- HTTP Server → Response:
- The updated state of the blockchain is returned to the client.

##### Architectural Patterns and Design Principles
- Presentation Layer: The HTTP server interface (handling GET and POST).
- Domain/Business Logic: The blockchain and PoW logic.
- Separation of Concerns: Each component has a distinct purpose – handling HTTP requests vs. managing blockchain state vs. running the consensus mechanism.

##### Relevant Technologies, Frameworks, and Libraries
- Go Language: All implementation details reside in main.go and dependency management is handled via go.mod and go.sum.
- Built-in HTTP Packages: Likely used from Go’s standard library for serving endpoints.
- JSON Handling: For parsing the POST request body (payload) and returning JSON responses.

##### Detail
- Every flow involved in the block addition process:
- User sends a POST → HTTP Server extracts the BPM → Passes to Blockchain Engine → Performs PoW → Adds block → Returns updated chain.
- Dependencies (like the Go built-in libraries) if relevant.
- Directional data flows are clear and that each component is well-labeled.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Application Entry Point"]:::domain
    B["HTTP Server (Port 8080)"]:::presentation
    F["Configuration (.env)"]:::config
    C["Blockchain Engine"]:::domain
    D["PoW Algorithm"]:::domain
    E["Blockchain Data (Chain)"]:::domain
    G["Client (Browser/CURL)"]:::client

    %% Initialization Flow
    A -->|"initializes"| B
    F -->|"loads_config"| B

    %% GET Request Flow
    G -->|"GET:RequestBlocks"| B
    B -->|"GET:RetrieveChain"| E
    E -->|"chain_data"| B
    B -->|"GET:Response"| G

    %% POST Request Flow
    G -->|"POST:SubmitBPM"| B
    B -->|"POST:ProcessBPM"| C
    C -->|"execute_PoW"| D
    D -->|"validate&add_block"| E
    C -->|"return_updated_chain"| B
    B -->|"POST:Response"| G

    %% Click Events
    click A "https://github.com/akhilsharma90/go-proof-of-work-blockchain/blob/master/main.go"
    click B "https://github.com/akhilsharma90/go-proof-of-work-blockchain/blob/master/main.go"
    click C "https://github.com/akhilsharma90/go-proof-of-work-blockchain/blob/master/main.go"
    click F "https://github.com/akhilsharma90/go-proof-of-work-blockchain/blob/master/.env"

    %% Styles
    classDef client fill:#e0f7fa,stroke:#006064,stroke-width:2px;
    classDef presentation fill:#ffecb3,stroke:#f57f17,stroke-width:2px;
    classDef domain fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef config fill:#d1c4e9,stroke:#7e57c2,stroke-width:2px;
```
