# goldenglorys/decentralized-ecommerce architecture

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

- Interactive diagram: https://gitdiagram.com/goldenglorys/decentralized-ecommerce
- Repository: https://github.com/goldenglorys/decentralized-ecommerce

## Overview

##### Project Type and Purpose
- This is a full-stack decentralized application (DApp) combining:
- A React/Redux frontend
- An Ethereum smart-contract backend (Truffle framework)
- Off-chain asset storage on IPFS
- Build/deployment automation via webpack, Netlify, and Truffle migrations
- The goal is to let users list, buy, and sell products, host images on IPFS, and—in future—add escrow and off-chain indexing.

##### File Structure
Top-level directories and files reveal the main layers:
- build/contracts/ : Compiled contract JSON (Store.json, Escrow.json)
- contracts/ & migrations/: Solidity source + deployment scripts
- src/ : React application
– src/components/: UI components (Home, About, AddProduct, YourOrders, etc.)
– src/actions/, src/reducers/, src/store/: Redux action → reducer → store pipeline
– src/utils/: web3.js (Ethereum provider), contracts.js (artifact loader), events.js (event listeners), promises.js
- Truffle config files: truffle-config.js, migrations
- Webpack configs: webpack.common.js, webpack.dev.js, webpack.prod.js
- Deployment config: netlify.toml
- dotfiles: .babelrc, ESLint, .gitignore

##### Extract Insights from README
- The frontend uses web3.js to interact with deployed contracts
- Product images are pinned on IPFS; future goal is full-site hosting on IPFS
- Real-time UI updates come from Solidity Events
- Truffle handles compile & migration; Netlify serves the built SPA

