# phucthanh3a/web3-lottery-dapp-reactjs architecture

> Architecture diagram of the GitHub repository phucthanh3a/web3-lottery-dapp-reactjs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/phucthanh3a/web3-lottery-dapp-reactjs
- Repository: https://github.com/phucthanh3a/web3-lottery-dapp-reactjs

## Overview

##### Project type and purpose
- This is a React-based decentralized application (dApp) whose sole purpose is to serve as the front-end for a “Lottery” smart contract on the Ethereum blockchain. Users connect via MetaMask, enter the lottery by sending ETH, and the contract owner picks a winner.

##### File structure
- Top-level files:
- package.json / package-lock.json – lists dependencies (React, web3 or ethers).
- public/index.html, manifest.json, robots.txt – static HTML entry point.
- src/ directory:
- App.js / App.css – bootstraps the React single-page application.
- Home.js – shows manager, players, balance, and a form to enter the lottery.
- PickWinner.js – shows a button for the manager to pick a winner.
- constants.js – exports contract ABI and the deployed contract address.
- index.js, reportWebVitals.js, setupTests.js – standard CRA scaffolding.

##### README for additional insights
- Smart contract source (Lottery.sol) must be compiled in Remix to obtain the ABI.
- Deployment via Injected Provider (MetaMask), copy resulting address into src/constants.js.
- Front-end communicates directly with the deployed contract on localhost:3000.

##### Capturing essential architectural elements
- Distinguish between “read” vs. “write” contract interactions.
- Role of constants.js as the source of truth for ABI & contract address.
- Call out that transaction signing is always mediated by MetaMask.
- User role (Manager vs. Participant) if space allows, to show PickWinner is manager-only.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Browser Boundary
    subgraph "Browser (Client-Side)"
        direction TB
        ReactApp["React SPA"]:::frontend
        MetaMask["MetaMask Provider"]:::provider
        %% Source Code Files
        subgraph "Source Code"
            direction TB
            IndexJS["src/index.js"]:::code
            AppJS["src/App.js"]:::code
            AppCSS["src/App.css"]:::code
            HomeJS["src/Home.js"]:::code
            PickWinnerJS["src/PickWinner.js"]:::code
            ConstantsJS["src/constants.js"]:::config
            AppTest["src/App.test.js"]:::code
            SetupTests["src/setupTests.js"]:::code
            ReportVitals["src/reportWebVitals.js"]:::code
            IndexCSS["src/index.css"]:::code
        end
        %% Public Assets
        subgraph "Public Assets"
            direction TB
            HTML["public/index.html"]:::assets
            Manifest["public/manifest.json"]:::assets
            Robots["public/robots.txt"]:::assets
        end
        %% Dependencies
        subgraph "Dependencies & Scripts"
            direction TB
            PackageJSON["package.json"]:::deps
            PackageLock["package-lock.json"]:::deps
        end
    end

    %% External Tools
    Remix["Remix (Compile & Deploy)"]:::tool

    %% Ethereum Network Boundary
    subgraph "Ethereum Network"
        direction TB
        EthNode["Ethereum Node / Infura"]:::network
        Contract["Lottery Smart Contract"]:::contract
    end

    %% Interactions
    ReactApp -->|"initialize Web3"| MetaMask
    ReactApp -->|"read: getPlayers, balance"| Contract
    ReactApp -->|"write: enter, pickWinner"| MetaMask
    MetaMask -->|"sign & send tx"| EthNode
    EthNode -->|"execute tx"| Contract
    Contract -->|"events & confirmations"| EthNode
    EthNode -->|"tx receipt"| MetaMask
    MetaMask -->|"response"| ReactApp

    %% Deployment flow
    Remix -.->|"compile & deploy"| Contract

    %% Click Events
    click IndexJS "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/src/index.js"
    click AppJS "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/src/App.js"
    click AppCSS "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/src/App.css"
    click HomeJS "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/src/Home.js"
    click PickWinnerJS "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/src/PickWinner.js"
    click ConstantsJS "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/src/constants.js"
    click AppJS "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/src/App.js"
    click HTML "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/public/index.html"
    click Manifest "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/public/manifest.json"
    click Robots "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/public/robots.txt"
    click PackageJSON "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/package.json"
    click PackageLock "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/package-lock.json"
    click AppTest "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/src/App.test.js"
    click SetupTests "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/src/setupTests.js"
    click ReportVitals "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/src/reportWebVitals.js"
    click IndexCSS "https://github.com/phucthanh3a/web3-lottery-dapp-reactjs/blob/main/src/index.css"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#1B4F72,stroke-width:1px
    classDef provider fill:#FCF3CF,stroke:#B7950B,stroke-width:1px
    classDef code fill:#E8DAEF,stroke:#6C3483,stroke-width:1px
    classDef config fill:#F9E79F,stroke:#B9770E,stroke-width:1px
    classDef assets fill:#F5B7B1,stroke:#7B241C,stroke-width:1px
    classDef deps fill:#ABEBC6,stroke:#196F3D,stroke-width:1px
    classDef tool fill:#D5F5E3,stroke:#117864,stroke-width:1px
    classDef network fill:#D5DBDB,stroke:#2C3E50,stroke-width:1px
    classDef contract fill:#A9DFBF,stroke:#145A32,stroke-width:1px
```
