How sosane/agriculture-product-tracking-chain works
Project type and purpose
• AgriChain is a full-stack, blockchain-enabled supply-chain tracking system for agricultural products.
• It consists of:
• A React/Vite frontend (customer/admin dashboards, QR scanning, data visualization)
• A Node.js/Express backend exposing a REST API and managing sessions
• A PostgreSQL database for user/product metadata
• Solidity smart contracts deployed via Hardhat on an Ethereum testnet
• QR‐code based verification against on‐chain data
File structure
Top-level directories:
• agrichain-frontend-react/agrichain-frontend → React/Vite UI
• agrichain-backend/ → Express server, domain-driven controllers, services
• agrichain-database/ → SQL scripts for schema and initialization
• agrichain-smartcontract/ → Solidity contracts, Hardhat config, deployment scripts
Other files: LICENSE, root README, assets (screenshots)
Key architectural insights from README
• Frontend runs on port 5173, interacts with backend (port 5000) via REST + directly with blockchain through Ethers.js
• Backend connects to PostgreSQL and to Ethereum node (Hardhat) to call contracts
• Smart contracts handle ownership transfer, certification, supply chain events
• PostgreSQL stores off-chain metadata, sessions, user accounts
Main components
a. Clients & UI
• Web Browser / React App
• QR Scanner / Mobile camera (web)
b. Frontend Layer
• React pages & components
• Service modules (authService, productService, contractService)
c. Backend Layer
• Express server (index.js, server.js)
• Domain modules (User, Product controllers/routes/models)
• ContractServices and utility modules
d. Persistence & On-chain
• PostgreSQL database (agrichain schema)
• Ethereum network (Hardhat local node)
• Smart contracts (Deployed address)
e. External services
• MetaMask / Wallet
• CORS origin (frontend → backend)
Relationships & data flows
• User interacts with React UI → REST API calls to backend endpoints → controllers invoke domain services → queries to PostgreSQL or on-chain transactions via contractServices → responses back to UI.
• For blockchain reads/writes:
• Frontend contractService uses Ethers.js to call smart contracts on Ethereum node.
• Backend contractServices uses admin private key to send transactions or read events.
• QR Scanner triggers frontend to fetch on-chain product history, calling either backend or directly contractService.
Architectural patterns & principles
• Separation of concerns: UI / API / data / blockchain layers
• Domain-driven design in backend (per-domain controllers/models/routes)
• Single-page application with REST + direct blockchain calls
• Immutable event sourcing on blockchain vs. mutable relational storage
Detailed elements to capture
• Frontend: service modules, pages, hooks
• Backend: env/config, domain folders, utils/generator
• Smart contracts: artifacts vs. source, deploy script
• Database: init.sql, schema.sql
• Environment variables (e.g., CONTRACT_ADDRESS, BLOCKCHAIN_PROVIDER_URL)