An advanced blockchain forensics platform for detecting suspicious token behaviors, mixer usage, wash trading, and Ponzi schemes on the Ethereum network in real-time.
- π Token Analysis: Real-time ERC-20 token forensics with BitQuery integration
- π Graph Visualization: Interactive force-directed network graphs with 50+ influential nodes
β οΈ Pattern Detection: Simultaneous detection of:- Mixer/privacy pool usage (Tornado Cash patterns)
- Wash trading rings and circular transactions
- Ponzi scheme hierarchies
- π― Risk Scoring: Comprehensive 40/40/10/10 weighted heuristic model
- 40% Fan-in analysis (incoming transactions)
- 40% Fan-out analysis (outgoing transactions)
- 10% Uniform denomination detection (Tornado Cash)
- 10% Temporal randomness analysis
- π Real-time Status: Track analysis progress (0-100%) with live updates
- πΎ Export Results: Download analysis as CSV or JSON
- π Production Ready: <30 second analysis time, 99%+ uptime target
- Quick Start
- Architecture
- Project Structure
- Development
- Deployment
- API Documentation
- Contributing
- License
- Python 3.8+
- Node.js 18+
- Docker & Docker Compose (optional, for containerized deployment)
- Git
git clone https://github.com/ouemnaa/ai-odyssey.git
cd ai-odysseycd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Copy environment file
cp .env.example .env
# Edit .env with your BitQuery API key
# BITQUERY_API_KEY=your_api_key_here
# Run server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Backend will be available at http://localhost:8000
cd frontend
# Install dependencies
npm install
# Start development server
npm run devFrontend will be available at http://localhost:5173
# From project root
docker-compose up
# Backend: http://localhost:8000
# Frontend: http://localhost:3000
βββββββββββββββββββββββββββββββββββββββββββ
β Frontend (React + TypeScript) β
β β’ Interactive Graph Visualization β
β β’ Risk Dashboard & Metrics β
β β’ Token Input & Search β
ββββββββββββββββββ¬βββββββββββββββββββββββββ
β HTTP/JSON
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Backend API (FastAPI + Python) β
β β’ POST /api/v1/analyze β
β β’ GET /api/v1/analysis/{id}/status β
β β’ GET /api/v1/analysis/{id} β
β β’ GET /api/v1/analysis/{id}/export β
ββββββββββββββββββ¬βββββββββββββββββββββββββ
β
ββββββββββββ ββββββββββββ
βΌ βΌ
ββββββββ ββββββββββββ
β β β Neo4j β
βCache β βDatabaseβ
ββββββββ ββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Agent Layer (Python) β
β β’ First Flow: Mixer Detection Agent β
β β’ Second Flow: General Forensics Agent β
β β’ Louvain Community Detection β
β β’ Risk Metrics Calculation β
ββββββββββββββββββ¬βββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β BitQuery API β
β (Ethereum Data) β
βββββββββββββββββββ
- Framework: React 18 + TypeScript + Vite
- UI Library: Radix UI + TailwindCSS
- Visualization: Custom graph renderer with Framer Motion animations
- State Management: React Hooks + Context API
- API Client: Axios with polling for async operations
Key Components:
SearchSection.tsx- Token input and analysis submissionGraphVisualization.tsx- Interactive graph with zoom/panRiskDashboard.tsx- Risk metrics and statisticsNodeDetailsModal.tsx- Detailed wallet information
- Framework: FastAPI + Uvicorn (Python 3.8+)
- Database: Neo4j for persistence and graph manipulation
- Validation: Pydantic models
- Async: AsyncIO for non-blocking operations
Key Modules:
api/routes/analysis.py- Main analysis endpointsservices/analysis_service.py- Orchestrates agent executionutils/graph_converter.py- Converts agent output to frontend formatschemas/- Data models (Pydantic)
# Specialized mixer detection using behavioral heuristics
- detect_direct_mixer_addresses() # Known mixer detection
- calculate_fan_in_score() # Incoming tx analysis (40% weight)
- calculate_fan_out_score() # Outgoing tx analysis (40% weight)
- calculate_uniform_denominations() # Tornado denomination pattern (10%)
- calculate_temporal_randomness() # Timing analysis (10%)Tornado Cash Denominations Detected:
- 0.1 ETH
- 1 ETH
- 10 ETH
- 100 ETH
# Comprehensive token forensics and pattern detection
- fetch_real_transactions() # BitQuery integration
- fetch_real_internal_transactions() # Smart contract calls
- build_graph_from_real_data() # NetworkX graph construction
- detect_all_clusters_real() # Louvain community detection
- calculate_advanced_risk_metrics() # Gini coefficient, PageRank, etc.Pattern Detection:
- Mixer clusters (fan-in/fan-out spikes)
- Wash trading rings (circular transactions)
- Ponzi hierarchies (centralized fund flows)
ai-odyssey/
βββ README.md # This file
βββ PROJECT_REPORT.md # Comprehensive technical documentation
βββ MVP_DEPLOYMENT.md # 4-week deployment guide
βββ DEPLOYMENT_SUMMARY.md # Quick reference
βββ docker-compose.yml # Local development stack
β
βββ backend/ # FastAPI application
β βββ app/
β β βββ main.py # Application entry point
β β βββ config.py # Configuration management
β β βββ api/
β β β βββ routes/
β β β βββ analysis.py # Analysis endpoints
β β β βββ health.py # Health check
β β βββ models/
β β β βββ analysis.py # SQLAlchemy models
β β βββ schemas/
β β β βββ analysis.py # Request/response schemas
β β β βββ graph.py # Graph data models
β β β βββ status.py # Status schemas
β β βββ services/
β β β βββ analysis_service.py # Core analysis orchestration
β β β βββ export_service.py # Export to CSV/JSON
β β βββ utils/
β β βββ graph_converter.py # Agent output transformation
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Container image
β βββ README.md # Backend documentation
β
βββ frontend/ # React application
β βββ client/
β β βββ index.html
β β βββ src/
β β β βββ App.tsx # Root component
β β β βββ main.tsx # Entry point
β β β βββ pages/
β β β β βββ Home.tsx # Main analysis page
β β β βββ components/
β β β β βββ SearchSection.tsx
β β β β βββ GraphVisualization.tsx
β β β β βββ RiskDashboard.tsx
β β β β βββ NodeDetailsModal.tsx
β β β β βββ AnalysisResults.tsx
β β β βββ services/
β β β β βββ analysisService.ts # API client
β β β βββ contexts/
β β β β βββ ThemeContext.tsx # Dark/light mode
β β β βββ ui/ # Radix UI components
β β βββ public/
β βββ package.json
β βββ vite.config.ts
β βββ tsconfig.json
β
βββ agent/ # ML agents for forensics
β βββ first-flow/
β β βββ mixer_mcp_tool.py # Mixer detection agent (1830 lines)
β β βββ queries.py # BitQuery GraphQL queries
β βββ second-flow/
β βββ work.py # General forensics agent (1544 lines)
β βββ work.md # Agent documentation
β βββ forensic_token_*.{csv,json} # Sample outputs
β
βββ .github/
βββ workflows/
βββ deploy.yml # CI/CD pipeline (GitHub Actions)
# Backend
python-3.8+
fastapi==0.104.1
uvicorn==0.24.0
pydantic==2.5.0
networkx==3.2
community-python==1.0.0
requests==2.31.0
redis==5.0.1
psycopg2-binary==2.9.9
sqlalchemy==2.0.23
# Frontend
node-18.x
npm-10.x
react==18.2.0
typescript==5.3.3
vite==5.0.8
tailwindcss==3.4.1# Run all tests
pytest backend/
# Run specific test
pytest backend/test_graph_converter.py
# With coverage
pytest backend/ --cov=app# Type checking
npm run check
# Build check
npm run build
# Format code
npm run formatBackend: PEP 8 (Python)
# Format
black backend/
# Lint
flake8 backend/Frontend: Prettier + TypeScript
# Format
npm run format
# Type check
npm run check# Using docker-compose (recommended)
docker-compose up
# Manually
# Terminal 1: Backend
cd backend && uvicorn app.main:app --reload
# Terminal 2: Frontend
cd frontend && npm run dev
# Terminal 3: Agents (optional, for manual testing)
cd agent/second-flow && python work.pySee MVP_DEPLOYMENT.md for complete 4-week deployment guide:
- Week 1: Infrastructure (PostgreSQL, Redis, container registry)
- Week 2: Backend (ECS Fargate, 3x FastAPI, 2x workers)
- Week 3: Frontend (S3 + CloudFront CDN)
- Week 4: Monitoring & go-live
Quick Cost Summary:
- Monthly: ~$265
- Setup: 4 weeks
- Concurrent Users: 100-1,000
- Uptime: 99%+
Backend (.env):
# API Configuration
DEBUG=false
LOG_LEVEL=info
PORT=8000
# Database
Neo4j
# API Keys
BITQUERY_API_KEY=your_bitquery_key_here
# Analysis Settings
MAX_ANALYSIS_TIME=30s
MAX_TRANSACTIONS_PER_ANALYSIS=10000Frontend (.env.local):
VITE_API_URL=http://localhost:8000
VITE_API_TIMEOUT=300000Development: http://localhost:8000
Production: https://api.yourdomain.com
Currently MVP (no auth required). Enterprise version will support JWT/OAuth2.
POST /api/v1/analyze
Content-Type: application/json
{
"tokenAddress": "0x6982508145454ce325ddbe47a25d4ec3d2311933",
"daysBack": 7,
"sampleSize": 5000
}Response (HTTP 202 Accepted):
{
"analysisId": "550e8400-e29b-41d4-a716-446655440000",
"status": "processing",
"timestamp": "2025-12-06T10:30:00Z"
}GET /api/v1/analysis/{analysisId}/statusResponse:
{
"analysisId": "550e8400-e29b-41d4-a716-446655440000",
"status": "detecting_patterns",
"progress": 75,
"currentStep": "Detecting wash trading patterns...",
"startedAt": "2025-12-06T10:30:05Z"
}Status Values: queued, fetching_data, building_graph, detecting_patterns, completed, failed
GET /api/v1/analysis/{analysisId}Response:
{
"nodes": [
{
"id": "0x1234...abcd",
"type": "wallet",
"riskLevel": "high",
"holdings": 1500000,
"txCount": 425,
"degree": 50
}
],
"links": [
{
"source": "0x1234...abcd",
"target": "0x5678...efgh",
"value": 50000,
"txCount": 12
}
],
"riskScore": 78.5,
"metrics": {
"giniCoefficient": 0.82,
"avgClusteringCoefficient": 0.34,
"networkDensity": 0.12
},
"topInfluentialWallets": [...],
"detectedCommunities": [...],
"redFlags": [...]
}GET /api/v1/analysis/{analysisId}/export?format=csv
GET /api/v1/analysis/{analysisId}/export?format=jsonGET /healthResponse:
{
"status": "online",
"timestamp": "2025-12-06T10:30:00Z"
}Interactive API docs available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
1. User submits token address
β
2. Backend validates input
β
3. First Agent (Mixer Detection)
ββ Fetch 24h transactions
ββ Detect known mixer addresses
ββ Calculate heuristic scores
ββ Return mixer confidence
β
4. Second Agent (General Forensics)
ββ Fetch 7-day transaction history
ββ Fetch internal transactions
ββ Fetch token holders
ββ Build NetworkX directed graph
ββ Community detection (Louvain)
ββ Pattern detection (wash trading, Ponzi)
ββ Calculate risk metrics
β
5. Graph Converter transforms output
β
6. Results stored
β
7. Frontend polls and displays visualization
risk_score = (
0.40 * fan_in_score +
0.40 * fan_out_score +
0.10 * uniform_denominations_score +
0.10 * temporal_randomness_score
) * 100
if tornado_denominations_detected:
risk_score = min(100, risk_score + 20)
- Low (0-30): Normal trading patterns
- Medium (30-60): Some suspicious indicators
- High (60-80): Multiple red flags
- Critical (80-100): Strong illicit activity indicators
- Fan-In: Number of unique senders to address
- Fan-Out: Number of unique receivers from address
- Gini Coefficient: Wealth concentration measure
- PageRank: Node influence in network
- Clustering Coefficient: Local network density
- Modularity: Community structure quality (>0.6 is strong)
- BitQuery GraphQL API: Real-time Ethereum transaction data
- ERC-20 Token Transfers: Via standard transfer events
- Internal Transactions: Smart contract interactions
- Token Holders: Distribution analysis
- Known Mixer List: Hardcoded Tornado Cash addresses
- No authentication required (public API)
- Rate limiting not implemented
- Data stored in memory/local cache
- Add JWT/OAuth2 authentication
- Implement rate limiting (1000 req/min per IP)
- Use HTTPS only
- Encrypt sensitive data in transit
- Rotate API keys regularly
- Add CORS restrictions
- Implement request signing
| Transaction Count | Analysis Time | Pattern Accuracy |
|---|---|---|
| 1,000 | 5-8s | 90% |
| 5,000 | 12-18s | 92% |
| 10,000 | 20-28s | 95% |
- MVP: 100-1,000 concurrent users
- Scale 1: 5,000+ concurrent users (add read replicas, more workers)
- Scale 2: 50,000+ concurrent users (multi-region deployment, K8s)
# Check port 8000 is free
lsof -i :8000 # macOS/Linux
netstat -ano | findstr :8000 # Windows
# Clear Python cache
find . -type d -name __pycache__ -exec rm -r {} +
find . -name "*.pyc" -delete
# Reinstall dependencies
pip install --upgrade -r requirements.txt# Clear node modules and cache
rm -rf node_modules pnpm-lock.yaml
npm install
# Clear Vite cache
rm -rf dist .vite
npm run dev# Check Redis is running
redis-cli ping
# Should return: PONG
# Or with Docker
docker-compose up redisError: "Rate limit exceeded"
Solution:
- Add exponential backoff (implemented in code)
- Wait 60 seconds before retry
- Consider upgrading BitQuery plan
PROJECT_REPORT.md: Comprehensive technical documentationMVP_DEPLOYMENT.md: Week-by-week deployment guidebackend/README.md: Backend-specific documentation- API Docs:
/docs(Swagger) or/redoc(ReDoc) endpoints
- Create feature branch
git checkout -b feature/your-feature- Make changes and test
# Backend testing
cd backend && pytest
# Frontend testing
cd frontend && npm run check- Commit with clear messages
git commit -m "feat: add mixer detection improvement"- Push and create pull request
git push origin feature/your-featurefeat: add new feature
fix: fix bug
docs: update documentation
test: add tests
refactor: refactor code
perf: improve performance
ci: update CI/CD
MIT License - see LICENSE file for details
- Project: AI-Odyssey Blockchain Forensics Team
- Repository: https://github.com/ouemnaa/ai-odyssey
- BitQuery for Ethereum data API
- NetworkX for graph analysis
- FastAPI for async framework
- React community for UI components