# ngotrieuhao/web3-dapps architecture

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

- Interactive diagram: https://gitdiagram.com/ngotrieuhao/web3-dapps
- Repository: https://github.com/ngotrieuhao/web3-dapps

## Overview

##### Main Components
- Client/User Interface:
- Represented by React components in the “src” directory (App.jsx, and individual components such as Account.jsx, ERC20Token.jsx, ReadContract.jsx, SendTransaction.jsx, and WalletOptions.jsx).
- These components are responsible for rendering the UI and capturing user interactions.

- Web3/Blockchain Interaction Layer:
- Components like Web3Provider.jsx which wraps the application to provide blockchain connectivity and context across components.

- Styling & Build Infrastructure:
- Use of Tailwind CSS (configured via tailwind.config.js) for UI styling and Vite (via vite.config.js) as the build tool.
- Build artifacts (represented in the “dist” folder) that are a product of the build pipeline.

- External Services:
- MetaMask Wallet: Indicate that the user’s MetaMask is the gateway for signing transactions and authenticating blockchain actions.
- Blockchain Network: Show interaction with external blockchain services (Ethereum network and BNB transactions) where the DApp sends/reads data.

- Assets and Static Files:

##### Relationships and Data Flow
- User Interaction Flow:
- This page loads the bundled JavaScript and CSS produced by Vite and points into the React application (the “src” folder).

- Component Communication:
- The main App component acts as an orchestrator, integrating various sub-components that handle user account details, token transactions, and contract interactions.

- Blockchain Integration:
- Data flows from the user’s action (via MetaMask) through the Web3Provider, which then communicates with the blockchain via Ethereum libraries (wagmi, viem).

##### Architectural Patterns and Design Principles
- Component-Based Architecture:
- The separation between UI components and blockchain interaction logic (encapsulated within Web3Provider and hook-based libraries) reflects clear modularization.

- Unidirectional Data Flow:
- How each component only triggers upward (or context-based) actions that eventually change state, leading to re-rendered UI updates.

- Integration with External Services:
- Clearly push the external services (MetaMask & Blockchain networks) as externally managed components which interact with the core client via specific API and hook integrations.

## Diagram (Mermaid)

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

    %% Client Layer
    subgraph "Client Layer"
        B["Browser/Client (index.html)"]:::client
    end

    %% React Application Layer
    subgraph "React Application"
        A["Main App (App.jsx)"]:::client
        subgraph "UI Components"
            ACC["Account.jsx"]:::client
            ERC["ERC20Token.jsx"]:::client
            RC["ReadContract.jsx"]:::client
            STX["SendTracsaction.jsx"]:::client
            WO["WalletOptions.jsx"]:::client
        end
    end

    %% Blockchain Interaction Layer
    subgraph "Blockchain Interaction"
        WP["Web3 Provider (Web3Provider.jsx)"]:::provider
        LIB["Ethereum Libraries (wagmi,viem,etc)"]:::provider
    end

    %% External Services
    subgraph "External Services"
        MM["MetaMask Wallet"]:::external
        BC["Blockchain Network"]:::external
    end

    %% Build & Assets
    subgraph "Build & Assets"
        V["Vite Build (vite.config.js)"]:::build
        TW["Tailwind CSS (tailwind.config.js)"]:::build
        BA["Build Artifacts (dist)"]:::build
        DS["Dist Assets (dist/assets)"]:::build
        PA["Public Assets (public)"]:::build
        SA["Static Assets (src/assets)"]:::build
    end

    %% Data Flow Arrows
    U -->|"initiates"| B
    B -->|"loads"| A

    A -->|"renders"| ACC
    A -->|"renders"| ERC
    A -->|"renders"| RC
    A -->|"renders"| STX
    A -->|"renders"| WO

    A -->|"triggers blockchain action"| WP
    WP -->|"utilizes"| LIB
    WP -->|"prompts"| MM
    MM -->|"broadcasts to"| BC
    BC -->|"sends update to"| WP
    WP -->|"updates state for"| A

    %% Build & Assets Interactions
    B -->|"loads assets from"| PA
    V -->|"builds"| BA
    BA -->|"contains"| DS
    TW -->|"styles"| A

    %% Click Events
    click A "https://github.com/ngotrieuhao/web3-dapps/blob/main/src/App.jsx"
    click ACC "https://github.com/ngotrieuhao/web3-dapps/blob/main/src/components/Account.jsx"
    click ERC "https://github.com/ngotrieuhao/web3-dapps/blob/main/src/components/ERC20Token.jsx"
    click RC "https://github.com/ngotrieuhao/web3-dapps/blob/main/src/components/ReadContract.jsx"
    click STX "https://github.com/ngotrieuhao/web3-dapps/blob/main/src/components/SendTracsaction.jsx"
    click WO "https://github.com/ngotrieuhao/web3-dapps/blob/main/src/components/WalletOptions.jsx"
    click WP "https://github.com/ngotrieuhao/web3-dapps/blob/main/src/Web3Provider.jsx"
    click V "https://github.com/ngotrieuhao/web3-dapps/blob/main/vite.config.js"
    click TW "https://github.com/ngotrieuhao/web3-dapps/blob/main/tailwind.config.js"
    click BA "https://github.com/ngotrieuhao/web3-dapps/tree/main/dist"
    click PA "https://github.com/ngotrieuhao/web3-dapps/tree/main/public"
    click SA "https://github.com/ngotrieuhao/web3-dapps/tree/main/src/assets"

    %% Styles
    classDef client fill:#a9d0f5,stroke:#333,stroke-width:2px;
    classDef provider fill:#a3f7bf,stroke:#333,stroke-width:2px;
    classDef external fill:#f7a3a3,stroke:#333,stroke-width:2px;
    classDef build fill:#f3e573,stroke:#333,stroke-width:2px;
```
