# dappuniversity/decentratwitter architecture

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

- Interactive diagram: https://gitdiagram.com/dappuniversity/decentratwitter
- Repository: https://github.com/dappuniversity/decentratwitter

## Overview

##### Main Components
- Smart Contract Layer:
- “contracts” directory containing Solidity code.
- Role of smart contracts in managing the decentralized aspects (e.g., tweet data, user interactions).
- Blockchain Development and Deployment:
- Hardhat development environment (hardhat.config.js, local blockchain node).
- Deploy script in the “scripts” directory that migrates contracts.
- Local blockchain (simulated network when using npx hardhat node, with chainID 31337).
- Frontend Application:
- “public” folder for static HTML (index.html, manifest.json) and the “src” folder for React components (App.js, Home.js, Profile.js).
- Use of React Router for navigation between pages.
- Blockchain Interaction:
- Ethers.js component that bridges the frontend to the smart contracts via blockchain calls.
- Testing Environment:
- Briefly mention the “test” folder where the smart contract tests are organized.
- External Dependencies:
- IPFS for metadata storage, as per the README, which may be considered an external service storing off-chain data.

##### Relationships & Data Flow
- User actions in the frontend triggering events that interact with Ethers.js.
- Ethers.js sending transactions or queries to the smart contract layer on the blockchain.
- Smart contract responses/transaction confirmations flowing back through Ethers.js to the frontend.
- Off-chain data flow to/from IPFS (e.g., metadata storage related to tweets).
- That the Hardhat node simulates the blockchain environment, letting developers deploy and test contracts locally.

##### Architectural Patterns & Design Principles
- A clear separation of concerns:
- Frontend (UI, routing, state management) versus blockchain (contracts, tests, deployments).
- That the project follows a multi-tier architecture:
- Presentation Layer (React frontend)
- Blockchain/Smart Contract Layer (Solidity contracts executed on a private Hardhat network)
- Integration Layer (Ethers.js that acts as a bridge)
- Mention that testing is handled independently for smart contract logic through Hardhat’s testing framework.

##### Technical Stack and Tools
- Specific technologies alongside each component:
- Solidity (Smart Contracts)
- Hardhat (Development blockchain, deploy script, config)
- React (Frontend framework, hosted in the src/public folders)
- Ethers.js (Blockchain interaction library)
- IPFS (Off-chain storage for metadata)
- React Router (Navigation within the frontend)
- NodeJS and npm (Project dependency management and script execution)

##### Final Recommendations
- Detail each component to capture both the development (Hardhat node, deploy script, test suite) and runtime (React app, wallet connection via Metamask) aspects.
- Tailor the explanation of component interactions to both development and user usage scenarios – from contract deployment, testing, to frontend interactions.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    U["User"]:::userStyle

    %% Frontend Layer
    subgraph "Frontend Layer (React App)"
        F1["Static Files (public/)"]:::frontend
        F2["React Components (src/)"]:::frontend
        F3["Routing (React Router)"]:::frontend
    end

    %% Integration Layer
    subgraph "Integration Layer"
        I1["Blockchain Interaction (Ethers.js)"]:::integration
        I2["Contract Data (src/contractsData/)"]:::integration
    end

    %% Blockchain Layer
    subgraph "Blockchain Layer (Smart Contracts & Deployment)"
        B1["Smart Contracts (Solidity, contracts/)"]:::blockchain
        B2["Hardhat Configuration (hardhat.config.js)"]:::blockchain
        B3["Deploy Script (scripts/deploy.js)"]:::blockchain
        B4["Local Blockchain Node (ChainID:31337)"]:::blockchain
        B5["Testing Environment (test/)"]:::blockchain
    end

    %% External Dependency
    IPFS["Off-chain Storage (IPFS)"]:::external

    %% Data Flow Connections
    U -->|"initiates action"| F2
    F2 -->|"navigates via"| F3
    F2 -->|"requests blockchain call"| I1
    I1 -->|"submits transaction"| B1
    B1 -->|"executes on"| B4
    B4 -->|"returns confirmation"| I1
    I1 -->|"updates UI"| F2
    F2 -->|"fetches metadata from"| IPFS
    B1 -->|"stores/retrieves metadata"| IPFS
    B2 -->|"configures"| B1
    B3 -->|"deploys"| B1
    B5 -->|"validates contracts"| B1
    I2 -->|"provides contract data to"| I1

    %% Click Events
    click B1 "https://github.com/dappuniversity/decentratwitter/tree/main/contracts/"
    click B2 "https://github.com/dappuniversity/decentratwitter/blob/main/hardhat.config.js"
    click B3 "https://github.com/dappuniversity/decentratwitter/blob/main/scripts/deploy.js"
    click F1 "https://github.com/dappuniversity/decentratwitter/tree/main/public/"
    click F2 "https://github.com/dappuniversity/decentratwitter/tree/main/src/"
    click I2 "https://github.com/dappuniversity/decentratwitter/tree/main/src/contractsData/"
    click B5 "https://github.com/dappuniversity/decentratwitter/tree/main/test/"

    %% Styles
    classDef frontend fill:#a3d2ca,stroke:#000,stroke-width:1px;
    classDef integration fill:#f7d794,stroke:#000,stroke-width:1px;
    classDef blockchain fill:#f38181,stroke:#000,stroke-width:1px;
    classDef external fill:#bde0fe,stroke:#000,stroke-width:1px;
    classDef userStyle fill:#ffcccb,stroke:#000,stroke-width:1px;
```
