Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Blockchain Explorer

A full-stack real-time blockchain event indexing and analytics dashboard built with modern web technologies.


๐Ÿš€ Features

โšก Real-time Event Indexing - Automatic blockchain event monitoring and indexing
๐Ÿ“Š Interactive Dashboard - Beautiful visualizations with Recharts
๐Ÿ”„ Live Updates - WebSocket-powered real-time data streaming
๐Ÿ’พ Efficient Caching - In-memory LRU cache with 8-10x performance improvement
๐Ÿ“ฆ Batch Processing - Optimized event processing (50 events/batch)
๐Ÿ” Advanced Filtering - Search and filter events by multiple criteria
๐Ÿ“ˆ Analytics - Player leaderboards, event distribution, activity timelines
๐Ÿฅ Health Monitoring - Comprehensive health checks and status reporting
๐Ÿ” Production-Grade Practices - Error handling, retry logic, graceful shutdown
๐Ÿณ Docker Support - One-command deployment with hot reload
๐Ÿค– CI/CD Ready - GitHub Actions workflows included
๐Ÿ“ Comprehensive Docs - 4,600+ lines of documentation across 7 guides


๐Ÿ“‹ Table of Contents


๐Ÿ›  Tech Stack

Layer Technology Version
Frontend React 19.0.0
TypeScript 5.7.2
Vite 7.1.10
Tailwind CSS 4.1.14
Recharts 3.2.1
Socket.IO Client 4.8.1
Backend Node.js 22.11.0
Express 5.1.0
TypeScript 5.7.2
Socket.IO 4.8.1
ethers.js 6.15.0
Database PostgreSQL 18.0
pg 8.13.1
Blockchain Hardhat 3.0.4
Solidity 0.8.28
DevOps Docker Latest
Docker Compose v2+

โšก Quick Start

Option 1: Automated Setup (Recommended)

# Clone repository
git clone https://github.com/Exalt24/Blockchain-Explorer.git
cd Blockchain-Explorer

# One-command setup (5-10 minutes)
.\scripts\setup.ps1

# Open dashboard
Start-Process http://localhost:3000

Option 2: Manual Docker Setup

# 1. Start all services
docker-compose up -d

# 2. Run database migrations
docker-compose exec backend npm run migrate

# 3. Deploy smart contracts
docker-compose exec hardhat npm run deploy-docker

# 4. Restart backend
docker-compose restart backend

# 5. Generate test events (optional)
docker-compose exec hardhat npm run generate-events

Access the application:


๐Ÿ“ Project Structure

blockchain-explorer/
โ”œโ”€โ”€ backend/              # Node.js/Express backend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ api/         # REST API routes
โ”‚   โ”‚   โ”œโ”€โ”€ config/      # Configuration files
โ”‚   โ”‚   โ”œโ”€โ”€ services/    # Business logic
โ”‚   โ”‚   โ”œโ”€โ”€ types/       # TypeScript types
โ”‚   โ”‚   โ”œโ”€โ”€ utils/       # Utility functions
โ”‚   โ”‚   โ””โ”€โ”€ websocket/   # WebSocket server
โ”‚   โ”œโ”€โ”€ migrations/      # Database migrations
โ”‚   โ””โ”€โ”€ tests/           # Test files
โ”œโ”€โ”€ contracts/           # Smart contracts
โ”‚   โ”œโ”€โ”€ contracts/       # Solidity files
โ”‚   โ”œโ”€โ”€ ignition/        # Deployment scripts
โ”‚   โ”œโ”€โ”€ scripts/         # Helper scripts
โ”‚   โ””โ”€โ”€ test/            # Contract tests
โ”œโ”€โ”€ frontend/            # React frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/  # React components
โ”‚   โ”‚   โ”œโ”€โ”€ contexts/    # Context providers
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/       # Custom hooks
โ”‚   โ”‚   โ”œโ”€โ”€ services/    # API services
โ”‚   โ”‚   โ””โ”€โ”€ types/       # TypeScript types
โ”‚   โ”œโ”€โ”€ public/          # Static assets
โ”‚   โ””โ”€โ”€ nginx.conf       # Nginx config for the production frontend image
โ”œโ”€โ”€ docker/              # Docker configuration
โ”‚   โ”œโ”€โ”€ backend.Dockerfile
โ”‚   โ”œโ”€โ”€ contracts.Dockerfile
โ”‚   โ””โ”€โ”€ frontend.Dockerfile
โ”œโ”€โ”€ scripts/             # Automation scripts (PowerShell)
โ”‚   โ”œโ”€โ”€ setup.ps1
โ”‚   โ”œโ”€โ”€ start-dev.ps1
โ”‚   โ”œโ”€โ”€ health-check.ps1
โ”‚   โ””โ”€โ”€ ... (7 more)
โ”œโ”€โ”€ docs/                # Documentation
โ”‚   โ”œโ”€โ”€ API.md
โ”‚   โ”œโ”€โ”€ ARCHITECTURE.md
โ”‚   โ”œโ”€โ”€ DEPLOYMENT.md
โ”‚   โ”œโ”€โ”€ TESTING.md
โ”‚   โ”œโ”€โ”€ TROUBLESHOOTING.md
โ”‚   โ”œโ”€โ”€ MONITORING.md
โ”‚   โ””โ”€โ”€ PRODUCTION-CHECKLIST.md
โ”œโ”€โ”€ .github/workflows/   # CI/CD pipelines
โ”‚   โ”œโ”€โ”€ ci.yml
โ”‚   โ””โ”€โ”€ deploy.yml
โ”œโ”€โ”€ docker-compose.yml       # Development environment
โ”œโ”€โ”€ docker-compose.prod.yml  # Production environment
โ”œโ”€โ”€ CHANGELOG.md
โ””โ”€โ”€ README.md

