Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—³οΈ SecureVote - Online Voting System

πŸ“‹ Project Overview

SecureVote is a secure, efficient, and fair online voting system designed to demonstrate real-world application of fundamental data structures. The system provides a complete end-to-end voting solution with voter authentication, candidate selection, vote submission, and real-time result tallying.

πŸ’‘ The Idea

The project simulates a real-world electronic voting scenario where:

  • Registered voters can authenticate using their Government ID
  • Voters can view all candidates and cast their vote
  • Each voter can only vote once (preventing fraud)
  • Votes are processed fairly in the order they are received
  • Real-time results are displayed with vote counts and percentages

🎯 Problems Solved

Problem Solution
Voter Identity Verification Fast O(log n) lookup using AVL Tree ensures quick authentication even with millions of voters
Preventing Double Voting Each voter's status is tracked in the tree; once voted, they cannot vote again
Fair Vote Processing FIFO Queue ensures votes are counted in the exact order received - no vote gets priority
High Traffic Handling Queue-based buffering decouples vote submission from processing, handling traffic spikes gracefully
Dynamic Candidate Management Linked List allows easy addition/removal of candidates without memory reallocation
Scalability Custom data structures avoid framework overhead, providing lightweight and efficient operations

πŸ—οΈ Data Structures & Their Logic

1. AVL Tree (Self-Balancing Binary Search Tree) - Voter Registry

File: VoterBST.java

        GOV005
       /      \
    GOV003    GOV007
    /    \    /    \
 GOV001 GOV004 GOV006 GOV009

Why AVL Tree?

  • O(log n) Search: When a voter logs in, their Government ID must be verified. With millions of voters, linear search O(n) would be too slow. AVL Tree guarantees O(log n) lookup.
  • Self-Balancing: Unlike a regular BST that can degrade to O(n) with sorted inputs, AVL Tree maintains balance through rotations, ensuring consistent performance.
  • Ordered Storage: Voters are stored sorted by Government ID, enabling efficient range queries if needed.

How It's Used:

  1. Registration: Voters are inserted into the tree during system initialization
  2. Login: When a voter enters their ID, the tree is searched to validate their identity
  3. Vote Status: Each voter node tracks whether they've voted, preventing double voting

Key Operations:

Operation Time Complexity Description
Insert O(log n) Add new voter with automatic rebalancing
Search O(log n) Find voter by Government ID
Update O(log n) Mark voter as "has voted"

2. Queue (FIFO) - Vote Buffer

File: VoteQueue.java

ENQUEUE β†’  [Vote5] β†’ [Vote4] β†’ [Vote3] β†’ [Vote2] β†’ [Vote1]  β†’ DEQUEUE
  (rear)                                            (front)

Why Queue?

  • Fairness: Votes are processed in exactly the order they're received - First In, First Out (FIFO)
  • Decoupling: Separates vote submission (fast) from vote processing (can be slower), implementing the Producer-Consumer pattern
  • Traffic Handling: During peak voting hours, the queue buffers incoming votes, preventing system overload
  • Thread Safety: Synchronized operations prevent race conditions in concurrent environments

How It's Used:

  1. Vote Submission: When a voter casts their vote, it's immediately added to the queue (enqueue)
  2. Background Processing: A separate thread continuously processes votes from the queue (dequeue)
  3. Vote Counting: Each dequeued vote updates the respective candidate's count

Key Operations:

Operation Time Complexity Description
Enqueue O(1) Add vote to rear of queue
Dequeue O(1) Remove and process vote from front
Peek O(1) View next vote without removing

3. Linked List - Candidate Management

File: CandidateLinkedList.java

HEAD β†’ [Elizabeth Warren] β†’ [James Mitchell] β†’ [Sarah Chen] β†’ [Michael Rivera] β†’ NULL
              ↓                    ↓                 ↓               ↓
         Democratic          Republican        Independent      Green Party

Why Linked List?

  • Dynamic Size: Candidates can be added or removed without resizing arrays
  • Memory Efficiency: Only allocates memory for actual candidates, no wasted space
  • Ordered Traversal: Easy iteration to display all candidates or calculate results
  • Simple Updates: Vote counts are stored in each node, easily incremented

How It's Used:

  1. Display Candidates: Traverse the list to show all candidates on the voting page
  2. Vote Counting: When a vote is processed, find the candidate and increment their count
  3. Results Calculation: Traverse to sum votes and calculate percentages

Key Operations:

Operation Time Complexity Description
Add O(1) Add candidate at tail
Find by ID O(n) Search for specific candidate
Traverse O(n) Display all candidates or calculate results

4. Tree Node - BST Building Block

File: TreeNode.java

Each node in the AVL Tree contains:

  • Voter Data: The voter object with ID, name, and voting status
  • Left Child: Reference to left subtree (smaller IDs)
  • Right Child: Reference to right subtree (larger IDs)
  • Height: Used for AVL balance calculations

πŸ”„ System Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   VOTER     β”‚     β”‚  AVL TREE   β”‚     β”‚    QUEUE    β”‚     β”‚ LINKED LIST β”‚
β”‚   LOGIN     │────▢│   SEARCH    β”‚     β”‚             β”‚     β”‚             β”‚
β”‚  (Gov ID)   β”‚     β”‚  O(log n)   β”‚     β”‚             β”‚     β”‚             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
                    β”‚   VALID?    β”‚
                    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
                           β”‚ YES
                    β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  SELECT     β”‚     β”‚   ENQUEUE   β”‚     β”‚  PROCESSOR  β”‚
                    β”‚  CANDIDATE  │────▢│    VOTE     │────▢│   THREAD    β”‚
                    β”‚  & SUBMIT   β”‚     β”‚    O(1)     β”‚     β”‚  (DEQUEUE)  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
                                                                   β”‚
                                                            β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
                                                            β”‚  UPDATE     β”‚
                                                            β”‚  CANDIDATE  β”‚
                                                            β”‚  VOTE COUNT β”‚
                                                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Backend

Technology Purpose
Java 8+ Core programming language
HttpServer Built-in Java HTTP server (com.sun.net.httpserver)
Custom Data Structures AVL Tree, Queue, Linked List - no external libraries
Multi-threading Background vote processor thread

Frontend

Technology Purpose
HTML5 Semantic page structure
CSS3 Modern styling with gradients, animations, glassmorphism
JavaScript (ES6+) Dynamic UI, API calls, state management
Fetch API Asynchronous HTTP requests to backend

Architecture

Component Description
RESTful API JSON-based communication between frontend and backend
Single Page Application Dynamic content updates without page reloads
Real-time Polling Results update every 3 seconds
Responsive Design Works on desktop and mobile devices

πŸ“ Project Structure

voting/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ model/                    # Data Models
β”‚   β”‚   β”œβ”€β”€ Voter.java           # Voter entity (ID, name, hasVoted)
β”‚   β”‚   β”œβ”€β”€ Candidate.java       # Candidate entity (ID, name, party, votes)
β”‚   β”‚   └── Vote.java            # Vote entity (voterId, candidateId, timestamp)
β”‚   β”‚
β”‚   β”œβ”€β”€ datastructures/          # Custom Data Structure Implementations
β”‚   β”‚   β”œβ”€β”€ VoterBST.java        # AVL Tree for voter registry
β”‚   β”‚   β”œβ”€β”€ TreeNode.java        # Node class for AVL Tree
β”‚   β”‚   β”œβ”€β”€ VoteQueue.java       # FIFO Queue for vote processing
β”‚   β”‚   └── CandidateLinkedList.java  # Linked List for candidates
β”‚   β”‚
β”‚   β”œβ”€β”€ service/                  # Business Logic
β”‚   β”‚   └── VotingSystem.java    # Core voting operations
β”‚   β”‚
β”‚   └── server/                   # HTTP Server
β”‚       └── VotingServer.java    # REST API endpoints
β”‚
β”œβ”€β”€ web/                          # Frontend
β”‚   β”œβ”€β”€ index.html               # Main voting page
β”‚   β”œβ”€β”€ admin.html               # Admin dashboard
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── styles.css           # Styling
β”‚   └── js/
β”‚       └── app.js               # Frontend logic
β”‚
└── README.md                     # This file

πŸš€ How to Run

Prerequisites

  • Java JDK 8 or higher
  • Web browser (Chrome, Firefox, Edge)

Steps

  1. Compile the Java files:

    cd src
    javac -d ../out server/VotingServer.java
  2. Run the server:

    cd ../out
    java server.VotingServer
  3. Open the application: Navigate to http://localhost:8080 in your browser


πŸ§ͺ Test Voter IDs

Use these pre-registered Government IDs to test the system:

Government ID Voter Name
GOV001 Alice Johnson
GOV002 Bob Smith
GOV003 Carol Williams
GOV004 David Brown
GOV005 Eva Martinez
GOV006 Frank Wilson
GOV007 Grace Lee
GOV008 Henry Taylor
GOV009 Ivy Anderson
GOV010 Jack Thomas

πŸ“‘ API Endpoints

Endpoint Method Description Request Body
/api/login POST Validate voter ID {"govId": "GOV001"}
/api/vote POST Submit a vote {"voterId": "GOV001", "candidateId": "C001"}
/api/results GET Get current tally -
/api/candidates GET Get candidate list -
/* GET Serve static files -

πŸ“Š Time Complexity Summary

Operation Data Structure Time Complexity
Voter Lookup AVL Tree O(log n)
Voter Registration AVL Tree O(log n)
Vote Submission Queue O(1)
Vote Processing Queue O(1)
Candidate Search Linked List O(n)
Display Candidates Linked List O(n)
Calculate Results Linked List O(n)

πŸ‘¨β€πŸ’» Key Features

  • βœ… Secure voter authentication with O(log n) lookup
  • βœ… One vote per voter enforcement
  • βœ… Fair FIFO vote processing
  • βœ… Real-time result updates
  • βœ… Modern, responsive UI
  • βœ… No external frameworks - pure Java & vanilla JavaScript
  • βœ… Thread-safe concurrent operations

πŸ“ License

This project is created for educational purposes to demonstrate data structure implementations in a real-world application.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages