A prototype e-voting system built with Next.js that implements blockchain concepts for secure, transparent, and tamper-proof voting.
BlockVote is a comprehensive e-voting platform that combines modern web technologies with blockchain security principles. The system supports three distinct user roles and ensures vote integrity through cryptographic validation.
Current Status: Complete database implementation with Prisma ORM - ready for authentication development.
- Blockchain Security: Custom blockchain implementation with proof-of-work
- Digital Signatures: Ed25519 cryptographic signatures for vote authenticity
- Merkle Tree Validation: Efficient vote integrity verification
- Role-Based Access: Admin, Organization, and Voter interfaces
- Anti-Tampering: Hash injection and replay attack prevention
- Transparent Results: Verifiable election outcomes
| Role | Capabilities |
|---|---|
| Admin | System oversight, election monitoring, blockchain validation |
| Organization | Create elections, manage candidates, invite voters, view results |
| Voter | Receive credentials via email, cast votes securely |
- Unified Auth: Custom Prisma-based authentication
- JWT Implementation:
joselibrary for Edge Runtime compatibility - Secure Sessions: HttpOnly cookies and access/refresh token rotation
- Role-Based Access: Middleware protection for Admin, Organization, and Voter roles
- Email Verification: Nodemailer integration for account verification
- CryptoUtils: Double SHA-256, Ed25519 signatures, canonical serialization
- MerkleTree: Vote integrity proofs and validation
- Block: Mining, validation, vote storage
- Blockchain: Chain validation, security threat detection
- BlockchainManager: Multi-election blockchain support
- Dual Support: Seamless switching between SQLite (local dev/test) and PostgreSQL (production)
- Prisma ORM: Optimized schema with all relationships
- Services: Complete CRUD operations for Users, Elections, Votes
- Automated Seeding: Ready-to-use test data
- Next.js 15 with TypeScript
- Tailwind CSS styling
- Complete type definitions
- Environment configuration
- Zero build errors
- Admin dashboard refinement
- Organization portal
- Voter interaction flow
- Real-time results visualization
- Framework: Next.js 15 with TypeScript
- Database: Prisma ORM with hybrid support:
- SQLite: Optimized for local development and testing (zero-config)
- PostgreSQL: Production-grade performance and scalability
- Styling: Tailwind CSS
- Authentication: Custom JWT (JOSE) + bcrypt + Nodemailer
- Blockchain: Custom implementation with Node.js crypto
- Email: Nodemailer
- UI Components: Radix UI + Lucide React
src/
βββ app/ # Next.js app router
β βββ admin/ # Admin dashboard pages
β βββ organization/ # Organization pages
β βββ voter/ # Voter pages
β βββ api/ # API routes
β βββ auth/ # Authentication pages
βββ components/ # Reusable UI components
βββ lib/ # Core utilities
β βββ blockchain/ # Blockchain implementation
β β βββ crypto-utils.ts # Cryptographic functions
β β βββ merkle-tree.ts # Vote integrity verification
β β βββ block.ts # Blockchain blocks
β β βββ blockchain.ts # Main blockchain logic
β βββ database/ # Prisma database services
β β βββ client.ts # Database connection
β β βββ index.ts # Service exports
β β βββ services/ # CRUD operations
β β βββ user.service.ts
β β βββ election.service.ts
β β βββ vote.service.ts
β β βββ blockchain.service.ts
β βββ auth/ # Authentication utilities
β βββ email/ # Email service
βββ types/ # TypeScript definitions
βββ utils/ # General utilities
scripts/ # Development & testing scripts
βββ test-blockchain.ts # Blockchain functionality tests
- Double SHA-256: Prevents length extension attacks
- Digital Signatures: Ed25519 for vote authenticity
- Merkle Trees: Efficient vote integrity verification
- Canonical Serialization: Prevents hash injection
- Proof-of-Work: Light difficulty for block validation
- JWT Authentication: Stateless secure sessions
- bcrypt Hashing: Secure password storage
- Role-Based Access: Granular permission control
- Input Validation: Comprehensive data sanitization
- Audit Logging: Complete action tracking
- Node.js 18+
- npm or yarn
- Clone the repository
git clone https://github.com/mhdthariq/e-voting.git
cd e-voting- Install dependencies
npm install- Configure environment
cp env.example .env
# Edit .env with your configuration- Initialize database
npm run db:setup:dev # Setup development database with test data- Start development server
npm run devVisit http://localhost:3000 to see the application.
- Admin: admin@blockvote.com / admin123!
- Organization: org@blockvote.com / org123!
- Voters: voter1@blockvote.com / voter123! (voter1-5)
(Automatically created with npm run db:seed)
- Next.js setup and configuration
- Project structure and dependencies
- Environment configuration
- β Prisma ORM with multi-environment support
- β 11 comprehensive database tables
- β 4 complete database services with CRUD operations
- β Automated seeding with test data
- β Production deployment scripts
- JWT token implementation
- Login/logout functionality
- Role-based middleware
- Session management
- β Core blockchain classes
- β Cryptographic security
- β Vote validation and mining
- β Multi-election blockchain management
- Admin dashboard
- Organization management
- Voter interface
- Responsive design
- Election lifecycle
- Candidate management
- Vote processing
- Results calculation
- Voter credential distribution
- Election notifications
- Results delivery
- Template system
- Penetration testing
- Performance optimization
- Security audit
- Load testing
# Test blockchain functionality
npm run test:blockchain# Test database health
npm run db:health
# Seed test data
npm run db:seed
# Open database GUI
npm run db:studio# Setup development environment
npm run db:setup:dev
# Reset database (development only)
npm run db:reset:dev
# Check build status
npm run buildPOST /api/auth/login- User loginPOST /api/auth/logout- User logoutGET /api/auth/me- Get current user
GET /api/elections- List electionsPOST /api/elections- Create electionPUT /api/elections/:id- Update electionDELETE /api/elections/:id- Delete election
POST /api/votes- Cast voteGET /api/results/:electionId- Get results
The system provides multiple ways to verify blockchain integrity:
- Hash Validation: Each block hash is cryptographically verified
- Signature Verification: All votes are digitally signed
- Merkle Proof: Individual vote integrity can be proven
- Chain Validation: Complete blockchain integrity checking
- Threat Detection: Automatic security threat identification
Configure email settings in .env:
EMAIL_SERVICE=gmail
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your-email@gmail.com
EMAIL_PASSWORD=your-app-passwordnpm run build
npm start- Set strong
JWT_SECRET - Configure production database
- Set up email service credentials
- Enable HTTPS
- Configure domain settings
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
- Follow TypeScript strict mode (pure TypeScript workflow)
- Use ESLint and Prettier for code quality
- Test blockchain functionality with
npm run test:blockchain - Document security considerations thoroughly
- Validate blockchain integrity before commits
- Use proper TypeScript imports (no .js extensions)
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: View roadmap
- Current Status: View status
- Project Specification: View specs
- TypeScript Setup: View guide
- Immutability: Votes cannot be changed once recorded
- Transparency: All votes are cryptographically verifiable
- Decentralization: No single point of failure (in concept)
- Consensus: Proof-of-work ensures valid blocks
- Vote choices are encrypted and anonymous
- Only vote counts are publicly visible
- Voter identities are protected
- Audit trails maintain integrity without revealing votes
- β Clean project structure with organized directories
- β Pure TypeScript codebase (no mixed JS/TS files)
- β Proper .gitignore configured
- β Test data excluded from version control
- β No build artifacts or temporary files
- β Comprehensive documentation
- Source Code: Complete TypeScript implementation
- Documentation: Project specs, roadmap, and setup guides
- Configuration: Environment templates and TypeScript configs
- Testing: Blockchain functionality tests
- Dependencies: All required packages in package.json
- Generated Data:
/datadirectory (blockchain test files) - Database Files:
*.db,dev.db*,test.db*(generated locally) - Prisma Generated:
/src/generated/,/prisma/migrations/ - Build Artifacts:
.next/,*.tsbuildinfo,/build - Dependencies:
node_modules/ - Environment:
.env*files (use env.example as template) - System Files:
.DS_Store,*.pem
- Clone repository
npm installto install dependenciesnpm run db:setup:devto setup database with test datanpm run test:blockchainto verify blockchain functionalitynpm run db:healthto verify database connectivitynpm run devto start development
The project is ready for collaborative development with a complete database foundation and zero build errors.
After running npm run db:setup:dev, you'll have:
- 7 user accounts (1 admin, 1 organization, 5 voters)
- 1 sample election with 3 candidates
- All database tables populated and ready for testing
Built with β€οΈ for secure, transparent democracy
Last Updated: October 2025 Database Implementation: Complete β Next Phase: Authentication System