๐Ÿ“š Documentation

Comprehensive documentation available in the /docs directory:


๐Ÿค– Development Scripts

PowerShell automation scripts for streamlined development:

# Setup & Management
.\scripts\setup.ps1              # Complete first-time setup
.\scripts\start-dev.ps1          # Start all services
.\scripts\stop-dev.ps1           # Stop services (keeps data)
.\scripts\reset-all.ps1          # Complete reset (destroys data)

# Utilities
.\scripts\deploy-contract.ps1   # Deploy smart contract
.\scripts\generate-events.ps1   # Generate test events
.\scripts\health-check.ps1      # System health check
.\scripts\view-logs.ps1         # View service logs
.\scripts\run-tests.ps1         # Run test suites
.\scripts\db-operations.ps1     # Database management

See DEPLOYMENT.md for detailed script documentation.


๐Ÿ”Œ API Reference

REST Endpoints

GET  /api/events                # List events (paginated, filterable)
GET  /api/events/tx/:hash       # Events by transaction
GET  /api/events/block/:block   # Events by block
GET  /api/stats                 # Platform statistics
GET  /api/leaderboard           # Player rankings
GET  /api/stats/distribution    # Event type breakdown
GET  /api/stats/timeline        # Activity over time
GET  /health                    # System health

WebSocket Events

// Client โ†’ Server
socket.emit('ping');

// Server โ†’ Client
socket.on('newEvent', (event) => { /* ... */ });
socket.on('statsUpdate', (stats) => { /* ... */ });
socket.on('blockUpdate', (block) => { /* ... */ });

See API.md for complete API documentation.


๐Ÿงช Testing

Quick Diagnostics

cd backend

# Quick API smoke test
npm run diagnose-api

Test Suites

# Unit Tests
npm run test:health      # Health monitoring
npm run test:cache       # Cache service
npm run test:batch       # Batch processor

# Integration Tests
npm run test:e2e         # End-to-end flow
npm run test:api-integration
npm run test:concurrent
npm run test:ws-stress

# Performance Tests
npm run test:load        # Load testing
npm run test:cache-perf  # Cache performance

Contract Tests

cd contracts
npm test                 # All 16 tests

Test Coverage: 42+ automated tests across backend and contracts

See TESTING.md for detailed testing documentation.


๐Ÿš€ Deployment

Development (Docker)

# Start environment
docker-compose up -d

# Stop environment
docker-compose down

Production (Docker)

# Create production .env
cp backend/.env.production.docker backend/.env
nano backend/.env

# Deploy
docker-compose -f docker-compose.prod.yml up -d

Production (PM2 + Nginx)

# Server setup
sudo apt update && sudo apt upgrade -y
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs postgresql-18 nginx

# Clone and setup
git clone https://github.com/Exalt24/Blockchain-Explorer.git /opt/blockchain-explorer
cd /opt/blockchain-explorer
npm run setup # Helper script

# Deploy with PM2
cd backend
npm install --production
npm run build
pm2 start ecosystem.config.js --env production
pm2 save

# Setup Nginx + SSL
sudo certbot --nginx -d yourdomain.com

See DEPLOYMENT.md for complete deployment guide.


โšก Performance

Benchmarks

API Response Times:

  • Cached: 5-20ms (avg)
  • Uncached: 50-150ms (avg)
  • P95: <200ms
  • P99: <500ms

Throughput:

  • 200-500 req/s (single instance)
  • 50+ concurrent WebSocket connections
  • 100+ events/second indexing

Cache Performance:

  • Hit rate: 80-90%
  • Performance improvement: 8-10x
  • Speedup: Cache hits are 8-10x faster than misses

Optimizations

โœ… Database:

  • Connection pooling (max 20)
  • Strategic indexes
  • Batch inserts (50 events)
  • Query optimization

โœ… Caching:

  • In-memory LRU cache
  • TTL-based expiration (5-60s)
  • Automatic cleanup
  • WebSocket throttling (1/s for blocks)

โœ… Processing:

  • Batch processing (50 events/batch)
  • Auto-flush (1s interval)
  • Error recovery with retry logic

๐Ÿ— Architecture

Frontend (React 19)
        โ†“ HTTP/WebSocket
Backend (Node.js + Express 5)
        โ†“
    โ”Œโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”
    โ”‚ Servicesโ”‚
    โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
    โ”‚โ”‚EventProcโ”‚โ”‚
    โ”‚โ”‚ Stats  โ”‚โ”‚
    โ”‚โ”‚ Cache  โ”‚โ”‚
    โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
    โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜
         โ†“
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚PostgreSQLโ”‚
    โ”‚ Database โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Backend โ† ethers.js โ†’ Blockchain (Hardhat/Ethereum)

See ARCHITECTURE.md for detailed architecture documentation.


๐Ÿ” Monitoring

Health Check

curl http://localhost:4000/health

# Returns comprehensive system status:
{
  "status": "healthy",
  "services": {
    "database": { "connected": true, "latency": 5 },
    "blockchain": { "connected": true, "latestBlock": "12345" },
    "eventListener": { "running": true, "errorCount": 0 },
    "websocket": { "enabled": true, "connectedClients": 3 },
    "cache": { "enabled": true, "hitRate": 0.85 }
  }
}

Recommended Stack

  • Metrics: Prometheus + Grafana
  • Logs: PM2 logs or ELK stack
  • APM: PM2 Plus, New Relic, or Datadog
  • Uptime: UptimeRobot or Pingdom

See MONITORING.md for monitoring setup guide.


๐Ÿ› Troubleshooting

Common Issues

Backend won't start:

# Check port availability
netstat -ano | findstr :4000

# Reinstall dependencies
rm -rf node_modules && npm install

# Verify environment variables
cat .env

Database connection failed:

# Check PostgreSQL is running
docker-compose ps postgres
docker-compose restart postgres

# Test connection manually
psql -h localhost -U postgres -d blockchain_explorer

No events indexed:

# Generate test events
cd contracts && npm run generate-events

# Check EventListener status
curl http://localhost:4000/health | jq '.services.eventListener'

# Verify CONTRACT_ADDRESS is set
grep CONTRACT_ADDRESS backend/.env

See TROUBLESHOOTING.md for complete troubleshooting guide.


๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow existing code style
  • Write tests for new features
  • Update documentation
  • Ensure all tests pass
  • Keep commits atomic and descriptive

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • Built with modern web3 stack
  • Inspired by blockchain explorers like Etherscan
  • Uses best practices from React, Node.js, and PostgreSQL communities

๐Ÿ“ž Support

  • Documentation: Check /docs directory
  • Issues: Open an issue on GitHub
  • Discussions: Start a discussion on GitHub

๐ŸŽฏ Project Status

Current Version: 1.0.0

This is a portfolio project that runs locally via Docker. There is no hosted demo instance, so the "production" references below describe the configuration and practices baked into the codebase (prod Docker compose, Nginx config, error handling, health checks), not a live deployment.

โœ… Completed Phases

  • โœ… Phase 0: Project Setup and Dependencies
  • โœ… Phase 1: Database Schema and Smart Contract
  • โœ… Phase 2: Backend Service (Event Indexer + REST API)
  • โœ… Phase 3: WebSocket Real-Time Layer
  • โœ… Phase 4: Frontend Dashboard (React 19 + Recharts)
  • โœ… Phase 5: Integration and Testing
  • โœ… Phase 6: Docker and Production Readiness

๐ŸŽ‰ Production-Ready Configuration

โœ… Full-stack application functional
โœ… Real-time event indexing
โœ… Interactive dashboard
โœ… Docker development environment
โœ… Docker production configuration
โœ… Comprehensive testing (42+ tests)
โœ… Complete documentation (4,600+ lines)
โœ… Performance optimized (cache, batch processing)
โœ… Error handling and retry logic
โœ… Health monitoring
โœ… Resource limits configured
โœ… Production-ready Nginx config
โœ… PowerShell automation scripts
โœ… CI/CD pipeline templates
โœ… Production readiness checklist


๐Ÿ”ฎ Roadmap

Short Term (v1.1.0)

  • Redis integration for distributed cache
  • Prometheus metrics export
  • Grafana dashboards
  • Rate limiting middleware
  • GraphQL API

Medium Term (v1.2.0)

  • Multi-chain support
  • Advanced analytics
  • Data export features
  • Event notifications
  • Mobile-responsive improvements

Long Term (v2.0.0)

  • Machine learning insights
  • Mobile app (React Native)
  • Plugin system
  • Advanced filtering and search

Built with โค๏ธ for the Web3 community


Quick Links

About

Real-time blockchain event indexing platform with interactive analytics, reaching 8-10x faster reads through in-memory LRU caching (80-90% hit rate) and handling 200-500 req/s at sub-200ms P95.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages