A full-stack Web3 application for decentralized decision management with on-chain accountability πβ¨
- π― Executive Summary
- π Architecture
- π» Technology Stack
- π Project Structure
- β¨ Core Features
- π Data Models
- π Smart Contracts
- π Installation & Setup
- π Deployment
- π Security
- π Troubleshooting
- π€ Contributing
Echo Chain bridges traditional web applications with blockchain technology, providing secure, accountable decision management where critical decisions are recorded on-chain for immutability and transparency.
- π Hybrid Architecture: Off-chain database + on-chain immutability
- π Decision Management: Create, version, comment, and finalize with audit trails
- βοΈ Blockchain Integration: Smart contracts, wallet auth, transaction management
- π’ Enterprise-Ready: TypeScript, modular architecture, production patterns
- ποΈ DAO governance and proposals
- π’ Corporate decision documentation
- β Audit-ready compliance systems
- π³οΈ Transparent voting platforms
- π¨ NFT-based decision proofs
Frontend Layer: Next.js App Router, React Components, TailwindCSS with TypeScript for type safety
Application Layer: Server Actions, Custom Hooks, and Utility functions handle business logic
Data Layer:
- Supabase provides PostgreSQL database and authentication
- Ethereum blockchain stores immutable decision hashes via smart contracts
Decision Creation Flow:
User creates decision β Saved as draft in Supabase β User finalizes decision β Generate SHA-256 hash β User signs with wallet β Submit transaction to blockchain β Update database with transaction hash β Confirmation displayed
Verification Flow:
Fetch decision from database β Compute current hash β Get on-chain hash β Compare hashes β Display verification status (Verified/Modified/Not Found)
| Layer | Technologies |
|---|---|
| Frontend π¨ | Next.js 14+, React 18+, TypeScript, TailwindCSS |
| Backend ποΈ | Supabase (PostgreSQL, Auth), Next.js API Routes |
| Blockchain βοΈ | Solidity 0.8.x, Hardhat, Ethers.js, wagmi, RainbowKit |
| Tools π οΈ | ESLint, Prettier, Git, pnpm |
app/ - Next.js App Router with all pages and routes
- (auth)/ - Authentication pages (login, sign-up)
- dashboard/ - Protected dashboard routes
- decisions/ - Decision management pages
- deploy/ - Smart contract deployment UI
- profile/ - User profile management
- settings/ - User settings and preferences
components/ - React components
- dashboard/ - Dashboard-specific components
- decisions/ - Decision-related components
- ui/ - Reusable UI primitives (buttons, forms, dialogs, etc.)
contracts/ - Solidity smart contracts
- DecisionRegistry.sol - Main decision registry contract
lib/ - Shared libraries and utilities
- supabase/ - Supabase client configurations
- web3/ - Web3 utilities (wallet, contract interactions, hashing)
- actions/ - Server actions for decisions and comments
- types.ts - TypeScript type definitions
hooks/ - Custom React hooks (use-mobile, use-toast, etc.)
scripts/ - Deployment and utility scripts
public/ - Static assets (images, fonts, etc.)
- Email/password via Supabase
- Session management
- Protected routes with middleware
Lifecycle Stages:
Draft (saved locally) β Review (edit and refine) β Finalize (prepare for blockchain) β Hash (generate SHA-256) β Sign (wallet signature) β Submit (blockchain transaction) β Confirmed (immutable on-chain)
Key Features:
- βοΈ Rich text editor with auto-save every 30 seconds
- π Immutable version history with complete audit trail
- π Diff viewer to compare between versions
- β One-way finalization process (cannot be undone)
- π Real-time verification status with visual indicators
- π§΅ Threaded comments
- π Markdown support
- π€ @mentions with notifications
- π Reactions
- π System-wide activity stream
- π€ Personal activity tracking
- β‘ Real-time updates
- π§ββοΈ Interactive wizard
- β½ Gas estimation
- π Network selection
- β Deployment confirmation
Decisions:
CREATE TABLE decisions (
id UUID PRIMARY KEY,
user_id UUID REFERENCES auth.users,
title TEXT NOT NULL,
content JSONB NOT NULL,
status VARCHAR(20) DEFAULT 'draft',
content_hash VARCHAR(66), -- π SHA-256
tx_hash VARCHAR(66), -- π‘ Transaction
created_at TIMESTAMPTZ DEFAULT NOW()
);Comments:
CREATE TABLE comments (
id UUID PRIMARY KEY,
decision_id UUID REFERENCES decisions,
user_id UUID REFERENCES auth.users,
parent_id UUID REFERENCES comments,
content TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);contract DecisionRegistry {
struct Decision {
bytes32 contentHash;
address creator;
uint256 timestamp;
string metadataURI;
}
mapping(bytes32 => Decision) public decisions;
function registerDecision(
bytes32 decisionId,
bytes32 contentHash,
string memory metadataURI
) external {
// Register decision on-chain
}
function verifyDecision(
bytes32 decisionId,
bytes32 contentHash
) external returns (bool) {
// Verify hash matches
}
}Key Functions:
registerDecision()- π Store hash on-chainverifyDecision()- β Verify integritygetDecision()- π Retrieve details
- Node.js 18+
- npm/yarn/pnpm
- MetaMask wallet
- Supabase account
- Ethereum RPC (Alchemy/Infura)
# 1οΈβ£ Clone repository
git clone https://github.com/AakashMutum/echo-chain.git
cd echo-chain
# 2οΈβ£ Install dependencies
npm install
# 3οΈβ£ Setup environment
cp .env.example .env.local
# Edit .env.local with your credentials
# 4οΈβ£ Setup database
npx supabase db push
# 5οΈβ£ Compile contracts
npx hardhat compile
# 6οΈβ£ Deploy to testnet
npx hardhat run scripts/deploy.js --network sepolia
# 7οΈβ£ Run development server
npm run dev# Supabase
NEXT_PUBLIC_SUPABASE_URL=your_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_key
# Blockchain
NEXT_PUBLIC_SEPOLIA_RPC_URL=your_rpc_url
NEXT_PUBLIC_SEPOLIA_CONTRACT=0x...
# WalletConnect
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_id# Push to GitHub
git push origin main
# Import to Vercel
1. Go to vercel.com
2. Import GitHub repository
3. Add environment variables
4. Deploy! π# Build
docker build -t echo-chain .
# Run
docker run -p 3000:3000 echo-chain# Deploy
npx hardhat run scripts/deploy.js --network mainnet
# Verify
npx hardhat verify --network mainnet DEPLOYED_ADDRESSSmart Contracts:
- β Audit before mainnet
- β Use ReentrancyGuard
- β Implement access control
- β Test extensively
Application:
- β Never commit private keys
- β Implement rate limiting
- β Validate all inputs
- β Use RLS policies
- β HTTPS only
Privacy:
- β Hash sensitive data
- β Keep PII off-chain
- β Clear privacy policy
Wallet Connection:
// Check if MetaMask is installed
console.log('MetaMask:', window.ethereum?.isMetaMask);Transaction Failures:
- Check gas settings
- Verify contract address
- Ensure sufficient balance
Database Errors:
- Verify environment variables
- Check RLS policies
- Test authentication
Build Errors:
# Clear cache
rm -rf .next
npm install
npm run build