# aradhya0/blockchain-file-storage architecture

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

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

## Overview

Based on our analysis of the project’s file tree and README, this application is a decentralized, blockchain‐based file storage system. It combines a web‐based client interface with a peer-to-peer blockchain network to securely store files in on-chain blocks. The architecture involves several key modules:

##### Main Components
- Blockchain Engine:
- Files Involved: Block.py, Blockchain.py, POW_Comparison.py.
- Purpose: Implements the blockchain data structure, handles block creation with file data (including filename, filesize, and file content) and integrates two different Proof of Work (PoW) algorithms (one using a random nonce and another incrementing a nonce) to secure the chain.
- Peer Node:
- File: peer.py.
- Purpose: Acts as one of the decentralized network nodes. It listens for incoming file upload transactions, initiates and participates in block creation/mining, and ensures that once a file is uploaded it can be retrieved securely.
- Web Client/Server:
- Files Involved: run_app.py, app/ (which includes templates, views.py, and static assets).
- Purpose: Provides a user interface, likely built with Flask, where users can upload files, view the blockchain data, and download files. The templates and CSS within app/templates and app/static offer a front-end web experience.
- File Upload & Testing:
- Directory: Test_File_Upload (contains sample files of various types).
- Purpose: Serves as a test suite or sample dataset for validating file uploads into the system.
- Static Resources and Templates:
- Files: CSS files, base.html, and index.html.
- Purpose: Support the front-end design and user interactions, offering an easy way to display and access files stored on the blockchain.

##### Relationships and Data Flow
- The Web Client/Server (via run_app.py and the “app” folder) interacts with the blockchain backend. When a user uploads a file, it is sent over to the blockchain engine.
- The Blockchain Engine (via Blockchain.py and Block.py) packages the file’s metadata and data into a new block. It then applies the PoW algorithm (with proof-of-work details in POW_Comparison.py) before appending it to the chain.
- The Peer Node (peer.py) operates as an independent server node that can also initiate mining and validate blocks. It interacts with the client, potentially letting users or other peers request/download stored files.
- The Test_File_Upload directory provides sample files to test the file upload mechanism and verify the blockchain’s behavior.

##### Architectural Patterns & Design Principles
- Client-Server Architecture: Clear separation between the front-end client (handling the user interface and uploads) and the back-end (handling blockchain operations).
- Decentralized/P2P Design: With the peer.py module, the system demonstrates decentralized data validation and blockchain propagation.
- Security via Cryptographic Proof of Work: Two PoW methods are implemented and compared, emphasizing both security (via random nonce generation) and performance trade-offs.
- Modular Code Separation: Different functionalities (block formation, file handling, proof of work, and web serving) are clearly separated into different Python modules and directories.

##### Technologies and Frameworks
- Python is the primary language, with Flask likely used for the web application (based on the “app” folder structure and template files).
- Cryptographic hashing algorithms (SHA256, as described in the README) are central to the blockchain’s security.
- Front-end assets (CSS, Bootstrap, Font Awesome) aid in creating a user-friendly interface.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    U["User Interface"]:::user

    %% Web Client/Server Subgraph
    subgraph "Web Client/Server"
        WA["run_app.py"]:::web
        AM["App Module"]:::web
        V["Views"]:::web
        T["Templates"]:::web
        S["Static Assets"]:::web
    end

    %% Blockchain Engine Subgraph
    subgraph "Blockchain Engine"
        B["Block"]:::blockchain
        BC["Blockchain"]:::blockchain
        POW["POW Comparison"]:::blockchain
    end

    %% Peer Node
    PN["Peer Node"]:::peer

    %% File Upload & Testing Component
    TF["File Upload & Testing"]:::test

    %% Relationships and Data Flow
    U -->|"uploads"| WA
    TF -->|"provides test files"| WA
    WA -->|"initializes"| AM
    AM -->|"handles file upload"| BC
    BC -->|"creates block"| B
    BC -->|"executes PoW"| POW
    BC -->|"notifies"| PN
    PN -->|"serves file retrieval"| WA

    %% Internal Web Module Structure
    AM -->|"renders view"| V
    AM -->|"loads templates"| T
    AM -->|"serves static content"| S

    %% Click Events
    click B "https://github.com/aradhya0/blockchain-file-storage/blob/main/Block.py"
    click BC "https://github.com/aradhya0/blockchain-file-storage/blob/main/Blockchain.py"
    click POW "https://github.com/aradhya0/blockchain-file-storage/blob/main/POW_Comparison.py"
    click PN "https://github.com/aradhya0/blockchain-file-storage/blob/main/peer.py"
    click WA "https://github.com/aradhya0/blockchain-file-storage/blob/main/run_app.py"
    click AM "https://github.com/aradhya0/blockchain-file-storage/tree/main/app/"
    click V "https://github.com/aradhya0/blockchain-file-storage/blob/main/app/views.py"
    click T "https://github.com/aradhya0/blockchain-file-storage/tree/main/app/templates"
    click S "https://github.com/aradhya0/blockchain-file-storage/tree/main/app/static"
    click TF "https://github.com/aradhya0/blockchain-file-storage/tree/main/Test_File_Upload"

    %% Styles
    classDef user fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef web fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef blockchain fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef peer fill:#FFCCCB,stroke:#333,stroke-width:2px;
    classDef test fill:#FFFF99,stroke:#333,stroke-width:2px;
```
