# harsh242/betterfund-crowdfunding-in-blockchain architecture

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

- Interactive diagram: https://gitdiagram.com/harsh242/betterfund-crowdfunding-in-blockchain
- Repository: https://github.com/harsh242/betterfund-crowdfunding-in-blockchain

## Overview

##### Project Type and Purpose
- This is a full-stack decentralized application (dApp) for crowdfunding, built with Next.js (React) on the frontend, Solidity smart contracts on Ethereum (Rinkeby), and Web3.js for blockchain interactions.
- Users create and contribute to campaigns via a web UI; funds and campaign logic live on Ethereum smart contracts (CampaignFactory & Campaign).

##### File Structure Analysis
- Top-level directories:
- pages/ – Next.js pages (UI for listing, creating campaigns & requests, plus an API route)
- components/ – Reusable React components (Navbar, Footer, DarkModeSwitch)
- lib/ – Helper modules (e.g., getETHPrice.js for fetching ETH price)
- smart-contract/ – Solidity contracts, build artifacts, and Node scripts (compile.js, deploy.js, campaign.js, factory.js, web3.js)
- public/ – Static assets
- styles/ – CSS modules and globals
- Configuration & deployment: next.config.js, package.json, .env in smart-contract for Infura credentials.

##### README Insights
- Tech Stack: Next.js, Chakra UI, Solidity, Web3.js, deployed on Vercel & Rinkeby via Infura.
- Workflow:
a. compile.js → generates ABI JSONs
b. deploy.js → pushes contracts to Rinkeby, writes addresses into factory.js
c. Frontend uses web3.js + factory.js to instantiate Contract instances

- Rectangles for services/components
- Parallelograms for user interfaces

[Parallelogram: User Browser + MetaMask]
| (1) connect, sign tx
V
[Rectangle (blue): Next.js Frontend on Vercel]
- pages/: index, campaign/[id], campaign/new, requests
- components/: Navbar, Footer, DarkModeSwitch
- Chakra UI styling
| (2) read/write calls via Web3.js
V
[Rectangle (green): Web3.js + lib/getETHPrice]
- web3.js → Infura provider (Rinkeby)
- getETHPrice.js → external price API
| (3) JSON-RPC over HTTPS/WebSocket
V
[Rectangle (orange): Ethereum Node (Infura)]
| (4) broadcast tx / query state
V
- Smart Contracts:
– CampaignFactory (creates Campaigns)
– Campaign (manages contributions & requests)

[compile.js] → build/*.json (ABI)
|
[deploy.js] → writes deployed address → factory.js config

##### Relationships & Interactions
a. Browser ↔ Frontend: UI events trigger React components → Web3 calls.
b. Frontend → Ethereum Node: via web3.js & Infura (read/write).
c. Ethereum Node → Blockchain: transaction propagation & state queries.
d. Dev scripts: compile.js & deploy.js run off-chain to prepare and deploy contracts.

##### Architectural Patterns & Principles
- Separation of concerns:
- UI layer (Next.js)
- Blockchain logic (Solidity contracts)
- Integration layer (Web3.js)
- Serverless + CDN hosting (Vercel) for frontend.
- Immutable, transparent on-chain storage for campaign data.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UB[/User Browser + MetaMask/]:::ui

    subgraph "Frontend (Vercel)"
        direction TB
        NI["pages/index.js"]:::ui
        CID["pages/campaign/[id].js"]:::ui
        CNEW["pages/campaign/new.js"]:::ui
        RINDEX["pages/campaign/[id]/requests/index.js"]:::ui
        RNEW["pages/campaign/[id]/requests/new.js"]:::ui
        API["pages/api/hello.js"]:::ui
        NAV["components/Navbar.js"]:::ui
        FOOT["components/Footer.js"]:::ui
        DM["components/DarkModeSwitch.js"]:::ui
        CFG["next.config.js"]:::ui
        ST1["styles/Home.module.css"]:::ui
        ST2["styles/globals.css"]:::ui
    end

    subgraph "Integration Layer"
        direction TB
        WEB3["smart-contract/web3.js"]:::integration
        PRICE["lib/getETHPrice.js"]:::integration
    end

    INFURA["Ethereum Node (Infura)"]:::network
    BC["Ethereum Blockchain (Rinkeby)\n(CampaignFactory & Campaign)"]:::storage

    subgraph "Dev Pipeline" 
        direction TB
        COMPILE["smart-contract/compile.js"]:::dev
        BUILD1["smart-contract/build/Campaign.json"]:::dev
        BUILD2["smart-contract/build/CampaignFactory.json"]:::dev
        DEPLOY["smart-contract/deploy.js"]:::dev
        FACT["smart-contract/factory.js"]:::dev
        SRC["smart-contract/Contracts/"]:::dev
        ENV["smart-contract/.env"]:::dev
    end

    UB -->|"1 connect/sign tx"| NI
    NI -->|"UI events"| CID
    CID -->|"2 read/write via Web3"| WEB3
    PRICE --> WEB3
    WEB3 -->|"3 JSON-RPC"| INFURA
    INFURA -->|"4 broadcast/query"| BC

    COMPILE --> BUILD1
    COMPILE --> BUILD2
    DEPLOY --> FACT

    click NI "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/pages/index.js"
    click CID "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/pages/campaign/[id].js"
    click CNEW "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/pages/campaign/new.js"
    click RINDEX "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/pages/campaign/[id]/requests/index.js"
    click RNEW "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/pages/campaign/[id]/requests/new.js"
    click API "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/pages/api/hello.js"
    click NAV "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/components/Navbar.js"
    click FOOT "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/components/Footer.js"
    click DM "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/components/DarkModeSwitch.js"
    click CFG "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/next.config.js"
    click ST1 "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/styles/Home.module.css"
    click ST2 "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/styles/globals.css"
    click PRICE "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/lib/getETHPrice.js"
    click WEB3 "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/smart-contract/web3.js"
    click FACT "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/smart-contract/factory.js"
    click SRC "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/tree/main/smart-contract/Contracts/"
    click BUILD1 "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/smart-contract/build/Campaign.json"
    click BUILD2 "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/smart-contract/build/CampaignFactory.json"
    click COMPILE "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/smart-contract/compile.js"
    click DEPLOY "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/smart-contract/deploy.js"
    click ENV "https://github.com/harsh242/betterfund-crowdfunding-in-blockchain/blob/main/smart-contract/.env"

    classDef ui fill:#ADD8E6,stroke:#000,color:#000
    classDef integration fill:#90EE90,stroke:#000,color:#000
    classDef network fill:#FFA500,stroke:#000,color:#000
    classDef storage fill:#FFFF00,stroke:#000,color:#000
    classDef dev fill:#D3D33,stroke:#000,color:#000
```
