# ganesh1583/piggybank-project architecture

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

- Interactive diagram: https://gitdiagram.com/ganesh1583/piggybank-project
- Repository: https://github.com/ganesh1583/piggybank-project

## Overview

##### Project type and purpose
- This is a full-stack Ethereum dApp (“piggybank-project”) comprising:
- An on-chain component (Solidity smart contract)
- Off-chain tooling for deployment and testing (Hardhat-based scripts)
- A single-page React/Vite frontend that interacts with the contract via Ethers.js and MetaMask

##### File structure
- Top-level directories:
- backend/ — Hardhat environment for compiling, testing, and deploying the EtherPiggyBank.sol contract
- frontend/ — Vite + React application that provides UI and Ethers.js integration
- Key backend subdirectories:
- contracts/ — contains EtherPiggyBank.sol
- scripts/ — deploy.js for deploying to Sepolia
- test/ — JavaScript tests against the contract
- hardhat.config.js — network configuration, compiler settings
- Key frontend subdirectories:
- src/ — React components (App.jsx, main.jsx), CSS, and an autogenerated ABI/address file (etherPiggyBank.js)
- public/index.html — single HTML entry point
- vite.config.js — build setup

##### README insights
- The README describes:
- Core functionality (deposit/withdraw Ether)
- Stack (Solidity, Hardhat, React, Vite, Ethers.js)
- Workflow (install, deploy to Sepolia, run frontend, MetaMask config)
- No external database: the blockchain itself is the persistent data store

- User’s Web Browser + MetaMask extension
- Frontend Application (React/Vite)
- Ethers.js library
- Ethereum Node or JSON-RPC provider (e.g., Infura/Alchemy or local Hardhat node)
- Smart Contract (EtherPiggyBank.sol) deployed on Sepolia Testnet
- Hardhat Toolkit (for compile, test, deploy) – optional to include dev pipeline
b. Relationships and interactions:
- Browser ←→ Frontend: HTTP(S) to load React assets
- Frontend ↔ Ethers.js: JavaScript API calls to prepare transactions/calls
- Ethers.js ↔ MetaMask: Request user signature for transactions
- MetaMask ↔ Ethereum Node (Sepolia): Broadcast signed TXs to network
- Ethereum Node ↔ Smart Contract: Execute deposit/withdraw calls and return transaction receipts/state
- Hardhat scripts → Ethereum Node: Deployment step (one-way)
c. Architectural patterns/design principles:
- Separation of concerns: UI layer vs. blockchain logic
- Client-side heavy: no centralized backend server, purely peer-to-peer with blockchain
- Modular contract and ABI generation for front-end integration
d. Key technologies/frameworks:
- Solidity (contract language)
- Hardhat (development, testing, deployment)
- React + Vite (frontend UI and bundler)
- Ethers.js (blockchain interaction library)
- MetaMask (user wallet for signing transactions)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User-side components
    subgraph "User Side"
        direction TB
        Browser["Web Browser"]:::frontend-blue
        Frontend["React/Vite Frontend"]:::frontend-blue
        EthersJS["Ethers.js Library"]:::frontend-blue
        MetaMask["MetaMask Extension"]:::frontend-blue
    end

    %% Blockchain-side components
    subgraph "Blockchain Network"
        direction TB
        EthereumNode["Ethereum Node (Sepolia)"]:::blockchain-green
        SmartContract["EtherPiggyBank.sol"]:::blockchain-green
    end

    %% Development tools
    subgraph "Dev Tools"
        direction TB
        HardhatCLI["Hardhat CLI"]:::dev-gray
        HardhatConfig["hardhat.config.js"]:::dev-gray
        DeployScript["deploy.js"]:::dev-gray
        TestSuite["Lock.js"]:::dev-gray
        BackendPackage["package.json"]:::dev-gray
    end

    %% Frontend file components
    subgraph "Frontend Files"
        direction TB
        AppComponent["App.jsx"]:::frontend-blue
        EntryPoint["main.jsx"]:::frontend-blue
        Stylesheet["App.css"]:::frontend-blue
        ABIFile["etherPiggyBank.js"]:::frontend-blue
        FrontendHTML["index.html"]:::frontend-blue
        ViteConfig["vite.config.js"]:::frontend-blue
        FrontendPackage["package.json"]:::frontend-blue
    end

    %% Runtime interactions
    Browser -->|"loads assets"| Frontend
    Frontend -->|"calls API"| EthersJS
    EthersJS -->|"requests signature"| MetaMask
    MetaMask -->|"broadcasts signed transaction"| EthereumNode
    EthereumNode -->|"executes contract call"| SmartContract
    Frontend -->|"reads state via JSON-RPC"| EthereumNode

    %% Deployment and testing workflow
    HardhatCLI -->|"deploys contract"| EthereumNode
    HardhatCLI -->|"uses config"| HardhatConfig
    HardhatCLI -->|"runs tests"| TestSuite

    %% File structure relationships
    Frontend --> AppComponent
    Frontend --> EntryPoint
    Frontend --> Stylesheet
    Frontend --> ABIFile
    Frontend --> FrontendHTML
    Frontend --> ViteConfig
    Frontend --> FrontendPackage

    %% Click events
    click SmartContract "https://github.com/ganesh1583/piggybank-project/blob/main/backend/contracts/EtherPiggyBank.sol"
    click HardhatConfig "https://github.com/ganesh1583/piggybank-project/blob/main/backend/hardhat.config.js"
    click DeployScript "https://github.com/ganesh1583/piggybank-project/blob/main/backend/scripts/deploy.js"
    click TestSuite "https://github.com/ganesh1583/piggybank-project/blob/main/backend/test/Lock.js"
    click AppComponent "https://github.com/ganesh1583/piggybank-project/blob/main/frontend/src/App.jsx"
    click EntryPoint "https://github.com/ganesh1583/piggybank-project/blob/main/frontend/src/main.jsx"
    click Stylesheet "https://github.com/ganesh1583/piggybank-project/blob/main/frontend/src/App.css"
    click ABIFile "https://github.com/ganesh1583/piggybank-project/blob/main/frontend/src/contracts/etherPiggyBank.js"
    click FrontendHTML "https://github.com/ganesh1583/piggybank-project/blob/main/frontend/index.html"
    click ViteConfig "https://github.com/ganesh1583/piggybank-project/blob/main/frontend/vite.config.js"
    click FrontendPackage "https://github.com/ganesh1583/piggybank-project/blob/main/frontend/package.json"
    click BackendPackage "https://github.com/ganesh1583/piggybank-project/blob/main/backend/package.json"

    %% Styles
    classDef frontend-blue fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef blockchain-green fill:#90EE90,stroke:#333,stroke-width:1px
    classDef dev-gray fill:#D3D3D3,stroke:#333,stroke-width:1px
```
