A secure, transparent, and tamper-proof voting system built with blockchain technology. This system provides end-to-end verifiable elections with real-time monitoring and comprehensive audit trails.
Note: This project has been updated to work without Docker. Windows users should use XAMPP for easy setup, while Linux/Mac users can use the traditional manual setup.
- π End-to-End Security: Complete encryption from vote casting to blockchain storage
- βοΈ Blockchain Verification: Immutable vote storage with cryptographic proof
- π Real-Time Monitoring: Live election statistics and system health monitoring
- π₯ Multi-User Roles: Separate interfaces for voters, candidates, and administrators
- π Audit Trails: Comprehensive logging of all system activities
- π WebSocket Integration: Real-time updates and notifications
- π± Responsive UI: Modern React-based interface with Bootstrap styling
- π§ Multi-Service Architecture: Scalable microservices design
The system consists of four main components:
blockchain-voting-system/
βββ frontend/ # React + TypeScript SPA
β βββ src/
β β βββ components/
β β βββ pages/
β β βββ services/
β β βββ types/
β βββ .env.example
β βββ package.json
β βββ vite.config.ts
βββ php-backend/ # PHP REST API
β βββ src/
β β βββ Controllers/
β β βββ Middleware/
β β βββ Models/
β βββ .env.example
β βββ composer.json
β βββ public/index.php
βββ python-blockchain/ # Blockchain implementation
β βββ src/
β β βββ core/
β β βββ api/
β βββ .env.example
β βββ requirements.txt
β βββ run.py
βββ node-ws/ # WebSocket server
β βββ src/
β β βββ server/
β β βββ utils/
β βββ .env.example
β βββ package.json
βββ database/ # Database schema & scripts
β βββ schema.sql
βββ setup-windows.bat # Windows setup script
βββ setup-database.bat # Windows database setup
βββ setup-xampp.bat # XAMPP setup script
- Frontend: React + TypeScript application with modern UI using Bootstrap
- Backend: PHP API with PSR-7 compliance and JWT authentication using Slim Framework
- Blockchain: Python-based blockchain for vote storage and verification with Flask API
- WebSocket: Node.js real-time communication server using WebSocket protocol
- XAMPP (includes Apache, MySQL, PHP)
- Node.js 14.0+ with npm 6.0+
- Python 3.8+ with pip 20.0+
- Git 2.0+
- PHP 8.1+ with Composer 2.0+
- Node.js 14.0+ with npm 6.0+
- Python 3.8+ with pip 20.0+
- MySQL 5.7+ or MariaDB 10.3+
# Clone the repository
git clone <repository-url>
cd blockchain-voting-system
# Install XAMPP from https://www.apachefriends.org/
# Start XAMPP Control Panel and start Apache + MySQL
# Run Windows setup script
setup-windows.bat
# Open phpMyAdmin (http://localhost/phpmyadmin)
# Create database 'voting_system' and import database/schema.sql
# Run database setup
setup-database.bat
# Install dependencies
cd python-blockchain && pip install -r requirements.txt
cd ../node-ws && npm install
cd ../frontend && npm install
# Start services
# Terminal 1: cd python-blockchain && python run.py
# Terminal 2: cd node-ws && npm start
# Terminal 3: cd frontend && npm run dev
# Access the application
start http://localhost:5173# Clone the repository
git clone <repository-url>
cd blockchain-voting-system
# Install MySQL Server from https://dev.mysql.com/downloads/mysql/
# Start MySQL service (run Command Prompt as Administrator)
# net start MySQL96 (or whatever your service name is)
# Run Windows setup script
setup-windows.bat
# Set up MySQL database and user
mysql-setup.bat
# Run database setup
setup-database.bat
# Install dependencies
cd python-blockchain && pip install -r requirements.txt
cd ../node-ws && npm install
cd ../frontend && npm install
# Start services
# Terminal 1: cd python-blockchain && python run.py
# Terminal 2: cd node-ws && npm start
# Terminal 3: cd frontend && npm run dev
# Terminal 4: cd php-backend && php -S localhost:8000 -t public/
# Access the application
start http://localhost:5173Default admin credentials:
- Email:
[email protected] - Password:
Admin123!
# Install MySQL/MariaDB and create database
sudo apt-get install mysql-server # Ubuntu/Debian
# OR
brew install mysql # macOS
# Start MySQL service
sudo systemctl start mysql # Linux
# OR
brew services start mysql # macOS
# Run database setup script
./setup-database.sh# PHP Backend
cd php-backend
composer install
cp .env.example .env # Configure your environment variables
php -S localhost:8000 -t public/# Python Blockchain
cd python-blockchain
pip install -r requirements.txt
python run.py# Node.js WebSocket Server
cd node-ws
npm install
npm start# React Frontend
cd frontend
npm install
npm run dev# From project root
./start-system.sh startFor Windows users, choose one of the database options:
# Run the setup script to create all environment files
setup-windows.bat
# Start XAMPP Control Panel
# Start Apache and MySQL services
# Open phpMyAdmin and create/import database
# Run database setup
setup-database.bat# Run the setup script to create all environment files
setup-windows.bat
# Ensure MySQL service is running
# Run MySQL setup script
mysql-setup.bat
# Run database setup
setup-database.batCreate .env files in each component directory:
APP_ENV=development
DB_HOST=localhost
DB_PORT=3306
DB_NAME=voting_system
DB_USER=root
DB_PASS=
JWT_SECRET=your-secret-key
BLOCKCHAIN_SERVICE_URL=http://localhost:5000SECRET_KEY=dev-secret-key
BLOCKCHAIN_DIFFICULTY=4
DATABASE_URL=sqlite:///blockchain.db
API_KEYS=test-key-123
HOST=0.0.0.0
PORT=5000NODE_ENV=development
PORT=3001
JWT_SECRET=dev-jwt-secret
REDIS_URL=redis://localhost:6379
BLOCKCHAIN_API_URL=http://localhost:5000
PHP_API_URL=http://localhost:8000/api/v1VITE_API_BASE_URL=http://localhost:8000/api/v1
VITE_BLOCKCHAIN_API_URL=http://localhost:5000
VITE_WS_URL=ws://localhost:3001Admin User:
- Email:
[email protected] - Password:
Admin123!
Check system status:
# Check if services are running on their ports
# Blockchain: http://localhost:5000/health
# WebSocket: http://localhost:3001/health
# Frontend: http://localhost:5173
# PHP API: http://localhost/voting-api (when using XAMPP)# Quick health check
./health-check.sh
# Detailed status
./start-system.sh status
# View logs
./start-system.sh logs# PHP tests
cd php-backend && composer test
# Node.js tests
cd node-ws && npm test
# Python tests
cd python-blockchain && python -m pytest# PHP linting
cd php-backend && composer lint
# Node.js linting
cd node-ws && npm run lint
# Python linting
cd python-blockchain && black . && flake8 .- End-to-End Encryption: All communications are encrypted
- Blockchain Verification: Votes are immutably stored on blockchain
- JWT Authentication: Secure token-based authentication
- Rate Limiting: Protection against brute force attacks
- Input Validation: Comprehensive data validation
- Audit Trails: Complete logging of all actions
The system provides real-time monitoring:
- WebSocket Connections: Live user activity
- Blockchain Status: Network health and statistics
- Vote Verification: Real-time vote confirmation
- System Metrics: Performance and usage statistics
POST /auth/login- User loginPOST /auth/register- User registrationGET /auth/verify- Verify JWT tokenPOST /auth/logout- User logout
GET /elections- List all electionsGET /elections/{id}- Get election detailsPOST /elections- Create new election (Admin only)PUT /elections/{id}- Update election (Admin only)DELETE /elections/{id}- Delete election (Admin only)
GET /candidates?election_id={id}- List candidates for electionPOST /candidates- Register as candidate (Admin approval required)GET /candidates/{id}- Get candidate details
POST /votes- Cast a voteGET /votes/{id}- Get vote detailsGET /votes?election_id={id}- Get votes for election (Admin only)
GET /users/profile- Get current user profilePUT /users/profile- Update user profileGET /users/pending- List pending registrations (Admin only)POST /users/{id}/verify- Verify user registration (Admin only)
GET /admin/dashboard- Get dashboard statisticsGET /admin/audit-log- Get audit logsPOST /admin/system/health- System health check
GET /stats- Blockchain statistics and healthGET /blocks- List all blocksGET /blocks/{index}- Get specific blockPOST /validate- Verify vote integrityGET /transactions/{hash}- Get transaction details
GET /status- Mining statusPOST /start- Start mining processPOST /stop- Stop mining process
The system uses WebSocket connections for real-time updates. All events require JWT authentication.
// Connect to WebSocket server
const ws = new WebSocket('ws://localhost:3001?token=YOUR_JWT_TOKEN');
// Connection established
ws.onopen = (event) => {
console.log('Connected to voting system');
};
// Handle incoming messages
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
switch(data.type) {
case 'vote_cast':
// Vote successfully cast and confirmed
console.log('Vote cast:', data.vote);
break;
case 'election_started':
// New election has begun
console.log('Election started:', data.election);
updateElectionStatus(data.election);
break;
case 'election_ended':
// Election has concluded
console.log('Election ended:', data.election);
showResults(data.election);
break;
case 'block_mined':
// New block added to blockchain
console.log('Block mined:', data.block);
updateBlockchainStatus(data.block);
break;
case 'user_registered':
// New user registration (admin notification)
console.log('New user:', data.user);
updatePendingRegistrations(data.user);
break;
case 'system_health':
// System health update
console.log('Health status:', data.health);
updateSystemHealth(data.health);
break;
case 'error':
// Error notification
console.error('WebSocket error:', data.message);
showError(data.message);
break;
}
};
// Handle connection errors
ws.onerror = (error) => {
console.error('WebSocket error:', error);
};
// Handle connection close
ws.onclose = (event) => {
console.log('WebSocket connection closed');
// Implement reconnection logic
};vote_cast: Vote successfully recordedelection_started: Election beginselection_ended: Election concludesblock_mined: New blockchain blockuser_registered: New user registrationsystem_health: System status updateerror: Error notification
-
XAMPP Not Found
# Ensure XAMPP is installed in C:\xampp # Or update XAMPP_DIR in setup-windows.bat
-
Port Conflicts
# Check what's using a port netstat -ano | findstr :5000 # Kill process using port (replace PID) taskkill /PID <PID> /F
-
MySQL Connection Issues
# Test MySQL connection (from XAMPP directory) C:\xampp\mysql\bin\mysql -h localhost -u root -p -e "SELECT 1;" # Reset database setup-database.bat -
Python/Node.js Path Issues
# Check versions python --version node --version # Ensure they're in PATH where python where node
-
Port Conflicts
# Check what's using a port lsof -i :5000 # Kill process using port kill -9 $(lsof -ti :5000)
-
Database Connection Issues
# Test MySQL connection mysql -h localhost -u root -p -e "SELECT 1;" # Reset database ./setup-database.sh
-
Permission Issues
# Make scripts executable chmod +x *.sh chmod +x php-backend/*.sh
-
Node.js/Python Path Issues
# Check versions node --version python --version # Update PATH if needed export PATH="/usr/local/bin:$PATH"
Check logs for debugging:
# XAMPP Logs
# Apache: C:\xampp\apache\logs\
# MySQL: C:\xampp\mysql\data\
# Application Logs (check individual service directories)
type python-blockchain\blockchain.log
type node-ws\websocket.log# All service logs
./start-system.sh logs
# Individual service logs
tail -f blockchain.log
tail -f websocket.log
tail -f php.log
tail -f frontend.log- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
This is a demonstration system. For production use, additional security measures, penetration testing, and compliance with local election regulations are required.
For support and questions:
- Create an issue in the repository
- Check the troubleshooting section above
- Review the logs for error messages