# sidharth0909/disaster-relief-fund architecture

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

- Interactive diagram: https://gitdiagram.com/sidharth0909/disaster-relief-fund
- Repository: https://github.com/sidharth0909/disaster-relief-fund

## Overview

##### Project type and purpose
- This is a full-stack decentralized application (DApp) for blockchain-based crowdfunding.
- Purpose: allow users to view campaigns, connect via MetaMask, donate ETH, and allow admins to create/manage campaigns and withdraw funds.

##### File structure
- Top level:
- blockchain/ – Truffle project with contracts, migrations, build artifacts, Ganache data directory
- public/ & src/ – React single-page-app (SPA) structure
- src/abis/ – compiled contract ABIs for Web3 integration
- src/components/ – React UI components (DisasterFund)
- src/App.js, index.js – app initialization, Web3/provider setup
- Config/build scripts:
- truffle-config.js – network & compiler settings
- package.json – React dependencies and Truffle commands
- ganache-cli invocation stores chain data in blockchain/ganache-data/

##### README insights
- Technology stack: Solidity, Truffle, Ganache, React.js, Web3.js, MetaMask, Chart.js
- Execution flow: Ganache → Truffle migrate → React start → user/admin operations via UI → Web3.js → Smart Contract
- Smart contract functions define the core business logic

##### Main components & their interactions
a. Frontend (React SPA)
- Components: ConnectWallet, CampaignList, DonateButton, AdminDashboard (Chart.js analytics)
- Asset: public/index.html, CSS files, Web3 provider setup in App.js
b. Web3 Layer
- Web3.js library + MetaMask (injected provider)
- src/abis/DisasterReliefFund.json provides contract ABI & network addresses
c. Smart Contract (Solidity)
- DisasterReliefFund.sol deployed via Truffle migrations
- Business logic: createCampaign, donate, withdrawFunds, getCampaigns
d. Blockchain Node
- Ganache (local Ethereum network) persists chain data under blockchain/ganache-data
- Truffle migrations drive deployment to this node
e. External Integrations (optional)
- Infura/Goerli (for testnet deployment) via HDWalletProvider in truffle-config.js
- MetaMask as user’s wallet interface

Interactions:
1. User clicks “Connect Wallet” → MetaMask injects provider → React stores account
2. User/Admin calls action (donate, createCampaign, withdraw) → UI calls Web3.js methods on contract → Transaction → Ganache processes and persists on blockchain
3. UI polls or subscribes to events or calls getCampaigns() to refresh state → Chart.js visualizes progress

##### Architectural patterns & design principles
- Layered architecture: UI layer (React) → Service layer (Web3.js) → Smart contract layer → Data layer (blockchain state)
- Separation of concerns:
- Contract logic isolated in Solidity
- UI and business workflows in React components
- Build/deploy steps in Truffle migrations
- Modularization: React components in src/components, ABIs in src/abis, migrations in blockchain/migrations

- External “MetaMask Wallet”
- (Optional) External “Infura / Testnet” for production/testnet deployment
- Frontend in blue, Blockchain & contracts in green, External services in yellow
d. Labels:
- Call out key technologies: React.js, Web3.js, Truffle, Ganache, Solidity, Chart.js
- Data stores (chain state) vs. off-chain UI state

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "React Frontend" 
        direction TB
        IndexHTML["public/index.html"]:::frontend
        IndexJS["src/index.js"]:::frontend
        AppJS["src/App.js\n(Web3 setup)"]:::frontend
        DisasterFundJS["src/components/DisasterFund.js"]:::frontend
        DisasterFundCSS["src/components/DisasterFund.css"]:::frontend
    end

    %% Web3 Service Layer
    subgraph "Web3 Service" 
        direction TB
        ABISrc["src/abis/DisasterReliefFund.json"]:::service
    end

    %% Smart Contract Layer
    subgraph "Smart Contract (Truffle)" 
        direction TB
        SCBuild["blockchain/build/contracts/DisasterReliefFund.json"]:::contract
        Migration["blockchain/migrations/2_deploy_contracts.js"]:::contract
        TruffleConfig["blockchain/truffle-config.js"]:::contract
    end

    %% Blockchain Node
    subgraph "Blockchain Node (Ganache)" 
        direction TB
        GanacheData["blockchain/ganache-data/"]:::blockchain
    end

    %% Project Config
    subgraph "Project Configuration" 
        direction TB
        PackageJSON["package.json"]:::service
        PackageLock["package-lock.json"]:::service
    end

    %% External Services
    MetaMask["MetaMask Wallet"]:::external
    Infura["Infura / Testnet"]:::external

    %% Interactions
    IndexHTML -->|loads| AppJS
    IndexJS -->|renders| AppJS
    AppJS -->|imports ABI| ABISrc
    AppJS -->|initializes Web3| MetaMask
    AppJS -->|calls methods| SCBuild
    ABISrc -->|ABI data| SCBuild

    Migration -->|deploys to| GanacheData
    TruffleConfig -->|configures| Migration

    SCBuild -->|state updates| GanacheData
    GanacheData -->|eth_call / events| ABISrc
    ABISrc -->|data for UI| AppJS

    MetaMask -->|signs tx| GanacheData
    Infura -->|optional deploy| SCBuild

    %% Click Events
    click IndexHTML "https://github.com/sidharth0909/disaster-relief-fund/blob/master/public/index.html"
    click IndexJS "https://github.com/sidharth0909/disaster-relief-fund/blob/master/src/index.js"
    click AppJS "https://github.com/sidharth0909/disaster-relief-fund/blob/master/src/App.js"
    click DisasterFundJS "https://github.com/sidharth0909/disaster-relief-fund/blob/master/src/components/DisasterFund.js"
    click DisasterFundCSS "https://github.com/sidharth0909/disaster-relief-fund/blob/master/src/components/DisasterFund.css"
    click ABISrc "https://github.com/sidharth0909/disaster-relief-fund/blob/master/src/abis/DisasterReliefFund.json"
    click SCBuild "https://github.com/sidharth0909/disaster-relief-fund/blob/master/blockchain/build/contracts/DisasterReliefFund.json"
    click Migration "https://github.com/sidharth0909/disaster-relief-fund/blob/master/blockchain/migrations/2_deploy_contracts.js"
    click TruffleConfig "https://github.com/sidharth0909/disaster-relief-fund/blob/master/blockchain/truffle-config.js"
    click GanacheData "https://github.com/sidharth0909/disaster-relief-fund/tree/master/blockchain/ganache-data/"
    click PackageJSON "https://github.com/sidharth0909/disaster-relief-fund/blob/master/package.json"
    click PackageLock "https://github.com/sidharth0909/disaster-relief-fund/blob/master/package-lock.json"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#3498DB
    classDef service fill:#FCF3CF,stroke:#F1C40F
    classDef contract fill:#D5F5E3,stroke:#28B463
    classDef blockchain fill:#E8DAEF,stroke:#8E44AD
    classDef external fill:#FDEDEC,stroke:#E74C3C
```
