How codingbeast25/blockchain-based-file-storage works
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.