# durgesh2001/servicecrypto architecture

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

- Interactive diagram: https://gitdiagram.com/durgesh2001/servicecrypto
- Repository: https://github.com/durgesh2001/servicecrypto

## Overview

##### Project type and purpose
- This is a full-stack decentralized application (dApp) built on Ethereum.
- Purpose: collect user feedback (“memos”) on services, store them immutably on-chain, and require a small ETH payment per feedback.

##### File structure
- Top level:
- contracts/ (Solidity smart contracts)
- scripts/ (deployment scripts using Hardhat + Ethers.js)
- client/ (React frontend)
- hardhat.config.js, package.json (project configuration)
- client/src/components: Buy.js (payment & feedback UI) and Memos.js (display feedback)
- client/src/contract/serviceCrypto.json: compiled contract ABI & address artifacts
- scripts/deploy.js and scripts/finaldeploy.js: scripts to deploy smart contract to local or test network
- No traditional database – blockchain serves as both ledger and storage.

##### README for additional insights
- Uses Hardhat framework for contract compilation, testing, and deployment
- npx hardhat nod spins up a local Ethereum node
- React app calls smart contract functions via Ethers.js

a. Main components
- React Frontend (Browser)
- Ethers.js Service Layer (in React)
- Ethereum Provider / Wallet (e.g., MetaMask)
- Smart Contract (ServiceCrypto) on Ethereum (local or testnet)
- Hardhat Development Network & Deployment Scripts
- External Ethereum Network (optional: testnet or mainnet)
b. Relationships & data flow
1. User interacts with React UI → enters feedback + ETH payment
2. React’s Ethers.js library connects to Ethereum Provider (MetaMask)
3. Transaction signed and sent to Smart Contract on the blockchain
4. Smart Contract stores memo on-chain and emits events
5. React listens to events or fetches memos via read calls
6. Deployment Scripts (deploy.js/finaldeploy.js) compile & deploy contract via Hardhat → update serviceCrypto.json
c. Architectural patterns & principles
- Separation of concerns: UI vs. on-chain logic vs. deployment
- Stateless frontend; blockchain as single source of truth
- Use of event-driven updates (smart contract events → UI refresh)
d. Key technologies
- Frontend: React.js, HTML/CSS, Ethers.js
- Smart Contracts: Solidity, Hardhat
- Deployment: Node.js scripts, Hardhat plugin
- Ethereum Provider: MetaMask or Hardhat node

- Layer 1 (User & Browser): React components (Buy & Memos)
- Layer 2 (Client Service): Ethers.js / Web3 provider adapter
- Layer 3 (Wallet): MetaMask or Hardhat signer
- Layer 4 (Blockchain Network): Hardhat local node or public testnet
- Layer 5 (Smart Contract): ServiceCrypto.sol with functions buyService() & getMemos()
- Layer 6 (Deployment): scripts/deploy.js → serviceCrypto.json

##### Final advice
- Every interaction path (read vs. write)
- Config files (hardhat.config.js) and artifacts (serviceCrypto.json)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User & Browser"
        UI["React Frontend"]:::frontend
        Buy["Buy.js"]:::frontend
        Memos["Memos.js"]:::frontend
        HTML["index.html"]:::frontend
    end

    subgraph "Client Service"
        Ethers["Ethers.js Service"]:::service
        ABI["serviceCrypto.json"]:::artifacts
    end

    subgraph "Wallet / Provider"
        MetaMask["MetaMask / Hardhat Signer"]:::wallet
    end

    subgraph "Blockchain Network"
        HardhatNode["Hardhat Local Node (JSON-RPC 8545)"]:::blockchain
        Testnet["External Testnet/Mainnet"]:::blockchain
    end

    SmartContract[(ServiceCrypto Smart Contract)]:::contract

    subgraph "Deployment"
        DeployLocal["deploy.js"]:::scripts
        DeployProd["finaldeploy.js"]:::scripts
        HardhatConfig["hardhat.config.js"]:::config
        PackageRoot["package.json"]:::config
        PackageClient["client/package.json"]:::config
    end

    %% Data Flows
    UI -->|renders| HTML
    UI -->|invokes| Buy
    UI -->|invokes| Memos
    Buy -->|calls| Ethers
    Memos -->|calls| Ethers
    Ethers -->|reads/writes| ABI
    Ethers -->|connects to| MetaMask
    MetaMask -->|sign/send tx| HardhatNode
    MetaMask -->|sign/send tx| Testnet
    HardhatNode -->|deploy & calls| SmartContract
    Testnet -->|deploy & calls| SmartContract
    SmartContract -->|emit events| Ethers
    Ethers -->|fetch events| Memos

    DeployLocal -->|deploy via Hardhat| HardhatNode
    DeployProd -->|deploy to network| Testnet
    DeployLocal -->|uses| HardhatConfig
    DeployProd -->|uses| HardhatConfig
    DeployLocal -->|generates| ABI
    DeployProd -->|generates| ABI

    %% Click Events
    click UI "https://github.com/durgesh2001/servicecrypto/blob/main/client/src/App.js"
    click Buy "https://github.com/durgesh2001/servicecrypto/blob/main/client/src/components/Buy.js"
    click Memos "https://github.com/durgesh2001/servicecrypto/blob/main/client/src/components/Memos.js"
    click HTML "https://github.com/durgesh2001/servicecrypto/blob/main/client/public/index.html"
    click ABI "https://github.com/durgesh2001/servicecrypto/blob/main/client/src/contract/serviceCrypto.json"
    click SmartContract "https://github.com/durgesh2001/servicecrypto/blob/main/contracts/ServiceCrypto.sol"
    click DeployLocal "https://github.com/durgesh2001/servicecrypto/blob/main/scripts/deploy.js"
    click DeployProd "https://github.com/durgesh2001/servicecrypto/blob/main/scripts/finaldeploy.js"
    click HardhatConfig "https://github.com/durgesh2001/servicecrypto/blob/main/hardhat.config.js"
    click PackageRoot "https://github.com/durgesh2001/servicecrypto/blob/main/package.json"
    click PackageClient "https://github.com/durgesh2001/servicecrypto/blob/main/client/package.json"

    %% Styling
    classDef frontend fill:#cce5ff,stroke:#007bff,color:#004085
    classDef service fill:#e2e3e5,stroke:#6c757d,color:#383d41
    classDef wallet fill:#ffeeba,stroke:#ffc107,color:#856404
    classDef blockchain fill:#d4edda,stroke:#28a745,color:#155724
    classDef contract fill:#c3e6cb,stroke:#28a745,color:#155724
    classDef scripts fill:#f8f9fa,stroke:#6c757d,color:#343a40
    classDef config fill:#f1f1f1,stroke:#adb5bd,color:#495057
    classDef artifacts fill:#e9d8fd,stroke:#6f42c1,color:#381082
```