##### Main Components & Relationships
a. Frontend (Browser / React SPA)
- React Components render UI
- Redux Store holds application state
- Actions dispatch business events (e.g., “ADD_PRODUCT”, “BUY_PRODUCT”)
- Reducers update state slices (orders, products)
- Utils/web3.js exposes Ethereum provider (MetaMask or HTTP)
- Utils/contracts.js loads build/contracts/*.json ABIs & addresses
- Utils/events.js listens to contract events, dispatches Redux actions
b. Blockchain Layer (Ethereum Network)
- Smart Contracts
– Store.sol: product listing & purchase logic
– (Future) Escrow.sol: escrow/payment release logic
- Truffle Migrations deploy contracts to chosen network
- build/contracts/*.json artifacts represent deployed ABIs & addresses
c. Off-chain Storage (IPFS)
- Product images uploaded to IPFS via IPFS HTTP API
- Frontend fetches image links from IPFS gateways
- (Future) Host built frontend bundle on IPFS
d. Deployment & Build
- Webpack bundles React app (webpack.dev/prod)
- Netlify (via netlify.toml) hosts the static bundle
- Truffle CLI (compile → migrate) deploys contracts

##### Architectural Patterns & Design Principles
- Separation of concerns:
Frontend UI ↔ State management (Redux) ↔ Blockchain calls (web3/utils)
- Event-driven updates: contract Events → utils/events → Redux store → UI
- Modularization: each React feature in its own folder; Redux logic separated
- Immutable state in Redux; single source of truth
- Pipeline for build/deploy: webpack for bundling, Truffle for contracts, Netlify/IPFS for hosting

## Diagram (Mermaid)

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

    %% Frontend Layer
    subgraph "Frontend (React SPA)"
        Entry["index.jsx"]:::ui
        Template["index.html"]:::ui
        App["App.jsx"]:::ui

        subgraph "UI Components"
            Home["Home.jsx"]:::ui
            AddProd["AddProduct.jsx"]:::ui
            YOBuyer["YourOrdersBuyer.jsx"]:::ui
            YOSeller["YourOrdersSeller.jsx"]:::ui
            ProductComp["Product.jsx"]:::ui
        end

        subgraph "Redux"
            ActionsP["products.js"]:::state
            ActionsO["orders.js"]:::state
            Types["types.js"]:::state
            ReducerP["products.js"]:::state
            ReducerO["orders.js"]:::state
            RootRed["index.js"]:::state
            StoreConf["configureStore.js"]:::state
        end

        subgraph "Utils / Web3"
            Web3["web3.js"]:::api
            ContractsUtil["contracts.js"]:::api
            Events["events.js"]:::api
            Promises["promises.js"]:::api
        end
    end

    %% Blockchain Layer
    subgraph "Blockchain Layer"
        subgraph "Smart Contracts"
            StoreSol["Store.sol"]:::blockchain
            EscrowSol["Escrow.sol"]:::blockchain
        end
        Migrate1["1_initial_migration.js"]:::blockchain
        Migrate2["2_deploy_contracts.js"]:::blockchain
        Artifacts["build/contracts"]:::blockchain
        EthereumNet["Ethereum Network"]:::blockchain
    end

    %% External Services
    IPFS["IPFS Storage"]:::external
    Netlify["Netlify"]:::external
    Webpack["Webpack"]:::external
    TruffleCLI["Truffle CLI"]:::external
    Metamask["MetaMask/HTTP Provider"]:::external

    %% User to Frontend
    User --> Entry
    Entry --> Template
    Entry --> App

    %% Component Hierarchy and Actions
    App --> Home
    App --> AddProd
    App --> YOBuyer
    App --> YOSeller
    App --> ProductComp

    Home -->|"dispatch"| ActionsP
    AddProd -->|"dispatch"| ActionsP
    YOBuyer -->|"dispatch"| ActionsO
    YOSeller -->|"dispatch"| ActionsO
    ProductComp -->|"dispatch"| ActionsP

    ActionsP --> Types
    ActionsO --> Types
    Types --> ReducerP
    Types --> ReducerO
    ActionsP --> ReducerP
    ActionsO --> ReducerO

    ReducerP --> RootRed
    ReducerO --> RootRed
    RootRed --> StoreConf

    %% Store uses utils
    StoreConf -.->|"uses"| Web3
    StoreConf -.->|"uses"| ContractsUtil
    StoreConf -.->|"uses"| Events
    StoreConf -.->|"uses"| Promises

    %% Blockchain interactions
    Web3 -->|RPC calls| EthereumNet
    ContractsUtil -->|loads ABI| Artifacts
    Events -->|listens to| EthereumNet
    EthereumNet -->|emits events| Events

    %% Migrations and Artifacts
    TruffleCLI --> Migrate1 --> Migrate2 --> StoreSol
    StoreSol --> Artifacts
    EscrowSol --> Artifacts

    %% Off-chain Storage Flow
    AddProd -->|upload image| IPFS
    ProductComp -->|fetch image| IPFS

    %% Build & Deployment
    Webpack --> Entry
    Webpack --> Template
    Webpack --> App
    Webpack -->|bundle| Netlify
    Netlify -->|serves| User

    %% External Provider
    App --> Metamask

    %% Click Events
    click Entry "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/index.jsx"
    click Template "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/index.html"
    click App "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/components/App.jsx"
    click Home "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/components/home/Home.jsx"
    click AddProd "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/components/add-product/AddProduct.jsx"
    click YOBuyer "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/components/your-orders-buyer/YourOrdersBuyer.jsx"
    click YOSeller "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/components/your-orders-seller/YourOrdersSeller.jsx"
    click ProductComp "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/components/product/Product.jsx"
    click ActionsP "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/actions/products.js"
    click ActionsO "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/actions/orders.js"
    click Types "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/actions/types.js"
    click ReducerP "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/reducers/products.js"
    click ReducerO "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/reducers/orders.js"
    click RootRed "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/reducers/index.js"
    click StoreConf "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/store/configureStore.js"
    click Web3 "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/utils/web3.js"
    click ContractsUtil "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/utils/contracts.js"
    click Events "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/utils/events.js"
    click Promises "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/utils/promises.js"
    click StoreSol "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/contracts/Store.sol"
    click EscrowSol "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/contracts/Escrow.sol"
    click Migrate1 "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/migrations/1_initial_migration.js"
    click Migrate2 "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/migrations/2_deploy_contracts.js"
    click Artifacts "https://github.com/goldenglorys/decentralized-ecommerce/tree/main/build/contracts/"
    click TruffleCLI "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/truffle-config.js"
    click Webpack "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/webpack.common.js"
    click Webpack "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/webpack.dev.js"
    click Webpack "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/webpack.prod.js"
    click Netlify "https://github.com/goldenglorys/decentralized-ecommerce/blob/main/src/netlify.toml"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0050A0,stroke-width:1px
    classDef state fill:#DFFFE0,stroke:#2B8A00,stroke-width:1px
    classDef api fill:#FFE8B0,stroke:#A05A00,stroke-width:1px
    classDef blockchain fill:#FFE0E0,stroke:#A00000,stroke-width:1px
    classDef external fill:#F0E0FF,stroke:#8000A0,stroke-width:1px
```
