# anhhuy007/nftify architecture

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

- Interactive diagram: https://gitdiagram.com/anhhuy007/nftify
- Repository: https://github.com/anhhuy007/nftify

## Overview

##### Project type and purpose
- NFTify is a React-based Single Page Application (SPA) built with Vite and Tailwind CSS.
- It serves as a decentralized application (DApp) frontend for interacting with an NFT Marketplace smart contract on Ethereum, integrating with MetaMask and external services (IPFS, Etherscan, and a separate backend server).

##### File structure
- Top-level: configuration files (.eslintrc, tailwind.config.js, vite.config.js), public assets, contract ABI (contract/NFTMarketplace.json), and frontend entrypoints (index.html, src/).
- src/ subdivides into:
· components/ — reusable UI elements and page-specific widgets
· pages/ — route-driven React pages (home, marketplace, NFT details, auth flows, settings)
· layouts/ — layout wrappers (AuthLayout, MarketplaceLayout, RootLayout)
· context/ — React Context providers (Auth, Cart, Wallet)
· handlers/ and services/ — abstraction for HTTP or blockchain calls (Endpoints.js, AuthHandler.js, NFTService.js, IpfsService.js)
· routes/ — client-side routing logic (PrivateRoute, index.jsx)
- No backend code here; the repo references a separate server.

##### Extract insights from the README
- Purpose: connect MetaMask, validate network, perform blockchain transactions (buy/sell/transfer NFTs), view transaction history.
- Tech stack: React, Vite, Tailwind, Solidity (contract ABI), Node.js/MongoDB backend (external), IPFS, Etherscan API.

##### Main components
a. Client (Browser)
- React SPA (pages, components, layouts).
- Context Providers (manage auth state, cart state, wallet state).
- Services & Handlers (NFTService, IpfsService, AuthHandler, Endpoints).
b. MetaMask Extension
- Provides Web3 provider, wallet address, network information, transaction signing.
c. Ethereum Network
- Smart contract (NFTMarketplace) deployed on a specific chain.
d. External Backend Server
- REST API for off-chain data (users, collections metadata), MongoDB database.
e. IPFS Network
- Stores and retrieves NFT media assets.
f. Etherscan API
- Fetches detailed transaction and block information.

##### Relationships and data flows
- User clicks in the UI → React component calls a Context or Service.
- For blockchain operations:
· Service picks up the contract ABI → metaMask.request() → Ethereum RPC endpoint → contract interaction (buy/sell/transfer).
· MetaMask pops up for signature → transaction submitted to Ethereum.
- For metadata or user data:
· Handler or Service issues HTTP request → External backend server → MongoDB → returns JSON metadata (e.g., collection info).
- For NFT media:
· Service calls IPFS gateway → retrieves image/video.
- For transaction details/history:
· Service calls Etherscan API → returns transaction logs → UI displays.

##### Architectural patterns and design principles
- Component-based UI (React) separated into Presentational and Container components.
- Context API for cross-cutting concerns (Auth, Wallet, Cart).
- Service/Handler layer abstracts external calls (blockchain RPC, REST API, IPFS).
- Layout + Route segregation for public vs authenticated flows (PrivateRoute).
- Single responsibility per module: UI, state management, data fetching.

