How goldenglorys/decentralized-ecommerce works
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