# rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting architecture

> Architecture diagram of the GitHub repository rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting
- Repository: https://github.com/rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting

## Overview

##### Project Type and Purpose
- This is a decentralized full-stack application (“dApp”) for secure, encrypted source-code hosting.
- It uses a browser‐based client, an Ethereum smart contract (VersionControl.sol), IPFS for storage, and a Node.js “middleman” server for optimistic key-share retrieval.

##### File Structure
- Top level:
- Client dApp files: index.html, style.css, app.js, libs/ (crypto-js, ethers.js, ipfs-http-client.js, secrets.js)
- Benchmark script (benchmark.ps1)
- Graphs folder (likely contains figures or data for the manuscript)
- Smart contract code (VersionControl.sol referenced in README but not shown in file tree)
- middleman-server/: Node.js/Express code (server.js, package.json) deployed serverlessly.
- Configuration: .gitignore, .gitattributes.

##### Key Insights from the README
- Three main components:
a) Client-side dApp (all crypto, SSS, AES-256 done in the browser)
b) Smart contract on Ethereum Sepolia
c) Middleman server for optimistic retrieval
- Data flows: encryption → IPFS upload → key splitting → one share on‐chain + remaining shares via middleman.

a. Client dApp
- Browser UI (index.html + style.css)
- JavaScript modules: app.js orchestrates operations, libs/crypto-js for AES, libs/secrets.js for Shamir’s Secret Sharing, libs/ethers.js for blockchain calls, libs/ipfs-http-client.js for IPFS interactions.
b. Ethereum Blockchain
- VersionControl.sol contract (on Sepolia testnet)
- Ethereum node or Infura/Alchemy endpoint
c. IPFS Network
- Public IPFS gateway or custom node for storing encrypted repo snapshots
d. Middleman Server
- Node.js/Express “fast path” cache (server.js) deployed as serverless (e.g., Vercel)

##### Relationships and Interactions
1) User triggers “push” in dApp →
- Encrypts code (AES-256) → splits key into N shares (SSS).
- Uploads encrypted repo to IPFS → receives CID.
- Sends one key‐share + metadata to blockchain via ethers.js → transaction pending.
- Sends remaining key‐shares to middleman server via REST API.
2) Collaborator “pull” in dApp →
- Tries optimistic retrieval: GET share from middleman → if available, reconstruct key early.
- Otherwise, waits for on‐chain event confirming share → fetches from blockchain logs.
- Fetches encrypted content from IPFS → decrypts in browser.

##### Architectural Patterns & Principles
- Decentralized storage & ledger
- Client-side end-to-end encryption
- Shamir’s Secret Sharing to minimize trust
- Optimistic‐first fallback to on‐chain for high performance
- Serverless middleware as cache (microservice pattern)

##### Essential Elements
- Clear, self-explanatory labels for every node.
- External dependencies (Ethereum node provider, public IPFS).

## Diagram (Mermaid)

```mermaid
graph TB
  subgraph "Browser dApp"
    UI["Client UI (index.html)"]
    Style["Stylesheet (style.css)"]
    App["App Orchestration (app.js)"]
    Crypto["AES-256 Encryption (crypto-js.js)"]
    SSS["Shamir’s Secret Sharing (secrets.js)"]
    Ethers["Ethereum SDK (ethers.js)"]
    IPFSLib["IPFS HTTP Client (ipfs-http-client.js)"]
  end

  subgraph "Middleman Server"
    ServerJS["Entry Point (server.js)"]
    PackageJSON["Configuration (package.json)"]
  end

  Ethereum[/ "Ethereum Sepolia" \]
  IPFS(("IPFS Network"))

  App -->|"Upload to IPFS (CID)"| IPFS
  App -->|"Send share & metadata"| Ethereum
  App -->|"POST shares to Middleman"| ServerJS

  App -->|"GET share (optimistic)"| ServerJS
  App -.->|"Fetch share from Chain (fallback)"| Ethereum

  App -->|"Fetch encrypted content"| IPFS
  App -->|"Decrypt & Reconstruct"| Crypto
  App -->|"Decrypt & Reconstruct"| SSS

  classDef frontend fill:#D6E9FF,stroke:#000
  classDef middleman fill:#DFFFE0,stroke:#000
  classDef blockchain fill:#FFE4B2,stroke:#000
  classDef storage fill:#E0D5FF,stroke:#000

  class UI,Style,App,Crypto,SSS,Ethers,IPFSLib frontend
  class ServerJS,PackageJSON middleman
  class Ethereum blockchain
  class IPFS storage

  click UI "https://github.com/rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting/blob/main/index.html"
  click Style "https://github.com/rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting/blob/main/style.css"
  click App "https://github.com/rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting/blob/main/app.js"
  click Crypto "https://github.com/rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting/blob/main/libs/crypto-js.js"
  click SSS "https://github.com/rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting/blob/main/libs/secrets.js"
  click Ethers "https://github.com/rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting/blob/main/libs/ethers.js"
  click IPFSLib "https://github.com/rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting/blob/main/libs/ipfs-http-client.js"
  click ServerJS "https://github.com/rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting/blob/main/middleman-server/server.js"
  click PackageJSON "https://github.com/rafidhaque/blockchain-and-middleman-ipfs-based-solution-for-repository-hosting/blob/main/middleman-server/package.json"
```
