flexycode/CCSFEN2L_ALTFLEX
π€ This repository is intended for our final project in Software Engineer CCSFEN2L by Professor Armida P. Salazar
π‘οΈ AltFlex: Artificial Intelligence Powered Forensic Framework for Exploit Detection
A. Project Overview
AltFlex is an integrated AI and digital forensics framework designed to proactively detect and analyze security exploits in cross-chain bridges and Decentralize Finance protocols. By combining machine learning anomaly detection with blockchain forensic analysis, the system provides a comprehensive security solution for the rapidly evolving Web3 ecosystem.
B. Problem Statement
DeFi protocols and cross-chain bridges are increasingly vulnerable to exploits, resulting in significant financial losses. Current security measures often lack the agility and intelligence to detect sophisticated attack vectors. AltFlex addresses this critical need by providing a proactive and adaptive solution for identifying and mitigating potential exploits using advanced AI/ML techniques.
C. Objectives
Primary Objective:
- Develop a functional AI-powered forensic framework (AltFlex) for automated exploit detection in DeFi and cross-chain environments.
Secondary Objectives:
- Implement machine learning models for anomaly detection and pattern recognition in transaction data.
- Create a user-friendly interface for visualizing forensic analysis results.
- Establish a comprehensive database of known exploit signatures and attack patterns.
- Evaluate the framework's effectiveness through rigorous testing and validation against real-world exploit scenarios.
D. Methodology
The project will be executed in the following phases:
- Data Collection: Gather historical transaction data, smart contract code, and exploit reports.
- Data Preprocessing: Clean, transform, and normalize collected data.
- Model Development: Develop and train AI/ML models for anomaly detection and pattern recognition.
- Framework Implementation: Integrate models into the AltFlex framework with UI and visualization.
- Testing and Validation: Evaluate performance against simulated and real-world scenarios.
- Integration and Testing: Deploy and test in sandboxed blockchain environments.
π Phase 1: Production-Ready Architecture (Flash Loan Detection)
Architecture Overview
flowchart LR
subgraph Data Layer
A[Etherscan API] --> B[EtherscanCollector]
C[Sample Data] --> D[data/]
end
subgraph Processing
B --> E[FeatureEngineer]
D --> E
E --> F[AnomalyDetector]
E --> G[ExploitDetector]
E --> H[BehavioralAnalyzer]
end
subgraph API Layer
F --> I[FastAPI :8000]
G --> I
H --> I
end
subgraph Frontend
I --> J[Next.js Dashboard :3000]
J --> K[Landing Page]
J --> L[Transaction Analysis]
J --> M[Address Verification]
J --> N[Exploit Database]
end⨠Key Features Implemented
| Component | Description | Status |
|---|---|---|
| π Rule-Based Detection | 6 detection rules for flash loan patterns | β Complete |
| π€ ML Anomaly Detection | XGBoost classifier with training pipeline | β Complete |
| π FastAPI Backend | 12 REST API endpoints with security middleware | β Complete |
| π¨ Next.js Frontend | Premium dashboard with 5 pages | β Complete |
| π‘οΈ Address Verification | 5-layer validation pipeline | β Complete |
| π¦ Sample Data | 5 real exploits, 50 transactions | β Complete |
| β Unit Tests | 159 test cases (100% passing) | β Complete |
π Known Exploits Tracked
| Exploit | Date | Protocol | Loss |
|---|---|---|---|
| Euler Finance | 2023-03-13 | Euler | $197M |
| Cream Finance | 2021-10-27 | Cream | $130M |
| Pancake Bunny | 2021-05-20 | PancakeBunny | $45M |
| Harvest Finance | 2020-10-26 | Harvest | $34M |
| bZx Protocol | 2020-02-15 | bZx | $350K |
π Proof-of-Concept: Benchmarking Results
Dataset: 50 samples (12 Exploit / 38 Normal) Β· Source: 5 Major Exploits ($406.35M)
Validation: 5-Fold Stratified CV Γ 5 Repeats = 25 independent runs per algorithm
Benchmark Table (Multi-Run Validated, Mean Β± Std)
| Algorithm | Accuracy | F1 | ROC-AUC | Latency |
|---|---|---|---|---|
| XGBoost (Ours) | 0.96 | 0.98 Β± 0.10 | 0.99 Β± 0.07 | ~87ms |
| Isolation Forest | 0.98 Β± 0.03 | 0.98 Β± 0.05 | 1.00 Β± 0.00 | ~45ms |
| One-Class SVM | 0.85 Β± 0.11 | 0.80 Β± 0.12 | 1.00 Β± 0.00 | ~62ms |
Accuracy Comparison
XGBoost (Ours) 96% ββββββββββββββββββββββββββββββββββββββββββββββββ
Isolation Forest 98% βββββββββββββββββββββββββββββββββββββββββββββββββ
One-Class SVM 85% ββββββββββββββββββββββββββββββββββββββββββ
| Metric | Value |
|---|---|
| Rule Coverage | 100% Combined Detection |
| Avg Confidence | 0.98 |
π Why XGBoost Is Still the Valid Choice
Both XGBoost and Isolation Forest achieve ~98-99% accuracy on this PoC dataset. However, XGBoost was selected as the primary algorithm for the following reasons:
- Supervised vs. Unsupervised β XGBoost learns what an exploit looks like from labeled data. Isolation Forest only detects statistical outliers and may flag unusual-but-legitimate transactions as attacks in production environments.
- Perfect Precision (Zero False Positives) β XGBoost achieved 1.00 precision across all 25 runs, meaning it never falsely accused a normal transaction. Isolation Forest dropped to 0.75 precision in some folds β a critical concern for a security tool where false alarms erode user trust.
- Interpretability β XGBoost provides feature importance scores, enabling explainable detection. This is essential for forensic analysis where why a transaction was flagged matters as much as whether it was flagged.
- Production Scalability β With larger, more diverse real-world datasets, supervised models generalize better than unsupervised anomaly detectors.
π Why Both Algorithms Score High on This Dataset
The PoC dataset (50 samples) contains clearly separable classes β exploit transactions exhibit extreme values (2,500β12,000 ETH, 1.8Mβ3.2M gas) vs. normal transactions (0.05β15 ETH, 88Kβ260K gas). With such clean separation, any reasonable algorithm achieves near-perfect results. The differentiation between algorithms would become more significant with a larger, more diverse dataset. This is expected behavior for a proof-of-concept and does not diminish the framework's value.
π Rule Coverage & Avg Confidence Breakdown
Rule Coverage: 100% β All 5 flash loan detection rules from the rule-based engine cover the complete exploit dataset:
| Rule | Description | Exploits Covered |
|---|---|---|
| Same-block borrow/repay | Transaction borrows and repays in same block | β 5/5 |
| Large value transfer | Value > $100K equivalent | β 5/5 |
| Lending protocol interaction | Interaction with known lending protocols | β 5/5 |
| Multiple contract calls | Multiple contract calls in single transaction | β 5/5 |
| High gas usage | Gas usage > 500K | β 5/5 |
Avg Confidence: 0.98 β Calculated from XGBoost's multi-run validated metrics:
- Precision: 1.00 (zero false positives across 25 runs)
- Recall: 0.97 (missed 1 exploit in 1 of 25 folds)
- F1 Score: 0.98 (harmonic mean of precision and recall)
- Avg Confidence = mean(Precision, Recall, F1) = (1.00 + 0.97 + 0.98) / 3 β 0.98
β Validation Methodology
Results validated using 5-fold Stratified Cross-Validation repeated 5 times (25 independent evaluations per algorithm). Metrics reported as multi-run means β not single-run results.
Benchmark script:benchmark_validation.pyΒ· Full results:benchmark_results.json
π API Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
/health |
GET | Health check |
/api/analyze |
POST | Full transaction analysis |
/api/address/check |
POST | Check known attackers |
/api/exploits |
GET | List known exploits |
/api/detect/rules |
POST | Rule-only detection |
/api/detect/anomaly |
POST | ML-only detection |
π Phase 2: Address Detection Security Enhancement
Overview
Phase 2 strengthens the framework's address verification and behavioral analysis capabilities through a comprehensive 4-sprint implementation focused on security, intelligence, and API hardening.
Architecture Enhancement
flowchart TB
subgraph Input Layer
A[Address Input] --> B[Validation Layer]
end
subgraph Sprint 1: Validation
B --> C[Format Check]
B --> D[Checksum Validation]
B --> E[ICAP Detection]
end
subgraph Sprint 2: On-Chain
C --> F[Etherscan Verifier]
F --> G[Balance Check]
F --> H[Contract Detection]
F --> I[Address Age]
end
subgraph Sprint 3: Behavioral
I --> J[Velocity Scoring]
I --> K[Funding Analysis]
I --> L[Blacklist Check]
end
subgraph Sprint 4: API Security
J --> M[Rate Limiter]
K --> M[Rate Limiter]
L --> M[Rate Limiter]
M --> N[API Key Auth]
N --> O[Audit Logger]
end
O --> P[Risk Assessment]π― Sprint Implementation Summary
| Sprint | Focus | Components | Tests | Status |
|---|---|---|---|---|
| Sprint 1 | Validation Layer | Format, Checksum, ICAP | 44 | β Complete |
| Sprint 2 | On-Chain Verification | Balance, Contract, Age | 21 | β Complete |
| Sprint 3 | Behavioral Analysis | Velocity, Funding, Blacklist | 24 | β Complete |
| Sprint 4 | API Hardening | Rate Limit, Auth, Logging | 34 | β Complete |
| Total | 11 New Modules | 123 | β Complete |
π¦ Sprint 1: Address Validation Layer
Objective: Implement comprehensive format validation for Ethereum addresses.
Components Added
address_validator.py(255 lines)validate_format()β Regex-based address format checkingvalidate_checksum()β EIP-55 checksum validationdetect_icap()β ICAP address format detectionis_all_same_character()β Detect suspicious patterns
Test Coverage
44/44 tests passed
- Format validation (11 tests)
- Checksum validation (10 tests)
- ICAP detection (6 tests)
- Pattern detection (17 tests)
Key Features
- β EIP-55 checksum validation
- β ICAP (IBAN-like) address support
- β Suspicious pattern detection (all zeros, sequential chars)
- β Comprehensive error messages
π Sprint 2: On-Chain Verification
Objective: Verify address existence and gather intelligence from the blockchain.
Components Added
-
etherscan_collector.py(Extended)get_balance()β ETH balance lookupget_transaction_count()β Transaction history countis_contract()β Contract vs EOA detectionget_first_transaction()β Address age calculationverify_address()β Comprehensive verification
-
address_verifier.py(277 lines)AddressVerifierβ High-level verification utilityComprehensiveAddressReportβ Combined validation + on-chain data
Test Coverage
21/21 tests passed
- Balance checks (3 tests)
- Contract detection (3 tests)
- Transaction counting (2 tests)
- Address age verification (2 tests)
- Comprehensive verification (11 tests)
Key Features
- β Real-time balance verification
- β Contract vs EOA differentiation
- β Address age detection (flag new addresses)
- β Dormant address identification
π§ Sprint 3: Behavioral Analysis Enhancement
Objective: Detect suspicious behavior patterns that format/on-chain checks miss.
Components Added
-
behavioral_analyzer.py(466 lines)VelocityScoreβ Transaction frequency analysisFundingPatternScoreβ Funding source analysisBehavioralReportβ Comprehensive behavioral assessmentanalyze_velocity()β Burst detection, high-frequency patternsanalyze_funding_patterns()β Circular funding, wash trading
-
feature_engineer.py(Extended)compute_velocity_features()β Velocity-based ML featurescompute_funding_pattern_features()β Funding-based ML featuresextract_enhanced_address_features()β Combined feature extraction
-
exploit_detector.py(Extended)check_external_blacklists()β OFAC, mixer, phisher checksget_comprehensive_address_risk()β Multi-source risk assessment
Test Coverage
24/24 tests passed
- Velocity analysis (4 tests)
- Funding pattern detection (4 tests)
- Behavioral scoring (4 tests)
- Feature engineering (3 tests)
- Blacklist integration (7 tests)
Key Features
- β Velocity Scoring β Detect burst activity, high transaction frequency
- β Funding Patterns β Circular funding, wash trading, concentration analysis
- β External Blacklists β OFAC sanctioned addresses, known mixers
- β Sybil Detection β Low funding diversity, suspicious patterns
π‘οΈ Sprint 4: API Hardening
Objective: Secure the FastAPI backend against abuse and enable security monitoring.
Components Added
-
security_middleware.py(615 lines)RateLimiterβ Token bucket rate limiting (100 req/min default)RateLimitMiddlewareβ FastAPI middleware wrapperAPIKeyAuthβ X-API-Key header authenticationRequestValidatorβ Input sanitization, XSS/SQLi preventionAuditLoggerβ Request/response logging with timestampsAuditLogMiddlewareβ Automatic security event logging
-
main.py(Extended)- Integrated
setup_security_middleware() - Security configuration via environment variables
- Integrated
Test Coverage
34/34 tests passed
- Rate limiting (6 tests)
- API key authentication (5 tests)
- Request validation (12 tests)
- Audit logging (5 tests)
- Security configuration (6 tests)
Security Features
| Feature | Configuration | Purpose |
|---|---|---|
| Rate Limiting | 100 req/min per IP | Prevent DoS attacks |
| API Key Auth | X-API-Key header |
Optional authentication |
| Request Validation | Auto-sanitization | Prevent injection attacks |
| Audit Logging | All requests logged | Security monitoring |
Environment Variables
# Rate Limiting
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW_SECONDS=60
# Authentication
ALTFLEX_API_KEYS=key1,key2,key3
ALTFLEX_API_KEY_REQUIRED=false
# Logging
AUDIT_LOG_ENABLED=true
AUDIT_LOG_FILE=logs/audit.log
# Validation
MAX_REQUEST_SIZE_BYTES=1048576π― Phase 2 Impact Summary
Codebase Growth
| Metric | Count |
|---|---|
| New/Modified Files | 11 |
| Lines of Code Added | ~2,400 |
| Test Cases Added | 123 |
| Documentation Pages | 4 |
Security Enhancements
- β Address Validation β 5-layer verification (format, checksum, ICAP, on-chain, behavioral)
- β Blacklist Integration β OFAC, mixers, phishers (auto-updated)
- β API Security β Rate limiting, auth, input validation, audit trails
- β Behavioral Intelligence β Velocity, funding patterns, sybil detection
Test Coverage
Phase 1: 23 tests β
Phase 2: 123 tests β
Total: 146 tests β
E. Conclusion
AltFlex addresses a critical gap in Web3 security through an innovative combination of artificial intelligence and digital forensics. The proposed framework provides a foundation for proactive security monitoring and comprehensive incident analysis.
F. Project Structure
Root Directory: CCSFEN2L-ALTFLEX/
1. Configuration & Setup
-
.devcontainer/- Purpose: Contains configuration files for Visual Studio Code Remote - Containers.
- Function: Automates the setup of the development environment.
- Key Files:
devcontainer.json,Dockerfile.
-
docker-compose.yml- Purpose: Container orchestration configuration.
- Function: Defines the services required to run the full AltFlex application stack.
-
README.md- Purpose: The central documentation hub ("The Bible") of the project.
2. Data Management
data/- Purpose: Storage for raw and processed forensic datasets.
- Note: Managed via GitLFS.
3. Source Code (src/)
src/collectors/- Purpose: Data ingestion layer (Python scripts for scraping/fetching data).
- Files:
etherscan_collector.py: Fetches account transaction history from Etherscan API.polygonscan_collector.py: Fetches account transaction history from PolygonScan API.bridge_monitor.py: Monitors cross-chain bridge events.
src/forensics/- Purpose: Rule-based detection engine (Signature matching, static analysis).
src/models/- Purpose: Machine Learning engine (GNN, XGBoost models).
- Files:
gnn_analyzer.py: Graph Neural Network logic for transaction graph analysis.anomaly_detector.py: XGBoost-based tabular anomaly detection.feature_engineer.py: Feature extraction pipelines.
src/app/- Purpose: FastAPI Backend (REST API endpoints, security middleware).
- Files:
main.py: FastAPI application entry point.routes.py: API endpoint definitions.
4. Frontend (frontend/)
frontend/src/app/- Purpose: Next.js 14 App Router pages and layouts.
- Files:
page.tsx: Landing page.dashboard/page.tsx: Main dashboard.dashboard/analyze/page.tsx: Transaction analysis interface.dashboard/verify/page.tsx: Address verification interface.dashboard/exploits/page.tsx: Exploit database browser.
frontend/src/components/- Purpose: Reusable React components.
- Sub-directories:
layout/: Sidebar, Header components.dashboard/: MetricCard, HealthStatus components.
frontend/src/lib/- Purpose: Utility functions and API client.
- Files:
api.ts: FastAPI client wrapper.utils.ts: Helper functions (formatCurrency, formatAddress).types.ts: TypeScript type definitions.
5. Research & Experimentation
notebooks/- Purpose: Sandbox for research and prototyping (Jupyter notebooks).
- Content:
01_data_exploration.ipynb: Exploratory Data Analysis (EDA).02_model_prototyping.ipynb: Prototyping ML architectures.
5. Quality Assurance
tests/- Purpose: Automated testing suite.
G. Getting Started
Access Links
Once the application is running, you can access the services at:
- Next.js Dashboard: http://localhost:3000
- API Docs (Swagger): http://localhost:8000/docs
- API Health Check: http://localhost:8000/health
πΈ Application Screenshots & UI Showcase
π Landing Page (localhost:3000)
The entry point of the AltFlex platform featuring a premium dark-themed hero section with animated statistics, feature highlights, and direct navigation to the dashboard.
Key Highlights:
- Hero section with real-time platform statistics (406M+ tracked losses, 5 known exploits, 159 unit tests, 12 API endpoints)
- Six enterprise-grade security feature cards (Transaction Analysis, Address Verification, Exploit Database, Real-time Detection, Behavioral Analysis, API Security)
- Dark mode with glassmorphism design and smooth scroll navigation
π Dashboard (localhost:3000/dashboard)
The main operational hub for monitoring and analyzing blockchain security threats in real-time.
Key Highlights:
- Metric Cards: Known Exploits (5), Total Tracked Loss ($406.4M), Detection Rules (6), Unit Tests (159)
- Quick Actions: Analyze Transaction, Verify Address, View Exploits β one-click navigation
- System Health Panel: Live API Server, ML Detector, Exploit Detector, and Feature Engine status
- API Information: 12 endpoints, 100 req/min rate limit, FastAPI backend
π API Documentation (localhost:8000/docs)
Auto-generated Swagger UI for the FastAPI backend, providing interactive API exploration and testing.
Endpoint Groups:
- Health: Root (
/) and health check (/health)- System: Model information (
/api/model/info)- Analysis: Transaction analysis (
/api/analyze), batch analysis (/api/analyze/batch), address check (/api/address/check)- Database: List exploits (
/api/exploits), get exploit details (/api/exploits/{id})- Detection: Rule-based detection (
/api/detect/rules), ML anomaly detection (/api/detect/anomaly)
π₯ API Health Check (localhost:8000/health)
Real-time system health endpoint showing all component statuses.
Response:
{"status":"healthy","version":"1.0.0","components":{"api":true,"anomaly_detector":true,"exploit_detector":true,"feature_engineer":true}}
π Transaction Analysis (localhost:3000/dashboard/analyze)
Deep analysis of blockchain transactions using rule-based detection and ML-powered anomaly scoring.
Form Inputs: From Address, To Address, Value (ETH), Gas Used, Gas Price, Flash Loan toggle
Filled form with suspicious flash loan transaction data:
Analysis results showing risk assessment, triggered rules, and ML prediction:
Key Features:
- Risk Score visualization with circular gauge (0-100)
- Triggered rules with severity badges (CRITICAL / HIGH / MEDIUM / LOW)
- ML Prediction with confidence percentage (Anomaly Detected / Normal Transaction)
- Split-screen layout β form on left, results on right
π‘οΈ Address Verification (localhost:3000/dashboard/verify)
5-layer security verification for Ethereum addresses against known exploit databases.
Verification result for a known attacker address:
Key Features:
- Status banner β
β οΈ Known Attacker (red) or β Address Safe (green)- Address details with risk level badge
- Associated exploit information (name, date, loss amount)
- Copy-to-clipboard for verified addresses
π Exploits Database (localhost:3000/dashboard/exploits)
Searchable database of known DeFi and cross-chain bridge exploits with detailed attacker tracking.
Key Features:
- Searchable list with protocol, date, loss amount, and attack type
- Exploit detail cards with attacker addresses
- Etherscan integration links for on-chain investigation
- Filter by attack type (Flash Loan, Reentrancy, Oracle Manipulation, etc.)
Option 1: Running with Docker Compose (Recommended)
Prerequisites: Docker Desktop (Windows) or Docker Engine (Linux)
Windows: Install and Configure Docker Desktop
-
Download Docker Desktop from https://www.docker.com/products/docker-desktop
-
Install Docker Desktop and follow the installation wizard
-
Fix "docker-users" Group Membership (if you see this error when opening Docker Desktop)
β οΈ Common Error: "Docker Desktop requires that your user is a member of the 'docker-users' group."Solution - Option A: PowerShell (Easiest)
Run this command as Administrator:
Add-LocalGroupMember -Group "docker-users" -Member $env:USERNAME
Steps:
- Right-click on PowerShell in Start Menu β Run as Administrator
- Paste the command above and press Enter
- Log out of Windows and log back in (or restart your PC)
- Open Docker Desktop - it should work now!
Solution - Option B: Computer Management GUI
- Press
Win + R, typelusrmgr.msc, press Enter - Click Groups in the left panel
- Double-click docker-users
- Click Add β type your username β Check Names β OK
- Log out and log back in
Verify Group Membership:
whoami /groups | findstr docker-users
-
Enable WSL 2 Backend (recommended for performance):
- Open Docker Desktop Settings β General
- Enable "Use WSL 2 based engine"
Linux: Install Docker Engine
For Pop!_OS 22.04 LTS or Linux Mint, see the comprehensive guide in docs/DOCKER_SETUP_GUIDE.md.
Quick Install (Ubuntu-based):
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Add your user to docker group
sudo usermod -aG docker $USER
newgrp docker
# Verify installation
docker --version
docker compose versionRun the Application
Step 1: Clone and Configure
git clone https://github.com/flexycode/CCSFEN2L_ALTFLEX.git
cd CCSFEN2L_ALTFLEX
# Copy environment file
cp .env.example .envStep 2: Start Services
Development Mode (with hot-reload):
docker compose -f docker-compose.dev.yml up --buildProduction Mode:
docker compose up --build -dStep 3: Access the Application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Docs: http://localhost:8000/docs
Stop Services:
# Development
docker compose -f docker-compose.dev.yml down
# Production
docker compose downOption 2: Running Locally (No Docker)
Prerequisites: Python 3.10+, Node.js 20+
Step 1: Create Virtual Environment
# Create virtual environment
python -m venv .venv
# Activate (choose your OS):
# Windows PowerShell:
.\.venv\Scripts\Activate.ps1
# Windows CMD:
.venv\Scripts\activate.bat
# Mac/Linux:
source .venv/bin/activate.env
# AltFlex Environment Configuration
# Copy this file to .env and fill in your values
# =============================================================================
# API Keys (Optional - Mock data used if not provided)
# =============================================================================
ETHERSCAN_API_KEY=your_etherscan_api_key_here
POLYGONSCAN_API_KEY=your_polygonscan_api_key_here
# =============================================================================
# Application Settings
# =============================================================================
# Set to 'development' for mock data, 'production' for live APIs
APP_ENV=development
# API Server
API_HOST=0.0.0.0
API_PORT=8000
# Dashboard
DASHBOARD_PORT=8501
# =============================================================================
# Model Configuration
# =============================================================================
MODEL_PATH=models/anomaly_detector.pkl
DETECTION_THRESHOLD=0.7
# =============================================================================
# Logging
# =============================================================================
LOG_LEVEL=INFO
Step 2: Install Python Dependencies {NOTE THIS IS FOR FIRST TIME ONLY if theirs no Python Dependencies in your localhost otherwise proceed to Step 4}
Windows OS
# Standard (if python/pip in PATH):
pip install -r requirements.txt
# Windows Alternative (if pip not found):
.\.venv\Scripts\pip.exe install -r requirements.txtPop_OS, Linux Mint, or any Ubuntu Linux Distro
# Check Python versions
python3 --version && python --version || true
# Check Node.js versions
node --version && npm --version
# Create venv and install requirements
python3 -m venv .venv && . .venv/bin/activate && pip install -r requirements.txt
# Install Python 3.10 venv (if needed)
sudo apt update && sudo apt install -y python3.10-venv
# Verify venv creation
test -d .venv && echo '.venv exists' || echo '.venv missing'
# Activate and install
. .venv/bin/activate && python -m pip install --upgrade pip && pip install -r requirements.txt
# List venv files
ls -la .venv && find .venv -maxdepth 2 -type f -name activate -o -name python -o -name pip | head
# Verify venv help
python3 -m venv --help | head -n 20
# List venv bin directory
ls -la .venv/bin
# Check for running processes on ports 8000 and 3000
ss -ltnp | (grep -E ':(8000|3000)\s' || true)
#
python3 -m venv --clear .venv && . .venv/bin/activate && python -m pip install --upgrade pip && pip install -r requirements.txtStep 3: Run the Backend API { If things get fuck-up try to run the step 4 Frontend then proceed to Step 3 }
Linux
# Step 1:
curl -sS -i http://127.0.0.1:8000/health | head -n 20
# Step 2:
curl -sS -I http://localhost:3000 | head -n 20Linux Option 2 Step
.venv/bin/python -m uvicorn src.app.main:app --reload --host 127.0.0.1 --port 8000
Windows
# Standard:
uvicorn src.app.main:app --reload --port 8000
# Windows Alternative:
py -m uvicorn src.app.main:app --host 127.0.0.1 --port 8000Step 4: Run the Frontend
Open a second terminal, navigate to the frontend directory, and start the Next.js dev server:
Linux
# Step 1:
venv/bin/python -m uvicorn src.app.main:app --reload --host 127.0.0.1 --port 8000
# Step 2:
test -d node_modules && echo 'node_modules exists' || echo 'node_modules missing'Linux Option 2 step:
NEXT_PUBLIC_API_URL=http://127.0.0.1:8000 npm run devWindows
cd frontend
npm install # First time only
npm run devThe frontend will be available at http://localhost:3000
Step 5: Run Tests (Optional)
# Standard:
pytest tests/ -v
# Windows Alternative:
.\.venv\Scripts\python.exe -m pytest tests/ -vπ§ Troubleshooting
Docker Issues
| Issue | Solution |
|---|---|
docker-users group error |
Follow the Windows docker-users fix above |
Cannot connect to Docker daemon |
Ensure Docker Desktop is running |
Port already in use |
Stop existing containers: docker compose down |
Build failed |
Try docker compose build --no-cache |
Local Setup Issues
| Issue | Solution |
|---|---|
pip not found |
Use .\.venv\Scripts\pip.exe instead |
python not found |
Use .\.venv\Scripts\python.exe instead |
Module not found |
Ensure you activated the virtual environment |
Port already in use |
Change port: --port 8001 |
API offline in dashboard |
Start the API server (port 8000) before the frontend |
Frontend not loading |
Run npm install in the frontend/ directory first |
CORS errors |
Ensure API is running on port 8000 and frontend on port 3000 |
Docker Commands Cheat Sheet
# View running containers
docker compose ps
# View logs
docker compose logs -f
# Restart a specific service
docker compose restart backend
# Rebuild without cache
docker compose build --no-cache
# Remove all containers and volumes
docker compose down -vπ Additional Documentation
For detailed Docker setup instructions including Linux distributions (Pop!_OS, Linux Mint), see:
- Docker Setup Guide - Comprehensive installation and troubleshooting
- Phase 3 Frontend Implementation - Sprint details and task breakdown
π ContributingΒ Β Β Β
ContributingΒ Β Β Β Β
If you would like to contribute to the Flight Booking App, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your changes to your forked repository.
- Submit a pull request to the main repository.
π§ Submitting Changes
π§ Contributions are welcome! If you have ideas for improvements or want to add more exercises, follow these steps:
- Fork the repository.
- Create a new branch.
- Make your changes and commit them.
- Push to your fork and submit a pull request. ππππ
π Contributors
Special thanks to all my groupmates:
-
π Jay Arre TalosigΒ - Machine Learning Engineer | Blockchain Developer | AI Architect Β Β Β
-
π΅οΈββοΈ Rinoah Venedict Dela Rama - Python DeveloperΒ | QA Engineer | Data EngineerΒ
-
π΅οΈ Alexander Castilo - Penetration Tester | Software EngineerΒ | Threat Researcher
-
π₯· Nicko Nehcterg Dalida - Digital Forensics AnalystΒ | QA Engineer | Smart Contract Auditor
-
π§βπ» Mark Jhosua Taberna - Digital Forensics AnalystΒ | UI Specialist | Full Stack Engineer
π€ Collab
-
π§ Brian Carlo De Vera - QA Engineer | Cybersecurity Engineer | Network Engineer
πΈ FAQ
πΈ Reporting Issues
Some changes need to be address
- TBA
- TBA
- TBAπ« Changelogs
Chronological list of updates, bug fixes, new features, and other modifications for our Software Engineering Project.
π» [01.0.0] - 2025-11-17Β Β Β Β Β Β
Role & Project Management
- π» Final Project requirements for our project
π» [01.1.0] - 2025-11-24Β Β Β Β Β Β
Role & Project Management
- π» Construct the important folder in the overall
π» [02.0.0] - 2025-11-25
Development Progress
- π» Initial project structure setup
- π Created
src/,data/,tests/,notebooks/directories - π§ Configured
.devcontainerfor VS Code development
π» [03.0.0] - 2025-12-04
Development Progress
- π Documentation structure established
- π³ Docker configuration added (
docker-compose.yml) - π Requirements planning completed
π» [04.0.0] - 2025-12-08
AI/ML Component Integration
- π» Collectors: Added
etherscan_collector.py,polygonscan_collector.py, andbridge_monitor.py. - π» Models: Added
gnn_analyzer.py,anomaly_detector.py, andfeature_engineer.py. - π» Notebooks: Added data exploration and model prototyping notebooks.
π [05.0.0] - 2025-12-17
Phase 1: Production-Ready Flash Loan Detection Platform
- π Exploit Detector: Implemented 6 rule-based detection rules for flash loan attacks
- π€ Anomaly Detector: Complete XGBoost implementation with training pipeline (265 lines)
- π Feature Engineer: Flash loan-specific feature extraction (185 lines)
- π FastAPI Backend: Expanded to 12 API endpoints (400+ lines)
- π± Streamlit Dashboard: Full 5-page interactive UI (450+ lines)
- π¦ Sample Data:
flash_loan_exploits.json: 5 real exploit signatures ($406M+ tracked)sample_transactions.csv: 50 transactions (12 malicious samples)
- β Testing: 23+ unit tests, API integration tests
- βοΈ Configuration: Added
.env.example, updatedrequirements.txt(15+ dependencies)
π§ [05.1.0] - 2026-01-07
Bug Fixes & Stability Improvements
- π API: Fixed
uvicornstartup configuration to support hot-reloading by using import strings. - π± Dashboard: Fixed critical navigation bug in "Quick Actions" using state callbacks.
- β Verification: Validated end-to-end functionality of API and Dashboard using sub-agent verification.
π [06.0.0] - 2026-01-13
Phase 2: Address Detection Security Enhancement (Complete)
Major Security Update β 4-sprint implementation adding comprehensive address verification and API hardening.
Sprint 1: Address Validation Layer
- π Validator: Implemented
address_validator.pywith EIP-55 checksum validation (255 lines) - β Features: Format validation, checksum verification, ICAP detection, pattern analysis
- π§ͺ Testing: 44 unit tests covering all validation scenarios
Sprint 2: On-Chain Verification
- π Etherscan Integration: Extended
etherscan_collector.pywith 6 new methods- Balance lookup, transaction counting, contract detection, address age
- π Address Verifier: Created
address_verifier.pyfor high-level verification (277 lines) - π§ͺ Testing: 21 unit tests with mocked API calls
Sprint 3: Behavioral Analysis Enhancement
- π§ Behavioral Analyzer: New
behavioral_analyzer.pymodule (466 lines)- Velocity scoring (burst detection, high-frequency patterns)
- Funding pattern analysis (circular funding, wash trading)
- π Feature Engineering: Extended with velocity and funding features
- π¨ Blacklist Integration: OFAC sanctions, known mixers, phishing addresses
- π§ͺ Testing: 24 unit tests for behavioral detection
Sprint 4: API Hardening
- π‘οΈ Security Middleware: New
security_middleware.pymodule (615 lines)- Rate limiting (token bucket, 100 req/min default)
- API key authentication (X-API-Key header)
- Request validation (XSS/SQLi prevention)
- Audit logging (all requests logged)
- π API Integration: Security middleware integrated into FastAPI
- π§ͺ Testing: 34 unit tests for security features
Phase 2 Impact
- π Codebase: 11 new/modified files, ~2,400 lines of code
- β Testing: 123 new tests (146 total)
- π Security: 5-layer address verification pipeline
- π― Detection: Velocity, funding patterns, external blacklists
π¨ [07.0.0] - 2026-01-14
Phase 3: Premium Frontend Implementation (Complete)
Objective: Build a production-grade Next.js frontend with enterprise-level design to replace the Streamlit prototype.
ποΈ Architecture & Stack
- Framework: Next.js 14 (App Router) with TypeScript
- Styling: Tailwind CSS 4 + Framer Motion
- Icons: Lucide React
- State Management: React Hooks + Server Components
- Design Philosophy: Glassmorphism, Dark Mode First, Premium Aesthetics
- Typography: Inter (UI) + JetBrains Mono (Code)
π Development Sprints
Sprint 1: Foundation (2 days)
- Next.js 14 initialization with App Router
- Tailwind CSS configuration with custom theme
- Premium landing page with animated hero section
- Statistics showcase and feature cards
- API client setup (
lib/api.ts)
Sprint 2: Dashboard Core (2 days)
- Responsive sidebar navigation (288px fixed)
- Dashboard layout with glassmorphism effects
- Real-time health status monitoring
- Metric cards with trend indicators
- Header with search and notifications
Sprint 3: Transaction Analysis (2 days)
- Transaction input form with validation
- Risk score visualization (circular gauge)
- Triggered rules display
- ML anomaly detection integration
- Split-screen layout (33% / 66%)
Sprint 4: Address Verification (2 days)
- Address input with format validation
- 5-layer verification result display
- Status banners (Known Attacker / Safe)
- Exploit information cards
- Copy-to-clipboard functionality
Sprint 5: Exploit Database & Polish (2 days)
- Searchable exploit list with filters
- Exploit detail cards with attacker tracking
- Etherscan integration for address lookups
- UI proportions refined for 1900px max-width
- Hydration error fixes
π Key Features & Improvements
- β Responsive Design: Optimized for vertical (1080px) and ultrawide (1920px+) monitors
- β Real-time Monitoring: System health status with API connectivity checks
- β Premium Aesthetics: Deep navy (#0A0F1C) + electric blue (#3B82F6) + cyber green (#10B981)
- β Smooth Animations: 60fps Framer Motion transitions throughout
- β Accessible Typography: Base 18px font, larger headings (h1: 3.5rem), improved contrast
- β Interactive Components: Hover effects, glow animations, trend indicators
- β Dark Mode Optimized: Glassmorphism cards with backdrop blur and subtle shadows
π Phase 3 Impact
| Metric | Value |
|---|---|
| New Files Created | 25+ TypeScript/TSX components |
| Lines of Code | ~3,500 lines (frontend only) |
| Reusable Components | 20+ (MetricCard, Header, Sidebar, etc.) |
| Pages Implemented | 5 (Landing, Dashboard, Analyze, Verify, Exploits) |
| API Integration | Full CRUD operations with FastAPI backend |
| Design System | Custom Tailwind theme with glassmorphism utilities |
π― User Experience Enhancements
- Landing Page: 1900px max-width for better screen utilization
- Sidebar: Larger fonts (text-lg nav items), improved logo prominence
- Metric Cards: Increased padding (p-8), larger values (text-4xl)
- Buttons: Enhanced sizes (16px/32px padding) for better accessibility
- Grid Layouts: Responsive breakpoints (sm:2-col, lg:4-col) for all monitor types
Commit message for pushing or pull-request
π§ CCSFEN2L ALTFLEX
Back to Table of Content
Β Β Β Β





