- UI Layer (components/pages/layouts)
- State Layer (AuthProvider, WalletProvider, CartProvider)
- Service Layer (NFTService, IpfsService, Endpoints, AuthHandler)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User["User"]:::external

    %% React SPA
    subgraph "React SPA"
        direction TB

        EntryPoints["Entrypoints"]:::frontend

        subgraph "UI Layer"
            direction TB
            Components["Reusable UI Components"]:::frontend
            Pages["Route-driven Pages"]:::frontend
            subgraph "Layouts"
                AuthLayout["AuthLayout"]:::frontend
                MarketplaceLayout["MarketplaceLayout"]:::frontend
                RootLayout["RootLayout"]:::frontend
            end
        end

        subgraph "State Layer"
            direction TB
            AuthProvider["AuthProvider"]:::frontend
            WalletProvider["WalletProvider"]:::frontend
            CartProvider["CartProvider"]:::frontend
        end

        subgraph "Routing"
            direction TB
            RoutesIndex["Route Definitions"]:::frontend
            PrivateRoute["Protected Routes"]:::frontend
        end

        subgraph "Service Layer"
            direction TB
            NFTService["NFTService"]:::frontend
            IpfsService["IpfsService"]:::frontend
            Endpoints["Endpoints"]:::frontend
            AuthHandler["AuthHandler"]:::frontend
        end

        subgraph "Utilities"
            direction TB
            Utils["General Utilities"]:::frontend
            ScrollToTop["ScrollToTop"]:::frontend
        end
    end

    %% Third-party and networks
    MetaMask["MetaMask Extension"]:::blockchain
    Ethereum["Ethereum Network"]:::blockchain
    Contract[(NFTMarketplace.json)]:::frontend
    IPFS["IPFS Network"]:::network
    Etherscan["Etherscan API"]:::network
    Backend["External Backend Server"]:::backend
    MongoDB[(MongoDB)]:::backend

    %% Connections
    User -->|uses| EntryPoints
    EntryPoints -->|renders UI| Components
    EntryPoints -->|renders UI| Pages

    Components -->|wraps with| AuthProvider
    Pages -->|accesses| WalletProvider
    Pages -->|updates| CartProvider

    RoutesIndex -->|checks| PrivateRoute
    EntryPoints -->|loads routes| RoutesIndex

    AuthProvider -->|provides to| Components
    WalletProvider -->|provides to| Components
    CartProvider -->|provides to| Components

    Components -->|calls| NFTService
    Components -->|calls| IpfsService
    Components -->|calls| Endpoints
    Components -->|calls| AuthHandler
    Components -->|uses| Utils
    Components -->|uses| ScrollToTop

    NFTService -->|"JSON-RPC"| MetaMask
    MetaMask -->|"signs tx"| NFTService
    NFTService -->|loads ABI| Contract
    Contract -->|deployed on| Ethereum
    Ethereum -->|"tx receipt"| NFTService

    IpfsService -->|"IPFS GET"| IPFS
    NFTService -->|"fetch history"| Etherscan

    Endpoints -->|"HTTP/REST"| Backend
    AuthHandler -->|"HTTP/REST"| Backend
    Backend -->|reads/writes| MongoDB
    Backend -->|responds| Endpoints
    Backend -->|responds| AuthHandler

    %% Click Events
    click EntryPoints "https://github.com/anhhuy007/nftify/blob/master/index.html"
    click EntryPoints "https://github.com/anhhuy007/nftify/blob/master/src/main.jsx"
    click EntryPoints "https://github.com/anhhuy007/nftify/blob/master/src/App.jsx"
    click Components "https://github.com/anhhuy007/nftify/tree/master/src/components/"
    click Pages "https://github.com/anhhuy007/nftify/tree/master/src/pages/"
    click AuthLayout "https://github.com/anhhuy007/nftify/blob/master/src/layouts/AuthLayout.jsx"
    click MarketplaceLayout "https://github.com/anhhuy007/nftify/blob/master/src/layouts/MarketplaceLayout.jsx"
    click RootLayout "https://github.com/anhhuy007/nftify/blob/master/src/layouts/RootLayout.jsx"
    click AuthProvider "https://github.com/anhhuy007/nftify/blob/master/src/context/AuthProvider.jsx"
    click WalletProvider "https://github.com/anhhuy007/nftify/blob/master/src/context/WalletProvider.jsx"
    click CartProvider "https://github.com/anhhuy007/nftify/blob/master/src/context/CartProvider.jsx"
    click NFTService "https://github.com/anhhuy007/nftify/blob/master/src/services/NFTService.js"
    click IpfsService "https://github.com/anhhuy007/nftify/blob/master/src/services/IpfsService.js"
    click Endpoints "https://github.com/anhhuy007/nftify/blob/master/src/handlers/Endpoints.js"
    click AuthHandler "https://github.com/anhhuy007/nftify/blob/master/src/handlers/AuthHandler.js"
    click RoutesIndex "https://github.com/anhhuy007/nftify/blob/master/src/routes/index.jsx"
    click PrivateRoute "https://github.com/anhhuy007/nftify/blob/master/src/routes/PrivateRoute.jsx"
    click Contract "https://github.com/anhhuy007/nftify/blob/master/contract/NFTMarketplace.json"
    click Utils "https://github.com/anhhuy007/nftify/blob/master/src/lib/utils.js"
    click ScrollToTop "https://github.com/anhhuy007/nftify/blob/master/src/utils/ScrollToTop.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef backend fill:#E6FFEA,stroke:#228B22,color:#228B22;
    classDef blockchain fill:#FFE8D0,stroke:#D2691E,color:#D2691E;
    classDef network fill:#F0F0F0,stroke:#808080,color:#808080;
    classDef external fill:#FFFFFF,stroke:#000000,color:#000000;
```
