# codingbeast25/blockchain-based-file-storage architecture

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

- Interactive diagram: https://gitdiagram.com/codingbeast25/blockchain-based-file-storage
- Repository: https://github.com/codingbeast25/blockchain-based-file-storage

## Overview

##### Project Type and Purpose
- This is a blockchain-based decentralized file storage web application.
- Users (via a web client) can upload and download files, and these files are stored “on-chain” within blocks. Each block contains file information (username, file size, file data) and is secured via a Proof-of-Work (PoW) algorithm.
- The README explains two variants of the PoW algorithm and compares their performance which is central to the blockchain’s security and performance.

##### Analysis of the File Structure
- At the top level, you see files like Block.py, Blockchain.py, POW_Comparison.py, and peer.py. These are core components responsible for constructing and managing the blockchain and executing Proof-of-Work.
- The Test_File_Upload folder holds test files of various types (e.g. .py, .pdf, .docx) used to simulate file uploads.
- The “app” directory contains the web application (Flask-based). Within it:
– __init__.py initializes the application.
– “views.py” likely contains the routes and logic handling the web requests.
– The “templates” directory holds HTML files (base.html, index.html) used for the presentation layer.
– The “static” directory (in both the root and within app) holds CSS assets and perhaps the Uploads folder for the actual files.
- run_app.py starts the client (web application) while peer.py starts the server/peer node.
- requirements.txt specifies the libraries required (likely including Flask, and possibly cryptographic libraries).

a. Main Components to Include:
- Web Client (Browser): Represents the user interface where the user accesses the application.
- web Application Server (run_app.py):
– Handles incoming HTTP requests from the browser.
– Uses templates (views in app/templates) and static assets (app/static) to render the file upload/download pages.
- Peer/Blockchain Node (peer.py):
– Runs in parallel to the client application.
– Contains the blockchain components (Block.py, Blockchain.py) and handles block creation, validation, and the PoW consensus process.
– Integrates the two PoW approaches detailed in POW_Comparison.py.
- Blockchain Core:
– Block and Blockchain modules showing how each block encapsulates file data and is chained securely.
- File Storage Module:
– Represents where the file data is physically stored (e.g., within app/static/Uploads or similar directories).
- PoW Comparison Utility:
– Although not part of the runtime system, POW_Comparison.py can be shown as an analysis tool that compares nonce generation strategies.

b. Relationships and Interactions:
- The web application communicates with the blockchain node when it needs to add a file (block) to the chain.
- Data flow within the blockchain system shows that once a file is received, it enters the blockchain core, gets wrapped in a block, and then the PoW algorithm (random vs. incremental) is employed to secure the block.
- The entire chain’s immutable nature (each block references the previous one) should be displayed as a sequential data flow.

c. Architectural Patterns and Key Technologies:
- Decentralization and peer-to-peer networking: Highlight that the peer node (peer.py) is meant to run concurrently with client operations.
- MVC (Model-View-Controller) like separation in the web application, where:
– Model: Blockchain, Block, and file storage logic.
– View: The HTML templates in app/templates and static assets (CSS).
– Controller: The routes/handlers in app/views.py.
- Use of PoW algorithms for consensus.
- Use of Flask for building the web interface.

- For this full-stack application, clearly distinguish the frontend (Client/Browser and web templates) from the backend (blockchain and file storage modules).
– The Client Layer (browser).
– The Application Layer (run_app.py, app/views.py, and the static/templates directories).
– The Blockchain/P2P Layer (peer.py, Block.py, Blockchain.py, POW_Comparison.py).

##### Summary of Steps to be Taken
- Blockchain component (core modules: Block.py and Blockchain.py).
- Interaction between the proof-of-work algorithms and block creation. Highlight the two strategies (random nonce vs. sequential nonce) and the performance implications discussed in the README.
- Decentralized aspect by showing a “peer” setup (peer.py) that interacts with connected clients.
- File storage path and role in the process (via the Uploads folder in the static directory).
- User interface layer (HTML templates, CSS, run_app.py) that interacts with the end user through a browser.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Layer
    subgraph "Client Layer"
        WC["Web Client"]:::client
        HT["HTML Templates"]:::client
    end

    %% Application Layer
    subgraph "Application Layer"
        WAS["Web Application Server"]:::app
    end

    %% Blockchain/P2P Layer
    subgraph "Blockchain/P2P Layer"
        PBN["Peer/Blockchain Node"]:::blockchain
        BC["Blockchain Core"]:::blockchain
        POW["PoW Comparison Utility"]:::blockchain
    end

    %% Storage Layer
    subgraph "Storage"
        FS["File Storage Module"]:::storage
    end

    %% Connections
    WC -->|"HTTP_Request"| WAS
    WAS -->|"Render_using"| HT
    WAS -->|"Upload_File_API"| PBN
    WAS -->|"Store_File"| FS
    PBN -->|"Block_Creation"| BC
    BC -->|"Run_PoW"| POW

    %% Click Events
    click HT "https://github.com/codingbeast25/blockchain-based-file-storage/tree/main/app/templates"
    click WAS "https://github.com/codingbeast25/blockchain-based-file-storage/blob/main/run_app.py"
    click WAS "https://github.com/codingbeast25/blockchain-based-file-storage/blob/main/app/views.py"
    click PBN "https://github.com/codingbeast25/blockchain-based-file-storage/blob/main/peer.py"
    click BC "https://github.com/codingbeast25/blockchain-based-file-storage/blob/main/Block.py"
    click BC "https://github.com/codingbeast25/blockchain-based-file-storage/blob/main/Blockchain.py"
    click FS "https://github.com/codingbeast25/blockchain-based-file-storage/tree/main/app/static/Uploads"
    click POW "https://github.com/codingbeast25/blockchain-based-file-storage/blob/main/POW_Comparison.py"

    %% Styles
    classDef client fill:#f9c,stroke:#333,stroke-width:2px;
    classDef app fill:#bbf,stroke:#333,stroke-width:2px;
    classDef blockchain fill:#afa,stroke:#333,stroke-width:2px;
    classDef storage fill:#ffb,stroke:#333,stroke-width:2px;
```
