Skip to content

Latest commit

Β 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”— Echo Chain - Complete Documentation

A full-stack Web3 application for decentralized decision management with on-chain accountability πŸš€βœ¨


πŸ“‹ Table of Contents

  1. 🎯 Executive Summary
  2. πŸ— Architecture
  3. πŸ’» Technology Stack
  4. πŸ“ Project Structure
  5. ✨ Core Features
  6. πŸ—ƒ Data Models
  7. πŸ“œ Smart Contracts
  8. πŸ›  Installation & Setup
  9. πŸš€ Deployment
  10. πŸ”’ Security
  11. πŸ› Troubleshooting
  12. 🀝 Contributing

🎯 Executive Summary

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.

Key Features 🌟

  • πŸ”„ 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

Use Cases πŸ’‘

  • πŸ›οΈ DAO governance and proposals
  • 🏒 Corporate decision documentation
  • βœ… Audit-ready compliance systems
  • πŸ—³οΈ Transparent voting platforms
  • 🎨 NFT-based decision proofs

πŸ— Architecture

System Overview 🎨

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

Data Flow πŸ”„

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)


πŸ’» Technology Stack

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

πŸ“ Project Structure

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.)


✨ Core Features

1. Authentication πŸ”

  • Email/password via Supabase
  • Session management
  • Protected routes with middleware

2. Decision Management πŸ“

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

3. Commenting System πŸ’¬

  • 🧡 Threaded comments
  • πŸ“ Markdown support
  • πŸ‘€ @mentions with notifications
  • 😊 Reactions

4. Timeline & Activity πŸ“Š

  • 🌐 System-wide activity stream
  • πŸ‘€ Personal activity tracking
  • ⚑ Real-time updates

5. Smart Contract Deployment πŸš€

  • πŸ§™β€β™‚οΈ Interactive wizard
  • β›½ Gas estimation
  • 🌐 Network selection
  • βœ… Deployment confirmation

πŸ—ƒ Data Models

Key Tables πŸ“

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()
);

πŸ“œ Smart Contracts

DecisionRegistry.sol ⛓️

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-chain
  • verifyDecision() - βœ… Verify integrity
  • getDecision() - πŸ” Retrieve details

πŸ›  Installation & Setup

Prerequisites βœ…

  • Node.js 18+
  • npm/yarn/pnpm
  • MetaMask wallet
  • Supabase account
  • Ethereum RPC (Alchemy/Infura)

Quick Start πŸš€

# 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

Environment Variables πŸ”

# 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

πŸš€ Deployment

Vercel (Recommended) ⚑

# 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! πŸŽ‰

Docker 🐳

# Build
docker build -t echo-chain .

# Run
docker run -p 3000:3000 echo-chain

Smart Contract to Mainnet 🌐

# Deploy
npx hardhat run scripts/deploy.js --network mainnet

# Verify
npx hardhat verify --network mainnet DEPLOYED_ADDRESS

πŸ”’ Security

Best Practices βœ…

Smart 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

πŸ› Troubleshooting

Common Issues πŸ”§

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

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages