How akhilsharma90/go-proof-of-work-blockchain works
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.