How koya-tech/simple-shop-dapps works
1. The “blockchain” directory contains everything related to smart contracts and blockchain interactions:
• Smart contracts written in Solidity.
• Hardhat configuration and deployment scripts (see hardhat.config.ts, ignition modules like Lock.ts and PurchaseHistory.ts).
• Automated tests for smart contracts.
The “shop-app” directory handles the user-facing frontend
• Built with Next.js, React, and TypeScript.
• Contains pages for products, the shopping cart, and an admin view to manage or view the purchase history.
• Integrates with external services (FakeStore API for product data) and custom hooks such as useBlockchain.ts to interact with the blockchain components.
• Frontend Application (shop-app)
• User Interface: Includes pages for product listing, individual product detail, cart, and admin page.
• UI Components: Such as Header, Footer, ProductTab, etc.
• State Management: Cart store and hooks to manage UI state (e.g., cartStore.ts, use-toast.ts).
• External API Integration: Connecting to FakeStore API to fetch product data.
• Blockchain Interaction: A custom hook (useBlockchain.ts) responsible for wallet interactions (MetaMask connection) and communication with smart contracts.
• Blockchain Backend (blockchain)
• Smart Contracts: Modules like PurchaseHistory and Lock in the ignition directory.
• Hardhat Environment: Configuration, deployment scripts, and local blockchain network setup.
• Test Suite: Testing for contract functionality.
• External Services:
• FakeStore API: Supplies product information.
• MetaMask: Connects users’ wallets to the dapp for authorizing transactions.
B. Map the relationships and interactions:
• The User Interface (shop-app) communicates with:
• The FakeStore API to fetch product listings.
• The blockchain backend through the blockchain hook (useBlockchain.ts) to trigger smart contract interactions.
• The blockchain component:
• Records purchase data on the Ethereum blockchain using smart contracts.
• Provides endpoints (through contract functions) that are invoked by the frontend (web3 calls via MetaMask).
• The admin page in the shop-app uses blockchain queries (or calls) to retrieve the purchase history stored on-chain.
C. Highlight key architectural patterns and design principles:
• Separation of Concerns: The project is clearly divided into a blockchain sub-project and a frontend web application.
• Client-Blockchain Decoupling: The frontend handles user interaction and integrates with the blockchain for persistent storage of purchase data.
• Use of Modern Frameworks: Next.js for SSR/SSG and Hardhat for smart contract management.
• Secure Smart Contract Deployment: Emphasis on security best practices in smart contract design, as noted in the README.
D. Include technologies, frameworks, and libraries:
• Frontend: Next.js, React, Tailwind CSS, TypeScript.
• Blockchain: Solidity, Hardhat, Ethereum.
• External API: FakeStore API.
• Wallet Interaction: MetaMask integration for user authentication and transaction signing.
1. Create high-level blocks for each major module:
• Shop App (Frontend)
• Blockchain (Smart Contracts)
• External Services (FakeStore API, MetaMask)
• Data flow from the frontend to the blockchain (for purchase transactions).
• API calls from the frontend to the FakeStore API.
• Wallet interactions between the user’s browser (via MetaMask) and the blockchain.
• Another for blockchain-related components.
• A third for external dependencies/APIs.
5. Additional notes or sub-components, such as:
• Breakdown of the shop-app pages and components.
• The separation between public pages (product listings, cart) and admin functionalities for viewing purchase history.
6. Deployment and configuration aspects:
• Deployment of smart contracts using Hardhat.
• Environment variables (contract address, ABI) linking the frontend to the deployed contracts.
• Integration point between the blockchain contracts and the web application via a clearly drawn interface.
• That user actions in the shop-app (e.g., clicking “buy”) initiate a series of interactions: fetching product details, connecting wallet via MetaMask, and executing a smart contract transaction.
• Admin view fetching data from the blockchain for a list view of purchase history.
• Including a small inset that shows the local development environment, including Hardhat’s local node, for clarity in understanding the development workflow.